Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Update to vscode 1.87.0 #246

Merged
merged 2 commits into from Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -49,9 +49,9 @@
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@tsconfig/node16": "^16.1.1",
"@tsconfig/node18": "^18.2.2",
"@types/node": "^18.19.2",
"@types/vscode": "^1.85.0",
"@types/vscode": "^1.87.0",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"eslint": "^8.55.0",
Expand Down
18 changes: 7 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/vscode/TabGroups.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, test, jest } from '@jest/globals';
// eslint-disable-next-line node/no-missing-import
import type { TabGroup } from 'vscode';
import { MockTabGroups } from './TabGroups';
import { createMockTabGroups } from './TabGroups';

describe('TabGroups', () => {
test('new MockTabGroups', () => {
Expand All @@ -11,7 +11,7 @@ describe('TabGroups', () => {
activeTab: undefined,
tabs: [],
};
const mtg = new MockTabGroups(jest, [tg]);
const mtg = createMockTabGroups(jest, [tg]);
expect(mtg.activeTabGroup).toBe(tg);
});
});
23 changes: 13 additions & 10 deletions src/vscode/TabGroups.ts
Expand Up @@ -2,17 +2,20 @@
import type { TabGroups, TabGroup } from 'vscode';
import { TestFramework } from '../TestFramework';

export class MockTabGroups implements TabGroups {
constructor(
private jest: TestFramework,
readonly all: TabGroup[],
) {}
export function createMockTabGroups(jest: TestFramework, all: TabGroup[]) {
class MockTabGroups implements TabGroups {
constructor(readonly all: TabGroup[]) {}

get activeTabGroup(): TabGroup {
return this.all[0];
get activeTabGroup(): TabGroup {
return this.all[0];
}

onDidChangeTabGroups = jest.fn();
onDidChangeTabs = jest.fn();
close = jest.fn();
}

onDidChangeTabGroups = this.jest.fn();
onDidChangeTabs = this.jest.fn();
close = this.jest.fn();
return new MockTabGroups(all);
}

export type MockTabGroups = ReturnType<typeof createMockTabGroups>;
4 changes: 2 additions & 2 deletions src/vscode/TextEditor.test.ts
@@ -1,13 +1,13 @@
import { describe, expect, test, jest } from '@jest/globals';

import { createTextDocument } from '../vscodeTypesHelper';
import { MockTextEditor } from './TextEditor';
import { createMockTextEditor } from './TextEditor';
import { Uri } from './uri';

describe('TextEditor', () => {
test('MockTextEditor', () => {
const doc = createTextDocument(Uri.file(__filename), sampleContent());
const te = new MockTextEditor(jest, doc);
const te = createMockTextEditor(jest, doc);
expect(te.document).toBe(doc);
expect(te.selection).toBeDefined();
expect(te.selections).toHaveLength(1);
Expand Down
100 changes: 55 additions & 45 deletions src/vscode/TextEditor.ts
Expand Up @@ -3,58 +3,68 @@ import type * as vscode from 'vscode';
import * as mockedTypes from './extHostTypes';
import { TestFramework } from '../TestFramework';

export class MockTextEditor implements vscode.TextEditor {
_options: vscode.TextEditorOptions = {};
_visibleRanges: vscode.Range[] = [];
_selections: vscode.Selection[];

constructor(
private jest: TestFramework,
public _document: vscode.TextDocument,
public _viewColumn?: vscode.ViewColumn | undefined,
selection: vscode.Selection = new mockedTypes.Selection(
new mockedTypes.Position(0, 0),
new mockedTypes.Position(0, 0),
),
) {
this._selections = [selection];
}
export function createMockTextEditor(
jest: TestFramework,
document: vscode.TextDocument,
_viewColumn?: vscode.ViewColumn | undefined,
selection?: vscode.Selection,
) {
class MockTextEditor implements vscode.TextEditor {
_options: vscode.TextEditorOptions = {};
_visibleRanges: vscode.Range[] = [];
_selections: vscode.Selection[];

get document(): vscode.TextDocument {
return this._document;
}
constructor(
public _document: vscode.TextDocument,
public _viewColumn?: vscode.ViewColumn | undefined,
selection: vscode.Selection = new mockedTypes.Selection(
new mockedTypes.Position(0, 0),
new mockedTypes.Position(0, 0),
),
) {
this._selections = [selection];
}

/**
* The primary selection on this text editor. Shorthand for `TextEditor.selections[0]`.
*/
get selection(): vscode.Selection {
return this.selections[0];
}
get document(): vscode.TextDocument {
return this._document;
}

get selections(): vscode.Selection[] {
return this._selections;
}
/**
* The primary selection on this text editor. Shorthand for `TextEditor.selections[0]`.
*/
get selection(): vscode.Selection {
return this.selections[0];
}

get visibleRanges(): vscode.Range[] {
return this._visibleRanges;
}
get selections(): vscode.Selection[] {
return this._selections;
}

get options(): vscode.TextEditorOptions {
return this._options;
}
get visibleRanges(): vscode.Range[] {
return this._visibleRanges;
}

set options(s: vscode.TextEditorOptions) {
this._options = s;
}
get options(): vscode.TextEditorOptions {
return this._options;
}

set options(s: vscode.TextEditorOptions) {
this._options = s;
}

get viewColumn(): vscode.ViewColumn | undefined {
return this._viewColumn;
get viewColumn(): vscode.ViewColumn | undefined {
return this._viewColumn;
}

edit = jest.fn();
insertSnippet = jest.fn();
setDecorations = jest.fn();
revealRange = jest.fn();
show = jest.fn();
hide = jest.fn();
}

edit = this.jest.fn();
insertSnippet = this.jest.fn();
setDecorations = this.jest.fn();
revealRange = this.jest.fn();
show = this.jest.fn();
hide = this.jest.fn();
return new MockTextEditor(document, _viewColumn, selection);
}

export type MockTextEditor = ReturnType<typeof createMockTextEditor>;
1 change: 1 addition & 0 deletions src/vscode/extHostTypes.ts
Expand Up @@ -1155,6 +1155,7 @@ export enum TextEditorLineNumbersStyle {
Off = 0,
On = 1,
Relative = 2,
Interval = 3,
}

export enum TextDocumentSaveReason {
Expand Down
8 changes: 4 additions & 4 deletions src/vscode/window.ts
Expand Up @@ -3,9 +3,9 @@ import type { TextEditor, TextDocumentShowOptions, Uri, TextDocument, ViewColumn
// eslint-disable-next-line node/no-missing-import, import/no-duplicates
import type * as vscode from 'vscode';
import { Selection } from './extHostTypes';
import { MockTextEditor } from './TextEditor';
import { createMockTextEditor } from './TextEditor';
import { isUri } from './uri';
import { MockTabGroups } from './TabGroups';
import { createMockTabGroups } from './TabGroups';
import { TestFramework } from '../TestFramework';
import { Workspace } from './workspace';

Expand Down Expand Up @@ -34,7 +34,7 @@ export function createWindow(jest: TestFramework, workspace: Workspace): Window
visibleNotebookEditors: [],
visibleTextEditors: [],

tabGroups: new MockTabGroups(jest, []),
tabGroups: createMockTabGroups(jest, []),

// Fully mocked methods
createStatusBarItem: jest.fn(createStatusBarItem),
Expand Down Expand Up @@ -145,6 +145,6 @@ export function createWindow(jest: TestFramework, workspace: Workspace): Window
const selectionRange = options?.selection;
const selection = selectionRange && new Selection(selectionRange.start, selectionRange.start);

return new MockTextEditor(jest, document, viewColumn, selection);
return createMockTextEditor(jest, document, viewColumn, selection);
}
}