Skip to content

Commit

Permalink
Remove vscode version checks (#2305)
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey authored Apr 25, 2024
1 parent fea523e commit a1bb6e4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 143 deletions.
28 changes: 1 addition & 27 deletions packages/cursorless-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,7 @@
"pokey.parse-tree"
],
"activationEvents": [
"onLanguage",
"onView:cursorless.scopes",
"onCommand:cursorless.command",
"onCommand:cursorless.internal.updateCheatsheetDefaults",
"onCommand:cursorless.private.logQuickActions",
"onCommand:cursorless.keyboard.escape",
"onCommand:cursorless.keyboard.modal.modeOff",
"onCommand:cursorless.keyboard.modal.modeOn",
"onCommand:cursorless.keyboard.modal.modeToggle",
"onCommand:cursorless.keyboard.targeted.clearTarget",
"onCommand:cursorless.keyboard.targeted.runActionOnTarget",
"onCommand:cursorless.keyboard.targeted.targetHat",
"onCommand:cursorless.keyboard.targeted.targetScope",
"onCommand:cursorless.keyboard.targeted.targetSelection",
"onCommand:cursorless.pauseRecording",
"onCommand:cursorless.recomputeDecorationStyles",
"onCommand:cursorless.recordTestCase",
"onCommand:cursorless.recordOneTestCaseThenPause",
"onCommand:cursorless.resumeRecording",
"onCommand:cursorless.showCheatsheet",
"onCommand:cursorless.showDocumentation",
"onCommand:cursorless.showQuickPick",
"onCommand:cursorless.takeSnapshot",
"onCommand:cursorless.toggleDecorations",
"onCommand:cursorless.showScopeVisualizer",
"onCommand:cursorless.hideScopeVisualizer",
"onCommand:cursorless.analyzeCommandHistory"
"onLanguage"
],
"main": "./extension.cjs",
"capabilities": {
Expand Down
28 changes: 7 additions & 21 deletions packages/cursorless-vscode/src/ide/vscode/VscodeFocusEditor.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import * as semver from "semver";
import { getCellIndex } from "@cursorless/vscode-common";
import {
commands,
NotebookDocument,
TextEditor,
version,
ViewColumn,
window,
} from "vscode";
import { getCellIndex } from "@cursorless/vscode-common";
import { getNotebookFromCellDocument } from "./notebook/notebook";
import { focusNotebookCellLegacy } from "./notebook/notebookLegacy";
import { isVscodeLegacyNotebookVersion } from "./notebook/notebook";
import type { VscodeIDE } from "./VscodeIDE";
import { VscodeTextEditorImpl } from "./VscodeTextEditorImpl";

const columnFocusCommands = {
Expand All @@ -28,10 +23,7 @@ const columnFocusCommands = {
[ViewColumn.Beside]: "",
};

export default async function vscodeFocusEditor(
ide: VscodeIDE,
editor: VscodeTextEditorImpl,
) {
export default async function vscodeFocusEditor(editor: VscodeTextEditorImpl) {
// Focusing the search editor brings focus back to the input field.
// FIXME: This is a hack. There is no way to focus the search editor. If we
// could figure out if the editor was not focused, we could issue
Expand All @@ -48,10 +40,6 @@ export default async function vscodeFocusEditor(
// If the view column is null we see if it's a notebook and try to see if we
// can just move around in the notebook to focus the correct editor

if (isVscodeLegacyNotebookVersion()) {
return await focusNotebookCellLegacy(ide, editor);
}

await focusNotebookCell(editor);
}
}
Expand All @@ -60,14 +48,12 @@ function getViewColumn(editor: TextEditor): ViewColumn | undefined {
if (editor.viewColumn != null) {
return editor.viewColumn;
}
// FIXME: tabGroups is not available on older versions of vscode we still support.
// Remove any cast as soon as version is updated.
if (semver.lt(version, "1.67.0")) {
return undefined;
}
const uri = editor.document.uri.toString();
const tabGroup = (window as any)?.tabGroups?.all?.find((tabGroup: any) =>
tabGroup?.tabs.find((tab: any) => tab?.input?.modified?.toString() === uri),
const tabGroup = window.tabGroups.all.find((tabGroup) =>
tabGroup.tabs.find(
(tab: any) =>
(tab?.input?.uri ?? tab?.input?.modified)?.toString() === uri,
),
);
return tabGroup?.viewColumn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class VscodeTextEditorImpl implements EditableTextEditor {
}

public focus(): Promise<void> {
return vscodeFocusEditor(this.ide, this);
return vscodeFocusEditor(this);
}

public editNewNotebookCellAbove(): Promise<
Expand Down
28 changes: 14 additions & 14 deletions packages/cursorless-vscode/src/ide/vscode/notebook/notebook.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import * as semver from "semver";
import { version } from "vscode";
import { TextDocument } from "vscode";
import { getNotebookFromCellDocumentLegacy } from "./notebookLegacy";
import { getNotebookFromCellDocumentCurrent } from "./notebookCurrent";

export function isVscodeLegacyNotebookVersion() {
return semver.lt(version, "1.68.0");
}
import { TextDocument, window } from "vscode";

/**
* Given a document corresponding to a single cell, retrieve the notebook
Expand All @@ -16,9 +8,17 @@ export function isVscodeLegacyNotebookVersion() {
* given cell
*/
export function getNotebookFromCellDocument(document: TextDocument) {
if (isVscodeLegacyNotebookVersion()) {
return getNotebookFromCellDocumentLegacy(document);
} else {
return getNotebookFromCellDocumentCurrent(document);
}
const { notebookEditor } =
window.visibleNotebookEditors
.flatMap((notebookEditor) =>
notebookEditor.notebook.getCells().map((cell) => ({
notebookEditor,
cell,
})),
)
.find(
({ cell }) => cell.document.uri.toString() === document.uri.toString(),
) ?? {};

return notebookEditor;
}

This file was deleted.

15 changes: 1 addition & 14 deletions packages/meta-updater/src/getCursorlessVscodeFields.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
CURSORLESS_SCOPE_TREE_VIEW_ID,
cursorlessCommandDescriptions,
cursorlessCommandIds,
} from "@cursorless/common";
import { cursorlessCommandDescriptions } from "@cursorless/common";
import { PackageJson } from "type-fest";

export function getCursorlessVscodeFields(input: PackageJson) {
Expand All @@ -21,15 +17,6 @@ export function getCursorlessVscodeFields(input: PackageJson) {
activationEvents: [
// Causes extension to activate whenever any text editor is opened
"onLanguage",

// Causes extension to activate when the Cursorless scope support side bar
// is opened
`onView:${CURSORLESS_SCOPE_TREE_VIEW_ID}`,

// Causes extension to activate when any Cursorless command is run.
// Technically we don't need to do this since VSCode 1.74.0, but we support
// older versions
...cursorlessCommandIds.map((id) => `onCommand:${id}`),
],
};
}

0 comments on commit a1bb6e4

Please sign in to comment.