Skip to content

Commit a1bb6e4

Browse files
authored
Remove vscode version checks (#2305)
Fixes #2274 ## Checklist - [-] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [-] I have not broken the cheatsheet
1 parent fea523e commit a1bb6e4

File tree

6 files changed

+24
-143
lines changed

6 files changed

+24
-143
lines changed

packages/cursorless-vscode/package.json

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,7 @@
4545
"pokey.parse-tree"
4646
],
4747
"activationEvents": [
48-
"onLanguage",
49-
"onView:cursorless.scopes",
50-
"onCommand:cursorless.command",
51-
"onCommand:cursorless.internal.updateCheatsheetDefaults",
52-
"onCommand:cursorless.private.logQuickActions",
53-
"onCommand:cursorless.keyboard.escape",
54-
"onCommand:cursorless.keyboard.modal.modeOff",
55-
"onCommand:cursorless.keyboard.modal.modeOn",
56-
"onCommand:cursorless.keyboard.modal.modeToggle",
57-
"onCommand:cursorless.keyboard.targeted.clearTarget",
58-
"onCommand:cursorless.keyboard.targeted.runActionOnTarget",
59-
"onCommand:cursorless.keyboard.targeted.targetHat",
60-
"onCommand:cursorless.keyboard.targeted.targetScope",
61-
"onCommand:cursorless.keyboard.targeted.targetSelection",
62-
"onCommand:cursorless.pauseRecording",
63-
"onCommand:cursorless.recomputeDecorationStyles",
64-
"onCommand:cursorless.recordTestCase",
65-
"onCommand:cursorless.recordOneTestCaseThenPause",
66-
"onCommand:cursorless.resumeRecording",
67-
"onCommand:cursorless.showCheatsheet",
68-
"onCommand:cursorless.showDocumentation",
69-
"onCommand:cursorless.showQuickPick",
70-
"onCommand:cursorless.takeSnapshot",
71-
"onCommand:cursorless.toggleDecorations",
72-
"onCommand:cursorless.showScopeVisualizer",
73-
"onCommand:cursorless.hideScopeVisualizer",
74-
"onCommand:cursorless.analyzeCommandHistory"
48+
"onLanguage"
7549
],
7650
"main": "./extension.cjs",
7751
"capabilities": {

packages/cursorless-vscode/src/ide/vscode/VscodeFocusEditor.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
import * as semver from "semver";
1+
import { getCellIndex } from "@cursorless/vscode-common";
22
import {
33
commands,
44
NotebookDocument,
55
TextEditor,
6-
version,
76
ViewColumn,
87
window,
98
} from "vscode";
10-
import { getCellIndex } from "@cursorless/vscode-common";
119
import { getNotebookFromCellDocument } from "./notebook/notebook";
12-
import { focusNotebookCellLegacy } from "./notebook/notebookLegacy";
13-
import { isVscodeLegacyNotebookVersion } from "./notebook/notebook";
14-
import type { VscodeIDE } from "./VscodeIDE";
1510
import { VscodeTextEditorImpl } from "./VscodeTextEditorImpl";
1611

1712
const columnFocusCommands = {
@@ -28,10 +23,7 @@ const columnFocusCommands = {
2823
[ViewColumn.Beside]: "",
2924
};
3025

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

51-
if (isVscodeLegacyNotebookVersion()) {
52-
return await focusNotebookCellLegacy(ide, editor);
53-
}
54-
5543
await focusNotebookCell(editor);
5644
}
5745
}
@@ -60,14 +48,12 @@ function getViewColumn(editor: TextEditor): ViewColumn | undefined {
6048
if (editor.viewColumn != null) {
6149
return editor.viewColumn;
6250
}
63-
// FIXME: tabGroups is not available on older versions of vscode we still support.
64-
// Remove any cast as soon as version is updated.
65-
if (semver.lt(version, "1.67.0")) {
66-
return undefined;
67-
}
6851
const uri = editor.document.uri.toString();
69-
const tabGroup = (window as any)?.tabGroups?.all?.find((tabGroup: any) =>
70-
tabGroup?.tabs.find((tab: any) => tab?.input?.modified?.toString() === uri),
52+
const tabGroup = window.tabGroups.all.find((tabGroup) =>
53+
tabGroup.tabs.find(
54+
(tab: any) =>
55+
(tab?.input?.uri ?? tab?.input?.modified)?.toString() === uri,
56+
),
7157
);
7258
return tabGroup?.viewColumn;
7359
}

packages/cursorless-vscode/src/ide/vscode/VscodeTextEditorImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class VscodeTextEditorImpl implements EditableTextEditor {
8989
}
9090

9191
public focus(): Promise<void> {
92-
return vscodeFocusEditor(this.ide, this);
92+
return vscodeFocusEditor(this);
9393
}
9494

9595
public editNewNotebookCellAbove(): Promise<
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import * as semver from "semver";
2-
import { version } from "vscode";
3-
import { TextDocument } from "vscode";
4-
import { getNotebookFromCellDocumentLegacy } from "./notebookLegacy";
5-
import { getNotebookFromCellDocumentCurrent } from "./notebookCurrent";
6-
7-
export function isVscodeLegacyNotebookVersion() {
8-
return semver.lt(version, "1.68.0");
9-
}
1+
import { TextDocument, window } from "vscode";
102

113
/**
124
* Given a document corresponding to a single cell, retrieve the notebook
@@ -16,9 +8,17 @@ export function isVscodeLegacyNotebookVersion() {
168
* given cell
179
*/
1810
export function getNotebookFromCellDocument(document: TextDocument) {
19-
if (isVscodeLegacyNotebookVersion()) {
20-
return getNotebookFromCellDocumentLegacy(document);
21-
} else {
22-
return getNotebookFromCellDocumentCurrent(document);
23-
}
11+
const { notebookEditor } =
12+
window.visibleNotebookEditors
13+
.flatMap((notebookEditor) =>
14+
notebookEditor.notebook.getCells().map((cell) => ({
15+
notebookEditor,
16+
cell,
17+
})),
18+
)
19+
.find(
20+
({ cell }) => cell.document.uri.toString() === document.uri.toString(),
21+
) ?? {};
22+
23+
return notebookEditor;
2424
}

packages/cursorless-vscode/src/ide/vscode/notebook/notebookLegacy.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
CURSORLESS_SCOPE_TREE_VIEW_ID,
3-
cursorlessCommandDescriptions,
4-
cursorlessCommandIds,
5-
} from "@cursorless/common";
1+
import { cursorlessCommandDescriptions } from "@cursorless/common";
62
import { PackageJson } from "type-fest";
73

84
export function getCursorlessVscodeFields(input: PackageJson) {
@@ -21,15 +17,6 @@ export function getCursorlessVscodeFields(input: PackageJson) {
2117
activationEvents: [
2218
// Causes extension to activate whenever any text editor is opened
2319
"onLanguage",
24-
25-
// Causes extension to activate when the Cursorless scope support side bar
26-
// is opened
27-
`onView:${CURSORLESS_SCOPE_TREE_VIEW_ID}`,
28-
29-
// Causes extension to activate when any Cursorless command is run.
30-
// Technically we don't need to do this since VSCode 1.74.0, but we support
31-
// older versions
32-
...cursorlessCommandIds.map((id) => `onCommand:${id}`),
3320
],
3421
};
3522
}

0 commit comments

Comments
 (0)