From 67f3fd94cc02fa29864c83586646cf073d558869 Mon Sep 17 00:00:00 2001 From: Johannes Date: Thu, 17 Mar 2022 11:44:23 +0100 Subject: [PATCH 001/121] set COOP, COEP, and CORP headers --- .../electron-main/protocolMainService.ts | 19 +++++++++++++++++-- .../electron-main/webviewProtocolProvider.ts | 9 ++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/vs/platform/protocol/electron-main/protocolMainService.ts b/src/vs/platform/protocol/electron-main/protocolMainService.ts index 324c8abbece0e..e1e479338c9bc 100644 --- a/src/vs/platform/protocol/electron-main/protocolMainService.ts +++ b/src/vs/platform/protocol/electron-main/protocolMainService.ts @@ -7,7 +7,7 @@ import { ipcMain, session } from 'electron'; import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { TernarySearchTree } from 'vs/base/common/map'; import { FileAccess, Schemas } from 'vs/base/common/network'; -import { extname, normalize } from 'vs/base/common/path'; +import { basename, extname, normalize } from 'vs/base/common/path'; import { isLinux } from 'vs/base/common/platform'; import { URI } from 'vs/base/common/uri'; import { generateUuid } from 'vs/base/common/uuid'; @@ -88,12 +88,27 @@ export class ProtocolMainService extends Disposable implements IProtocolMainServ //#region vscode-file:// + private static crossOriginRoots = new Set([ + 'workbench.html', + 'webWorkerExtensionHostIframe.html', + 'workerMain.js', + ]); + private handleResourceRequest(request: Electron.ProtocolRequest, callback: ProtocolCallback): void { const path = this.requestToNormalizedFilePath(request); // first check by validRoots if (this.validRoots.findSubstr(path)) { - return callback({ path }); + + let headers: Record | undefined; + if (ProtocolMainService.crossOriginRoots.has(basename(path))) { + headers = { + 'Cross-Origin-Opener-Policy': 'same-origin', + 'Cross-Origin-Embedder-Policy': 'require-corp' + }; + } + + return callback({ path, headers }); } // then check by validExtensions diff --git a/src/vs/platform/webview/electron-main/webviewProtocolProvider.ts b/src/vs/platform/webview/electron-main/webviewProtocolProvider.ts index a0c161312fbf0..652a5d7484f2c 100644 --- a/src/vs/platform/webview/electron-main/webviewProtocolProvider.ts +++ b/src/vs/platform/webview/electron-main/webviewProtocolProvider.ts @@ -36,7 +36,14 @@ export class WebviewProtocolProvider extends Disposable { if (typeof entry === 'string') { const relativeResourcePath = `vs/workbench/contrib/webview/browser/pre/${entry}`; const url = FileAccess.asFileUri(relativeResourcePath, require); - return callback(decodeURIComponent(url.fsPath)); + return callback({ + path: decodeURIComponent(url.fsPath), + headers: { + 'Cross-Origin-Opener-Policy': 'same-origin', + 'Cross-Origin-Embedder-Policy': 'require-corp', + 'Cross-Origin-Resource-Policy': 'cross-origin' + } + }); } else { return callback({ error: -10 /* ACCESS_DENIED - https://cs.chromium.org/chromium/src/net/base/net_error_list.h?l=32 */ }); } From f20bbbe8db6b37d4414177a030284110505d1b68 Mon Sep 17 00:00:00 2001 From: Johannes Date: Mon, 4 Apr 2022 15:18:50 +0200 Subject: [PATCH 002/121] updates --- .../electron-main/protocolMainService.ts | 19 +++++++++++++------ .../electron-main/webviewProtocolProvider.ts | 5 ++--- .../webview/browser/pre/service-worker.js | 1 + 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/vs/platform/protocol/electron-main/protocolMainService.ts b/src/vs/platform/protocol/electron-main/protocolMainService.ts index e1e479338c9bc..b814f18ed362a 100644 --- a/src/vs/platform/protocol/electron-main/protocolMainService.ts +++ b/src/vs/platform/protocol/electron-main/protocolMainService.ts @@ -88,8 +88,12 @@ export class ProtocolMainService extends Disposable implements IProtocolMainServ //#region vscode-file:// - private static crossOriginRoots = new Set([ - 'workbench.html', + private static coopRoots = new Set([ + 'workbench.html' + ]); + + private static coepRoots = new Set([ + ...ProtocolMainService.coopRoots, 'webWorkerExtensionHostIframe.html', 'workerMain.js', ]); @@ -99,15 +103,18 @@ export class ProtocolMainService extends Disposable implements IProtocolMainServ // first check by validRoots if (this.validRoots.findSubstr(path)) { - let headers: Record | undefined; - if (ProtocolMainService.crossOriginRoots.has(basename(path))) { + if (ProtocolMainService.coepRoots.has(basename(path))) { headers = { - 'Cross-Origin-Opener-Policy': 'same-origin', 'Cross-Origin-Embedder-Policy': 'require-corp' }; } - + if (ProtocolMainService.coopRoots.has(basename(path))) { + headers = { + ...headers, + 'Cross-Origin-Opener-Policy': 'same-origin' + }; + } return callback({ path, headers }); } diff --git a/src/vs/platform/webview/electron-main/webviewProtocolProvider.ts b/src/vs/platform/webview/electron-main/webviewProtocolProvider.ts index 652a5d7484f2c..22cc610a54110 100644 --- a/src/vs/platform/webview/electron-main/webviewProtocolProvider.ts +++ b/src/vs/platform/webview/electron-main/webviewProtocolProvider.ts @@ -39,9 +39,8 @@ export class WebviewProtocolProvider extends Disposable { return callback({ path: decodeURIComponent(url.fsPath), headers: { - 'Cross-Origin-Opener-Policy': 'same-origin', - 'Cross-Origin-Embedder-Policy': 'require-corp', - 'Cross-Origin-Resource-Policy': 'cross-origin' + 'Cross-Origin-Resource-Policy': 'cross-origin', + 'Cross-Origin-Embedder-Policy': 'credentialless' } }); } else { diff --git a/src/vs/workbench/contrib/webview/browser/pre/service-worker.js b/src/vs/workbench/contrib/webview/browser/pre/service-worker.js index 70534ee470d48..6a0b0225d2c6e 100644 --- a/src/vs/workbench/contrib/webview/browser/pre/service-worker.js +++ b/src/vs/workbench/contrib/webview/browser/pre/service-worker.js @@ -270,6 +270,7 @@ async function processResourceRequest(event, requestUrlComponents) { 'Content-Type': entry.mime, 'Content-Length': entry.data.byteLength.toString(), 'Access-Control-Allow-Origin': '*', + 'Cross-Origin-Resource-Policy': 'cross-origin' }; if (entry.etag) { headers['ETag'] = entry.etag; From 97a0f6c872c292cf03ebcddd0cc436ad0ea937fc Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Tue, 21 Jun 2022 08:27:32 +0000 Subject: [PATCH 003/121] =?UTF-8?q?=F0=9F=94=A8=20Take=20out=20core=20func?= =?UTF-8?q?tionality=20class=20from=20SurroundWithSnippet=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- .../snippets/browser/surroundWithSnippet.ts | 87 +++++++++++++------ 1 file changed, 60 insertions(+), 27 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts index 80d25b059685f..7c6ea9d818a54 100644 --- a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts @@ -10,51 +10,84 @@ import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetCon import { localize } from 'vs/nls'; import { registerAction2 } from 'vs/platform/actions/common/actions'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; -import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; +import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { pickSnippet } from 'vs/workbench/contrib/snippets/browser/snippetPicker'; -import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets.contribution'; +import { ISnippetsService } from './snippets.contribution'; +const options = { + id: 'editor.action.surroundWithSnippet', + title: { + value: localize('label', 'Surround With Snippet...'), + original: 'Surround With Snippet...' + }, + precondition: ContextKeyExpr.and( + EditorContextKeys.writable, + EditorContextKeys.hasNonEmptySelection + ), + f1: true, +}; -registerAction2(class SurroundWithAction extends EditorAction2 { +class SurroundWithSnippet { + constructor( + private readonly _editor: ICodeEditor, + @ISnippetsService private readonly _snippetService: ISnippetsService, + @IClipboardService private readonly _clipboardService: IClipboardService, + @IContextKeyService private readonly _contextKeyService: IContextKeyService, + @IInstantiationService private readonly _instaService: IInstantiationService, + ) { } - constructor() { - super({ - id: 'editor.action.surroundWithSnippet', - title: { value: localize('label', 'Surround With Snippet...'), original: 'Surround With Snippet...' }, - precondition: ContextKeyExpr.and(EditorContextKeys.writable, EditorContextKeys.hasNonEmptySelection), - f1: true - }); - } + async getSurroundableSnippets(): Promise { + if (!this._editor.hasModel()) { + return []; + } - async runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: any[]) { + const model = this._editor.getModel(); + const { lineNumber, column } = this._editor.getPosition(); + model.tokenization.tokenizeIfCheap(lineNumber); + const languageId = model.getLanguageIdAtPosition(lineNumber, column); - const snippetService = accessor.get(ISnippetsService); - const clipboardService = accessor.get(IClipboardService); - const instaService = accessor.get(IInstantiationService); + const allSnippets = await this._snippetService.getSnippets(languageId, { includeNoPrefixSnippets: true, includeDisabledSnippets: true }); + return allSnippets.filter(snippet => snippet.usesSelection); + } + + canExecute(): boolean { + return this._contextKeyService.contextMatchesRules(options.precondition); + } - if (!editor.hasModel()) { + async run() { + if (!this.canExecute()) { return; } - const { lineNumber, column } = editor.getPosition(); - editor.getModel().tokenization.tokenizeIfCheap(lineNumber); - const languageId = editor.getModel().getLanguageIdAtPosition(lineNumber, column); - - const allSnippets = await snippetService.getSnippets(languageId, { includeNoPrefixSnippets: true, includeDisabledSnippets: true }); - const surroundSnippets = allSnippets.filter(snippet => snippet.usesSelection); - const snippet = await instaService.invokeFunction(pickSnippet, surroundSnippets); + const snippets = await this.getSurroundableSnippets(); + if (!snippets.length) { + return; + } + const snippet = await this._instaService.invokeFunction(pickSnippet, snippets); if (!snippet) { return; } - let clipboardText: string | undefined; if (snippet.needsClipboard) { - clipboardText = await clipboardService.readText(); + clipboardText = await this._clipboardService.readText(); } - SnippetController2.get(editor)?.insert(snippet.codeSnippet, { clipboardText }); + SnippetController2.get(this._editor)?.insert(snippet.codeSnippet, { clipboardText }); + } +} + +class SurroundWithSnippetEditorAction extends EditorAction2 { + constructor() { + super(options); } -}); + async runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: any[]) { + const instaService = accessor.get(IInstantiationService); + const core = instaService.createInstance(SurroundWithSnippet, editor); + await core.run(); + } +} + +registerAction2(SurroundWithSnippetEditorAction); From 0dcd685fb03856b2f7e6f8f0c79301be987a49c7 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Tue, 21 Jun 2022 08:35:24 +0000 Subject: [PATCH 004/121] =?UTF-8?q?=F0=9F=8E=81=20Add=20SurroundWithSnippe?= =?UTF-8?q?t=20as=20a=20`QuickFix`=20code=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- .../snippets/browser/surroundWithSnippet.ts | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts index 7c6ea9d818a54..bff88a5996646 100644 --- a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { EditorAction2 } from 'vs/editor/browser/editorExtensions'; +import { EditorAction2, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetController2'; import { localize } from 'vs/nls'; @@ -14,6 +14,15 @@ import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/commo import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { pickSnippet } from 'vs/workbench/contrib/snippets/browser/snippetPicker'; import { ISnippetsService } from './snippets.contribution'; +import { CancellationToken } from 'vs/base/common/cancellation'; +import { Disposable } from 'vs/base/common/lifecycle'; +import { ITextModel } from 'vs/editor/common/model'; +import { CodeAction, CodeActionProvider, CodeActionContext, CodeActionList } from 'vs/editor/common/languages'; +import { CodeActionKind } from 'vs/editor/contrib/codeAction/browser/types'; +import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; +import { Range } from 'vs/editor/common/core/range'; +import { Selection } from 'vs/editor/common/core/selection'; +import { Snippet } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; const options = { id: 'editor.action.surroundWithSnippet', @@ -91,3 +100,40 @@ class SurroundWithSnippetEditorAction extends EditorAction2 { } registerAction2(SurroundWithSnippetEditorAction); + + +export class SurroundWithSnippetCodeActionProvider extends Disposable implements CodeActionProvider { + private static readonly codeAction: CodeAction = { + kind: CodeActionKind.QuickFix.value, + title: options.title.value, + command: { + id: options.id, + title: options.title.value, + }, + }; + + private core: SurroundWithSnippet; + + constructor( + editor: ICodeEditor, + @ILanguageFeaturesService languageFeaturesService: ILanguageFeaturesService, + @IInstantiationService instaService: IInstantiationService, + ) { + super(); + this.core = instaService.createInstance(SurroundWithSnippet, editor); + this._register(languageFeaturesService.codeActionProvider.register('*', this)); + } + + async provideCodeActions(model: ITextModel, range: Range | Selection, context: CodeActionContext, token: CancellationToken): Promise { + if (!this.core.canExecute()) { + return { actions: [], dispose: () => { } }; + } + const snippets = await this.core.getSurroundableSnippets(); + return { + actions: snippets.length ? [SurroundWithSnippetCodeActionProvider.codeAction] : [], + dispose: () => { } + }; + } +} + +registerEditorContribution(options.id, SurroundWithSnippetCodeActionProvider); From 746bc9f571bb1121ee719751258bc7680c90c5c4 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Wed, 6 Jul 2022 14:42:12 +0000 Subject: [PATCH 005/121] =?UTF-8?q?=F0=9F=94=A8=20Move=20'Surround=20With?= =?UTF-8?q?=20Snippet'=20from=20quick=20fixes=20to=20refactorings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- .../workbench/contrib/snippets/browser/surroundWithSnippet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts index bff88a5996646..40974a31647fd 100644 --- a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts @@ -104,7 +104,7 @@ registerAction2(SurroundWithSnippetEditorAction); export class SurroundWithSnippetCodeActionProvider extends Disposable implements CodeActionProvider { private static readonly codeAction: CodeAction = { - kind: CodeActionKind.QuickFix.value, + kind: CodeActionKind.Refactor.value, title: options.title.value, command: { id: options.id, From d0f9637fb4c28c32ebd8f766c5a66fa18483152c Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Thu, 7 Jul 2022 11:27:54 +0000 Subject: [PATCH 006/121] =?UTF-8?q?=F0=9F=94=A8=20Refactor=20"Surround=20W?= =?UTF-8?q?ith=20Snippet"=20editor=20contribution=20into=20workbench=20con?= =?UTF-8?q?tribution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- .../snippets/browser/surroundWithSnippet.ts | 140 ++++++++++-------- 1 file changed, 82 insertions(+), 58 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts index 40974a31647fd..44b03099e4c77 100644 --- a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts @@ -4,13 +4,13 @@ *--------------------------------------------------------------------------------------------*/ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { EditorAction2, registerEditorContribution } from 'vs/editor/browser/editorExtensions'; +import { EditorAction2 } from 'vs/editor/browser/editorExtensions'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetController2'; import { localize } from 'vs/nls'; import { registerAction2 } from 'vs/platform/actions/common/actions'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; -import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { pickSnippet } from 'vs/workbench/contrib/snippets/browser/snippetPicker'; import { ISnippetsService } from './snippets.contribution'; @@ -23,6 +23,12 @@ import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeat import { Range } from 'vs/editor/common/core/range'; import { Selection } from 'vs/editor/common/core/selection'; import { Snippet } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; +import { Registry } from 'vs/platform/registry/common/platform'; +import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWorkbenchContribution } from 'vs/workbench/common/contributions'; +import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; +import { Position } from 'vs/editor/common/core/position'; +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { EditorInputCapabilities } from 'vs/workbench/common/editor'; const options = { id: 'editor.action.surroundWithSnippet', @@ -37,72 +43,88 @@ const options = { f1: true, }; -class SurroundWithSnippet { - constructor( - private readonly _editor: ICodeEditor, - @ISnippetsService private readonly _snippetService: ISnippetsService, - @IClipboardService private readonly _clipboardService: IClipboardService, - @IContextKeyService private readonly _contextKeyService: IContextKeyService, - @IInstantiationService private readonly _instaService: IInstantiationService, - ) { } - - async getSurroundableSnippets(): Promise { - if (!this._editor.hasModel()) { - return []; - } +const MAX_SNIPPETS_ON_CODE_ACTIONS_MENU = 6; - const model = this._editor.getModel(); - const { lineNumber, column } = this._editor.getPosition(); - model.tokenization.tokenizeIfCheap(lineNumber); - const languageId = model.getLanguageIdAtPosition(lineNumber, column); +function makeCodeActionForSnippet(snippet: Snippet): CodeAction { + const title = localize('codeAction', "Surround With Snippet: {0}", snippet.name); + return { + title, + command: { + id: 'editor.action.insertSnippet', + title, + arguments: [{ name: snippet.name }] + }, + }; +} - const allSnippets = await this._snippetService.getSnippets(languageId, { includeNoPrefixSnippets: true, includeDisabledSnippets: true }); - return allSnippets.filter(snippet => snippet.usesSelection); +async function getSurroundableSnippets(accessor: ServicesAccessor, model: ITextModel | null, position: Position | null): Promise { + if (!model) { + return []; } - canExecute(): boolean { - return this._contextKeyService.contextMatchesRules(options.precondition); + const snippetsService = accessor.get(ISnippetsService); + + let languageId: string; + if (position) { + const { lineNumber, column } = position; + model.tokenization.tokenizeIfCheap(lineNumber); + languageId = model.getLanguageIdAtPosition(lineNumber, column); + } else { + languageId = model.getLanguageId(); } - async run() { - if (!this.canExecute()) { - return; - } + const allSnippets = await snippetsService.getSnippets(languageId, { includeNoPrefixSnippets: true, includeDisabledSnippets: true }); + return allSnippets.filter(snippet => snippet.usesSelection); +} - const snippets = await this.getSurroundableSnippets(); - if (!snippets.length) { - return; - } +function canExecute(accessor: ServicesAccessor): boolean { + const editorService = accessor.get(IEditorService); - const snippet = await this._instaService.invokeFunction(pickSnippet, snippets); - if (!snippet) { - return; - } + const editor = editorService.activeEditor; + if (!editor || editor.hasCapability(EditorInputCapabilities.Readonly)) { + return false; + } + const selections = editorService.activeTextEditorControl?.getSelections(); + return !!selections && selections.length > 0; +} - let clipboardText: string | undefined; - if (snippet.needsClipboard) { - clipboardText = await this._clipboardService.readText(); - } +async function surroundWithSnippet(accessor: ServicesAccessor, editor: ICodeEditor) { + const instaService = accessor.get(IInstantiationService); + const clipboardService = accessor.get(IClipboardService); - SnippetController2.get(this._editor)?.insert(snippet.codeSnippet, { clipboardText }); + if (!canExecute(accessor)) { + return; } + + const snippets = await getSurroundableSnippets(accessor, editor.getModel(), editor.getPosition()); + if (!snippets.length) { + return; + } + + const snippet = await instaService.invokeFunction(pickSnippet, snippets); + if (!snippet) { + return; + } + + let clipboardText: string | undefined; + if (snippet.needsClipboard) { + clipboardText = await clipboardService.readText(); + } + + SnippetController2.get(editor)?.insert(snippet.codeSnippet, { clipboardText }); } -class SurroundWithSnippetEditorAction extends EditorAction2 { + +registerAction2(class SurroundWithSnippetEditorAction extends EditorAction2 { constructor() { super(options); } async runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: any[]) { - const instaService = accessor.get(IInstantiationService); - const core = instaService.createInstance(SurroundWithSnippet, editor); - await core.run(); + await surroundWithSnippet(accessor, editor); } -} - -registerAction2(SurroundWithSnippetEditorAction); +}); - -export class SurroundWithSnippetCodeActionProvider extends Disposable implements CodeActionProvider { +export class SurroundWithSnippetCodeActionProvider extends Disposable implements CodeActionProvider, IWorkbenchContribution { private static readonly codeAction: CodeAction = { kind: CodeActionKind.Refactor.value, title: options.title.value, @@ -112,28 +134,30 @@ export class SurroundWithSnippetCodeActionProvider extends Disposable implements }, }; - private core: SurroundWithSnippet; - constructor( - editor: ICodeEditor, @ILanguageFeaturesService languageFeaturesService: ILanguageFeaturesService, - @IInstantiationService instaService: IInstantiationService, + @IInstantiationService private readonly instaService: IInstantiationService, ) { super(); - this.core = instaService.createInstance(SurroundWithSnippet, editor); this._register(languageFeaturesService.codeActionProvider.register('*', this)); } async provideCodeActions(model: ITextModel, range: Range | Selection, context: CodeActionContext, token: CancellationToken): Promise { - if (!this.core.canExecute()) { + if (!this.instaService.invokeFunction(canExecute)) { + return { actions: [], dispose: () => { } }; + } + + const snippets = await this.instaService.invokeFunction(accessor => getSurroundableSnippets(accessor, model, range.getEndPosition())); + if (!snippets.length) { return { actions: [], dispose: () => { } }; } - const snippets = await this.core.getSurroundableSnippets(); return { - actions: snippets.length ? [SurroundWithSnippetCodeActionProvider.codeAction] : [], + actions: snippets.length <= MAX_SNIPPETS_ON_CODE_ACTIONS_MENU + ? snippets.map(x => makeCodeActionForSnippet(x)) + : [SurroundWithSnippetCodeActionProvider.codeAction], dispose: () => { } }; } } -registerEditorContribution(options.id, SurroundWithSnippetCodeActionProvider); +Registry.as(WorkbenchExtensions.Workbench).registerWorkbenchContribution(SurroundWithSnippetCodeActionProvider, LifecyclePhase.Restored); From d90edae487aaa27d7501f24038c1bf7b3afe3859 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Mon, 11 Jul 2022 15:03:04 +0200 Subject: [PATCH 007/121] use request service from main --- .../sharedProcess/sharedProcessMain.ts | 4 ++-- src/vs/code/electron-main/app.ts | 6 ++++++ src/vs/platform/request/common/requestIpc.ts | 15 ++++++++------- .../services/request/browser/requestService.ts | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts b/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts index 7c128863922fe..be62894fd87fd 100644 --- a/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts +++ b/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts @@ -53,7 +53,6 @@ import { FollowerLogService, LoggerChannelClient, LogLevelChannelClient } from ' import { INativeHostService } from 'vs/platform/native/electron-sandbox/native'; import product from 'vs/platform/product/common/product'; import { IProductService } from 'vs/platform/product/common/productService'; -import { RequestService } from 'vs/platform/request/browser/requestService'; import { IRequestService } from 'vs/platform/request/common/request'; import { ISharedProcessConfiguration } from 'vs/platform/sharedProcess/node/sharedProcess'; import { IStorageService } from 'vs/platform/storage/common/storage'; @@ -106,6 +105,7 @@ import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/pol import { UserDataProfilesNativeService } from 'vs/platform/userDataProfile/electron-sandbox/userDataProfile'; import { OneDataSystemWebAppender } from 'vs/platform/telemetry/browser/1dsAppender'; import { DefaultExtensionsProfileInitService } from 'vs/platform/extensionManagement/electron-sandbox/defaultExtensionsProfileInit'; +import { RequestChannelClient } from 'vs/platform/request/common/requestIpc'; class SharedProcessMain extends Disposable { @@ -254,7 +254,7 @@ class SharedProcessMain extends Disposable { services.set(IUriIdentityService, new UriIdentityService(fileService)); // Request - services.set(IRequestService, new SyncDescriptor(RequestService)); + services.set(IRequestService, new RequestChannelClient(mainProcessService.getChannel('request'))); // Checksum services.set(IChecksumService, new SyncDescriptor(ChecksumService)); diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index 1434672826815..7b23aa7154696 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -104,6 +104,8 @@ import { PolicyChannel } from 'vs/platform/policy/common/policyIpc'; import { IUserDataProfilesMainService } from 'vs/platform/userDataProfile/electron-main/userDataProfile'; import { IDefaultExtensionsProfileInitService } from 'vs/platform/extensionManagement/common/extensionManagement'; import { DefaultExtensionsProfileInitHandler } from 'vs/platform/extensionManagement/electron-main/defaultExtensionsProfileInit'; +import { RequestChannel } from 'vs/platform/request/common/requestIpc'; +import { IRequestService } from 'vs/platform/request/common/request'; /** * The main VS Code application. There will only ever be one instance, @@ -728,6 +730,10 @@ export class CodeApplication extends Disposable { mainProcessElectronServer.registerChannel('userDataProfiles', userDataProfilesService); sharedProcessClient.then(client => client.registerChannel('userDataProfiles', userDataProfilesService)); + // Request + const requestService = new RequestChannel(accessor.get(IRequestService)); + sharedProcessClient.then(client => client.registerChannel('request', requestService)); + // Update const updateChannel = new UpdateChannel(accessor.get(IUpdateService)); mainProcessElectronServer.registerChannel('update', updateChannel); diff --git a/src/vs/platform/request/common/requestIpc.ts b/src/vs/platform/request/common/requestIpc.ts index 6263e47d71cac..b529e5c5d34b5 100644 --- a/src/vs/platform/request/common/requestIpc.ts +++ b/src/vs/platform/request/common/requestIpc.ts @@ -26,31 +26,32 @@ export class RequestChannel implements IServerChannel { throw new Error('Invalid listen'); } - call(context: any, command: string, args?: any): Promise { + call(context: any, command: string, args?: any, token: CancellationToken = CancellationToken.None): Promise { switch (command) { - case 'request': return this.service.request(args[0], CancellationToken.None) + case 'request': return this.service.request(args[0], token) .then(async ({ res, stream }) => { const buffer = await streamToBuffer(stream); return [{ statusCode: res.statusCode, headers: res.headers }, buffer]; }); + case 'resolveProxy': return this.service.resolveProxy(args[0]); } throw new Error('Invalid call'); } } -export class RequestChannelClient { +export class RequestChannelClient implements IRequestService { declare readonly _serviceBrand: undefined; constructor(private readonly channel: IChannel) { } async request(options: IRequestOptions, token: CancellationToken): Promise { - return RequestChannelClient.request(this.channel, options, token); + const [res, buffer] = await this.channel.call('request', [options], token); + return { res, stream: bufferToStream(buffer) }; } - static async request(channel: IChannel, options: IRequestOptions, token: CancellationToken): Promise { - const [res, buffer] = await channel.call('request', [options]); - return { res, stream: bufferToStream(buffer) }; + async resolveProxy(url: string): Promise { + return this.channel.call('resolveProxy', [url]); } } diff --git a/src/vs/workbench/services/request/browser/requestService.ts b/src/vs/workbench/services/request/browser/requestService.ts index 1f1e7384bc6d3..14dc53328682c 100644 --- a/src/vs/workbench/services/request/browser/requestService.ts +++ b/src/vs/workbench/services/request/browser/requestService.ts @@ -41,7 +41,7 @@ export class BrowserRequestService extends RequestService { } private _makeRemoteRequest(connection: IRemoteAgentConnection, options: IRequestOptions, token: CancellationToken): Promise { - return connection.withChannel('request', channel => RequestChannelClient.request(channel, options, token)); + return connection.withChannel('request', channel => new RequestChannelClient(channel).request(options, token)); } } From 226911ccb2fe26fddf50ed4a43fc75f35b418122 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Tue, 12 Jul 2022 11:12:31 +0200 Subject: [PATCH 008/121] use setting to switch between main and browser request service --- .../sharedProcess/sharedProcessMain.ts | 4 +- .../sharedProcessRequestService.ts | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/vs/platform/request/electron-browser/sharedProcessRequestService.ts diff --git a/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts b/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts index be62894fd87fd..7f2a4965b8141 100644 --- a/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts +++ b/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts @@ -105,7 +105,7 @@ import { IPolicyService, NullPolicyService } from 'vs/platform/policy/common/pol import { UserDataProfilesNativeService } from 'vs/platform/userDataProfile/electron-sandbox/userDataProfile'; import { OneDataSystemWebAppender } from 'vs/platform/telemetry/browser/1dsAppender'; import { DefaultExtensionsProfileInitService } from 'vs/platform/extensionManagement/electron-sandbox/defaultExtensionsProfileInit'; -import { RequestChannelClient } from 'vs/platform/request/common/requestIpc'; +import { SharedProcessRequestService } from 'vs/platform/request/electron-browser/sharedProcessRequestService'; class SharedProcessMain extends Disposable { @@ -254,7 +254,7 @@ class SharedProcessMain extends Disposable { services.set(IUriIdentityService, new UriIdentityService(fileService)); // Request - services.set(IRequestService, new RequestChannelClient(mainProcessService.getChannel('request'))); + services.set(IRequestService, new SharedProcessRequestService(mainProcessService, configurationService, logService)); // Checksum services.set(IChecksumService, new SyncDescriptor(ChecksumService)); diff --git a/src/vs/platform/request/electron-browser/sharedProcessRequestService.ts b/src/vs/platform/request/electron-browser/sharedProcessRequestService.ts new file mode 100644 index 0000000000000..e8dcf7532656c --- /dev/null +++ b/src/vs/platform/request/electron-browser/sharedProcessRequestService.ts @@ -0,0 +1,47 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { CancellationToken } from 'vs/base/common/cancellation'; +import { IRequestContext, IRequestOptions } from 'vs/base/parts/request/common/request'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/services'; +import { ILogService } from 'vs/platform/log/common/log'; +import { RequestService } from 'vs/platform/request/browser/requestService'; +import { IRequestService } from 'vs/platform/request/common/request'; +import { RequestChannelClient } from 'vs/platform/request/common/requestIpc'; + +export class SharedProcessRequestService implements IRequestService { + + declare readonly _serviceBrand: undefined; + + private readonly browserRequestService: IRequestService; + private readonly mainRequestService: IRequestService; + + constructor( + mainProcessService: IMainProcessService, + private readonly configurationService: IConfigurationService, + private readonly logService: ILogService, + ) { + this.browserRequestService = new RequestService(configurationService, logService); + this.mainRequestService = new RequestChannelClient(mainProcessService.getChannel('request')); + } + + request(options: IRequestOptions, token: CancellationToken): Promise { + return this.getRequestService().request(options, token); + } + + async resolveProxy(url: string): Promise { + return this.getRequestService().resolveProxy(url); + } + + private getRequestService(): IRequestService { + if (this.configurationService.getValue('developer.sharedProcess.useBrowserRequestService') === true) { + this.logService.trace('Using browser request service'); + return this.browserRequestService; + } + this.logService.trace('Using main request service'); + return this.mainRequestService; + } +} From e0e5339bf737a846640b693bf3a12c5bdc8a5ae2 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 12 Jul 2022 12:56:42 -0700 Subject: [PATCH 009/121] Shell integration CLI progress --- scripts/code-cli.bat | 4 ++-- src/vs/code/node/cli.ts | 19 +++++++++++++++++++ src/vs/platform/environment/common/argv.ts | 1 + src/vs/platform/environment/node/argv.ts | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/scripts/code-cli.bat b/scripts/code-cli.bat index 2b3c9db3ca3bd..482dba274b13e 100644 --- a/scripts/code-cli.bat +++ b/scripts/code-cli.bat @@ -6,7 +6,7 @@ title VSCode Dev pushd %~dp0.. :: Get electron, compile, built-in extensions -if "%VSCODE_SKIP_PRELAUNCH%"=="" node build/lib/preLaunch.js +@REM if "%VSCODE_SKIP_PRELAUNCH%"=="" node build/lib/preLaunch.js for /f "tokens=2 delims=:," %%a in ('findstr /R /C:"\"nameShort\":.*" product.json') do set NAMESHORT=%%~a set NAMESHORT=%NAMESHORT: "=% @@ -24,7 +24,7 @@ set ELECTRON_ENABLE_LOGGING=1 set ELECTRON_ENABLE_STACK_DUMPING=1 :: Launch Code -%CODE% --inspect=5874 out\cli.js --ms-enable-electron-run-as-node %~dp0.. %* +%CODE% out\cli.js --ms-enable-electron-run-as-node %~dp0.. %* goto end :builtin diff --git a/src/vs/code/node/cli.ts b/src/vs/code/node/cli.ts index 80e5dec517d04..ee641c05cf65f 100644 --- a/src/vs/code/node/cli.ts +++ b/src/vs/code/node/cli.ts @@ -24,6 +24,8 @@ import product from 'vs/platform/product/common/product'; import { CancellationTokenSource } from 'vs/base/common/cancellation'; import { randomPath } from 'vs/base/common/extpath'; import { Utils } from 'vs/platform/profiling/common/profiling'; +import { dirname } from 'vs/base/common/resources'; +import { FileAccess } from 'vs/base/common/network'; function shouldSpawnCliProcess(argv: NativeParsedArgs): boolean { return !!argv['install-source'] @@ -59,6 +61,23 @@ export async function main(argv: string[]): Promise { console.log(buildVersionMessage(product.version, product.commit)); } + // Shell integration + else if (args['shell-integration']) { + // Silently fail when the terminal is not VS Code's integrated terminal + if (process.env['TERM_PROGRAM'] !== 'vscode') { + return; + } + let p: string; + switch (args['shell-integration']) { + case 'bash': p = 'vs\\workbench\\contrib\\terminal\\browser\\media\\shellIntegration-bash.sh'; break; + // Usage: if ($s=$(code --shell-integration pwsh)) { . $s } + case 'pwsh': p = 'vs\\workbench\\contrib\\terminal\\browser\\media\\shellIntegration.ps1'; break; + case 'zsh': p = 'vs\\workbench\\contrib\\terminal\\browser\\media\\shellIntegration-rc.zsh'; break; + default: throw new Error('Error using --shell-integration: Invalid shell type'); + } + console.log(`${dirname(FileAccess.asFileUri('', require)).fsPath}\\out\\${p}`); + } + // Extensions Management else if (shouldSpawnCliProcess(args)) { const cli = await new Promise((resolve, reject) => require(['vs/code/node/cliProcessMain'], resolve, reject)); diff --git a/src/vs/platform/environment/common/argv.ts b/src/vs/platform/environment/common/argv.ts index 0e8ccc14714cd..08cf04683b512 100644 --- a/src/vs/platform/environment/common/argv.ts +++ b/src/vs/platform/environment/common/argv.ts @@ -89,6 +89,7 @@ export interface NativeParsedArgs { 'logsPath'?: string; '__enable-file-policy'?: boolean; editSessionId?: string; + 'shell-integration'?: string; // chromium command line args: https://electronjs.org/docs/all#supported-chrome-command-line-switches 'no-proxy-server'?: boolean; diff --git a/src/vs/platform/environment/node/argv.ts b/src/vs/platform/environment/node/argv.ts index e27a89390c2fd..86f2aeaa349db 100644 --- a/src/vs/platform/environment/node/argv.ts +++ b/src/vs/platform/environment/node/argv.ts @@ -127,6 +127,7 @@ export const OPTIONS: OptionDescriptions> = { 'logsPath': { type: 'string' }, '__enable-file-policy': { type: 'boolean' }, 'editSessionId': { type: 'string' }, + 'shell-integration': { type: 'boolean' }, // chromium flags 'no-proxy-server': { type: 'boolean' }, From f3399f6679352a8ce06cf9812069ebb81ca5b3ab Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 13 Jul 2022 03:22:17 -0700 Subject: [PATCH 010/121] Support bash and zsh paths too --- src/vs/code/node/cli.ts | 15 +++++++++------ src/vs/platform/environment/node/argv.ts | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/vs/code/node/cli.ts b/src/vs/code/node/cli.ts index ee641c05cf65f..42bf8bdee8c23 100644 --- a/src/vs/code/node/cli.ts +++ b/src/vs/code/node/cli.ts @@ -26,6 +26,7 @@ import { randomPath } from 'vs/base/common/extpath'; import { Utils } from 'vs/platform/profiling/common/profiling'; import { dirname } from 'vs/base/common/resources'; import { FileAccess } from 'vs/base/common/network'; +import { join } from 'path'; function shouldSpawnCliProcess(argv: NativeParsedArgs): boolean { return !!argv['install-source'] @@ -67,15 +68,17 @@ export async function main(argv: string[]): Promise { if (process.env['TERM_PROGRAM'] !== 'vscode') { return; } - let p: string; + let file: string; switch (args['shell-integration']) { - case 'bash': p = 'vs\\workbench\\contrib\\terminal\\browser\\media\\shellIntegration-bash.sh'; break; - // Usage: if ($s=$(code --shell-integration pwsh)) { . $s } - case 'pwsh': p = 'vs\\workbench\\contrib\\terminal\\browser\\media\\shellIntegration.ps1'; break; - case 'zsh': p = 'vs\\workbench\\contrib\\terminal\\browser\\media\\shellIntegration-rc.zsh'; break; + // Usage: `. "$(code --shell-integration bash)"` + case 'bash': file = 'shellIntegration-bash.sh'; break; + // Usage: `if ($s=$(code --shell-integration pwsh)) { . $s }` + case 'pwsh': file = 'shellIntegration.ps1'; break; + // Usage: `. "$(code --shell-integration zsh)"` + case 'zsh': file = 'shellIntegration-rc.zsh'; break; default: throw new Error('Error using --shell-integration: Invalid shell type'); } - console.log(`${dirname(FileAccess.asFileUri('', require)).fsPath}\\out\\${p}`); + console.log(join(dirname(FileAccess.asFileUri('', require)).fsPath, 'out', 'vs', 'workbench', 'contrib', 'terminal', 'browser', 'media', file)); } // Extensions Management diff --git a/src/vs/platform/environment/node/argv.ts b/src/vs/platform/environment/node/argv.ts index 86f2aeaa349db..d809cb792b8f2 100644 --- a/src/vs/platform/environment/node/argv.ts +++ b/src/vs/platform/environment/node/argv.ts @@ -127,7 +127,7 @@ export const OPTIONS: OptionDescriptions> = { 'logsPath': { type: 'string' }, '__enable-file-policy': { type: 'boolean' }, 'editSessionId': { type: 'string' }, - 'shell-integration': { type: 'boolean' }, + 'shell-integration': { type: 'string' }, // chromium flags 'no-proxy-server': { type: 'boolean' }, From 6763f2a996c3f07220b508164b2d04cdf885b3c6 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 13 Jul 2022 03:24:23 -0700 Subject: [PATCH 011/121] Use common path instead of node path --- src/vs/code/node/cli.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vs/code/node/cli.ts b/src/vs/code/node/cli.ts index 42bf8bdee8c23..c9c452590e06d 100644 --- a/src/vs/code/node/cli.ts +++ b/src/vs/code/node/cli.ts @@ -8,7 +8,7 @@ import { chmodSync, existsSync, readFileSync, statSync, truncateSync, unlinkSync import { homedir, release, tmpdir } from 'os'; import type { ProfilingSession, Target } from 'v8-inspect-profiler'; import { Event } from 'vs/base/common/event'; -import { isAbsolute, resolve } from 'vs/base/common/path'; +import { isAbsolute, resolve, join } from 'vs/base/common/path'; import { IProcessEnvironment, isMacintosh, isWindows } from 'vs/base/common/platform'; import { randomPort } from 'vs/base/common/ports'; import { isString } from 'vs/base/common/types'; @@ -26,7 +26,6 @@ import { randomPath } from 'vs/base/common/extpath'; import { Utils } from 'vs/platform/profiling/common/profiling'; import { dirname } from 'vs/base/common/resources'; import { FileAccess } from 'vs/base/common/network'; -import { join } from 'path'; function shouldSpawnCliProcess(argv: NativeParsedArgs): boolean { return !!argv['install-source'] From 053d35b69115f32237497ba6e30b6d19c39055b3 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 13 Jul 2022 06:58:58 -0700 Subject: [PATCH 012/121] Add shell integration to options category --- src/vs/platform/environment/node/argv.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/platform/environment/node/argv.ts b/src/vs/platform/environment/node/argv.ts index d809cb792b8f2..bab5fe618d077 100644 --- a/src/vs/platform/environment/node/argv.ts +++ b/src/vs/platform/environment/node/argv.ts @@ -49,6 +49,7 @@ export const OPTIONS: OptionDescriptions> = { 'waitMarkerFilePath': { type: 'string' }, 'locale': { type: 'string', cat: 'o', args: 'locale', description: localize('locale', "The locale to use (e.g. en-US or zh-TW).") }, 'user-data-dir': { type: 'string', cat: 'o', args: 'dir', description: localize('userDataDir', "Specifies the directory that user data is kept in. Can be used to open multiple distinct instances of Code.") }, + 'shell-integration': { type: 'string', cat: 'o', args: ['bash', 'pwsh', 'zsh'], description: localize('shellIntergation', "Print the shell integration script file path for the specified shell.") }, 'help': { type: 'boolean', cat: 'o', alias: 'h', description: localize('help', "Print usage.") }, 'extensions-dir': { type: 'string', deprecates: ['extensionHomePath'], cat: 'e', args: 'dir', description: localize('extensionHomePath', "Set the root path for extensions.") }, @@ -127,7 +128,6 @@ export const OPTIONS: OptionDescriptions> = { 'logsPath': { type: 'string' }, '__enable-file-policy': { type: 'boolean' }, 'editSessionId': { type: 'string' }, - 'shell-integration': { type: 'string' }, // chromium flags 'no-proxy-server': { type: 'boolean' }, From 2ced90145812832c1e7dd6e66ce328f92ad52d34 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 13 Jul 2022 07:04:23 -0700 Subject: [PATCH 013/121] Support --shell-integration in server cli --- src/vs/server/node/serverEnvironmentService.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vs/server/node/serverEnvironmentService.ts b/src/vs/server/node/serverEnvironmentService.ts index f291461470d91..2efbb4c5c9875 100644 --- a/src/vs/server/node/serverEnvironmentService.ts +++ b/src/vs/server/node/serverEnvironmentService.ts @@ -81,6 +81,7 @@ export const serverOptions: OptionDescriptions = { 'help': OPTIONS['help'], 'version': OPTIONS['version'], + 'shell-integration': OPTIONS['shell-integration'], 'compatibility': { type: 'string' }, @@ -193,6 +194,7 @@ export interface ServerParsedArgs { /* ----- server cli ----- */ help: boolean; version: boolean; + 'shell-integration'?: string; compatibility: string; From b497c1c1ff34226f632721b3f5a6845ccb3a5483 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 13 Jul 2022 07:10:50 -0700 Subject: [PATCH 014/121] Revert code-cli.bat changes --- scripts/code-cli.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/code-cli.bat b/scripts/code-cli.bat index 482dba274b13e..2b3c9db3ca3bd 100644 --- a/scripts/code-cli.bat +++ b/scripts/code-cli.bat @@ -6,7 +6,7 @@ title VSCode Dev pushd %~dp0.. :: Get electron, compile, built-in extensions -@REM if "%VSCODE_SKIP_PRELAUNCH%"=="" node build/lib/preLaunch.js +if "%VSCODE_SKIP_PRELAUNCH%"=="" node build/lib/preLaunch.js for /f "tokens=2 delims=:," %%a in ('findstr /R /C:"\"nameShort\":.*" product.json') do set NAMESHORT=%%~a set NAMESHORT=%NAMESHORT: "=% @@ -24,7 +24,7 @@ set ELECTRON_ENABLE_LOGGING=1 set ELECTRON_ENABLE_STACK_DUMPING=1 :: Launch Code -%CODE% out\cli.js --ms-enable-electron-run-as-node %~dp0.. %* +%CODE% --inspect=5874 out\cli.js --ms-enable-electron-run-as-node %~dp0.. %* goto end :builtin From 1baeb71f07630dbdb6745f891b03e6a86aa93fff Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 13 Jul 2022 07:32:24 -0700 Subject: [PATCH 015/121] Use TERM_PROGRAM conditional to activate --- src/vs/code/node/cli.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vs/code/node/cli.ts b/src/vs/code/node/cli.ts index c9c452590e06d..735a7e39669c4 100644 --- a/src/vs/code/node/cli.ts +++ b/src/vs/code/node/cli.ts @@ -69,11 +69,11 @@ export async function main(argv: string[]): Promise { } let file: string; switch (args['shell-integration']) { - // Usage: `. "$(code --shell-integration bash)"` + // Usage: `[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --shell-integration bash)"` case 'bash': file = 'shellIntegration-bash.sh'; break; - // Usage: `if ($s=$(code --shell-integration pwsh)) { . $s }` + // Usage: `if ($env:TERM_PROGRAM -eq "vscode") { . "$(code --shell-integration pwsh)" }` case 'pwsh': file = 'shellIntegration.ps1'; break; - // Usage: `. "$(code --shell-integration zsh)"` + // Usage: `[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --shell-integration zsh)"` case 'zsh': file = 'shellIntegration-rc.zsh'; break; default: throw new Error('Error using --shell-integration: Invalid shell type'); } From c6d246ebb8bbb0ad16df90760782ecf3e9f98944 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Thu, 14 Jul 2022 07:35:47 +0000 Subject: [PATCH 016/121] =?UTF-8?q?=E2=9A=97=EF=B8=8F=20Add=20stub=20imple?= =?UTF-8?q?mentation=20for=20`IWorkspaceContextService.getWorkspace`=20met?= =?UTF-8?q?hod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- .../snippet/test/browser/snippetSession.test.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts b/src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts index c9b7d0f2aa191..45d93c0540192 100644 --- a/src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts +++ b/src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts @@ -38,8 +38,15 @@ suite('SnippetSession', function () { languageConfigurationService = new TestLanguageConfigurationService(); const serviceCollection = new ServiceCollection( [ILabelService, new class extends mock() { }], - [IWorkspaceContextService, new class extends mock() { }], - [ILanguageConfigurationService, languageConfigurationService] + [ILanguageConfigurationService, languageConfigurationService], + [IWorkspaceContextService, new class extends mock() { + override getWorkspace() { + return { + id: 'workspace-id', + folders: [], + }; + } + }], ); editor = createTestCodeEditor(model, { serviceCollection }) as IActiveCodeEditor; editor.setSelections([new Selection(1, 1, 1, 1), new Selection(2, 5, 2, 5)]); From d2232aff830f02f8247b0ca514453300151c2a16 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Thu, 14 Jul 2022 07:38:15 +0000 Subject: [PATCH 017/121] =?UTF-8?q?=E2=9A=97=EF=B8=8F=20Add=20test=20to=20?= =?UTF-8?q?verify=20`SnippetSession.createEditsAndSnippetsFromEdits`=20res?= =?UTF-8?q?olves=20$SELECTION=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- .../test/browser/snippetSession.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts b/src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts index 45d93c0540192..137dfc2bb9f03 100644 --- a/src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts +++ b/src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts @@ -781,5 +781,23 @@ suite('SnippetSession', function () { assert.strictEqual(result.snippets.length, 1); assert.strictEqual(result.snippets[0].isTrivialSnippet, false); }); + + test('with $SELECTION variable', function () { + editor.getModel().setValue('Some text and a selection'); + editor.setSelections([new Selection(1, 17, 1, 26)]); + + const result = SnippetSession.createEditsAndSnippetsFromEdits( + editor, + [{ range: new Range(1, 17, 1, 26), template: 'wrapped <$SELECTION>' }], + true, true, undefined, undefined, languageConfigurationService + ); + + assert.strictEqual(result.edits.length, 1); + assert.deepStrictEqual(result.edits[0].range, new Range(1, 17, 1, 26)); + assert.deepStrictEqual(result.edits[0].text, 'wrapped '); + + assert.strictEqual(result.snippets.length, 1); + assert.strictEqual(result.snippets[0].isTrivialSnippet, true); + }); }); }); From 6ea779daca159d8a56294b4e8efa81139b6fe2e7 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Thu, 14 Jul 2022 07:38:57 +0000 Subject: [PATCH 018/121] =?UTF-8?q?=F0=9F=90=9B=20Fix=20not=20resolving=20?= =?UTF-8?q?variables=20`SnippetSession.createEditsAndSnippetsFromEdits`=20?= =?UTF-8?q?method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- .../contrib/snippet/browser/snippetSession.ts | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/vs/editor/contrib/snippet/browser/snippetSession.ts b/src/vs/editor/contrib/snippet/browser/snippetSession.ts index 74eaa5847f7a4..a25ee16b15ca0 100644 --- a/src/vs/editor/contrib/snippet/browser/snippetSession.ts +++ b/src/vs/editor/contrib/snippet/browser/snippetSession.ts @@ -535,6 +535,17 @@ export class SnippetSession { const parser = new SnippetParser(); const snippet = new TextmateSnippet(); + // snippet variables resolver + const resolver = new CompositeSnippetVariableResolver([ + editor.invokeWithinContext(accessor => new ModelBasedVariableResolver(accessor.get(ILabelService), model)), + new ClipboardBasedVariableResolver(() => clipboardText, 0, editor.getSelections().length, editor.getOption(EditorOption.multiCursorPaste) === 'spread'), + new SelectionBasedVariableResolver(model, editor.getSelection(), 0, overtypingCapturer), + new CommentBasedVariableResolver(model, editor.getSelection(), languageConfigurationService), + new TimeBasedVariableResolver, + new WorkspaceBasedVariableResolver(editor.invokeWithinContext(accessor => accessor.get(IWorkspaceContextService))), + new RandomBasedVariableResolver, + ]); + // snippetEdits = snippetEdits.sort((a, b) => Range.compareRangesUsingStarts(a.range, b.range)); let offset = 0; @@ -553,6 +564,7 @@ export class SnippetSession { } parser.parseFragment(template, snippet); + snippet.resolveVariables(resolver); const snippetText = snippet.toString(); const snippetFragmentText = snippetText.slice(offset); @@ -568,19 +580,6 @@ export class SnippetSession { // parser.ensureFinalTabstop(snippet, enforceFinalTabstop, true); - // snippet variables resolver - const resolver = new CompositeSnippetVariableResolver([ - editor.invokeWithinContext(accessor => new ModelBasedVariableResolver(accessor.get(ILabelService), model)), - new ClipboardBasedVariableResolver(() => clipboardText, 0, editor.getSelections().length, editor.getOption(EditorOption.multiCursorPaste) === 'spread'), - new SelectionBasedVariableResolver(model, editor.getSelection(), 0, overtypingCapturer), - new CommentBasedVariableResolver(model, editor.getSelection(), languageConfigurationService), - new TimeBasedVariableResolver, - new WorkspaceBasedVariableResolver(editor.invokeWithinContext(accessor => accessor.get(IWorkspaceContextService))), - new RandomBasedVariableResolver, - ]); - snippet.resolveVariables(resolver); - - return { edits, snippets: [new OneSnippet(editor, snippet, '')] From 191d74549cf2623fa09f197993efcf4c91e3958d Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Thu, 14 Jul 2022 07:41:08 +0000 Subject: [PATCH 019/121] =?UTF-8?q?=F0=9F=94=A8=20Apply=20"Surround=20With?= =?UTF-8?q?=20Snippet"=20code=20actions=20via=20workspace=20edits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- .../snippets/browser/surroundWithSnippet.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts index 44b03099e4c77..917e04e228841 100644 --- a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts @@ -20,7 +20,8 @@ import { ITextModel } from 'vs/editor/common/model'; import { CodeAction, CodeActionProvider, CodeActionContext, CodeActionList } from 'vs/editor/common/languages'; import { CodeActionKind } from 'vs/editor/contrib/codeAction/browser/types'; import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; -import { Range } from 'vs/editor/common/core/range'; +import { Range, IRange } from 'vs/editor/common/core/range'; +import { URI } from 'vs/base/common/uri'; import { Selection } from 'vs/editor/common/core/selection'; import { Snippet } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; import { Registry } from 'vs/platform/registry/common/platform'; @@ -45,15 +46,23 @@ const options = { const MAX_SNIPPETS_ON_CODE_ACTIONS_MENU = 6; -function makeCodeActionForSnippet(snippet: Snippet): CodeAction { +function makeCodeActionForSnippet(snippet: Snippet, resource: URI, range: IRange): CodeAction { const title = localize('codeAction', "Surround With Snippet: {0}", snippet.name); return { title, - command: { - id: 'editor.action.insertSnippet', - title, - arguments: [{ name: snippet.name }] - }, + edit: { + edits: [ + { + versionId: undefined, + resource: resource, + textEdit: { + insertAsSnippet: true, + text: snippet.body, + range: range + } + } + ] + } }; } @@ -153,7 +162,7 @@ export class SurroundWithSnippetCodeActionProvider extends Disposable implements } return { actions: snippets.length <= MAX_SNIPPETS_ON_CODE_ACTIONS_MENU - ? snippets.map(x => makeCodeActionForSnippet(x)) + ? snippets.map(x => makeCodeActionForSnippet(x, model.uri, range)) : [SurroundWithSnippetCodeActionProvider.codeAction], dispose: () => { } }; From c9ea02399b985dd78ae63dc1ecd5b5175e43ba81 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Thu, 14 Jul 2022 07:42:00 +0000 Subject: [PATCH 020/121] =?UTF-8?q?=F0=9F=92=84=20Improve=20field=20name?= =?UTF-8?q?=20for=20"Surround=20With=20Snippet"=20overflow=20code=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Babak K. Shandiz --- .../workbench/contrib/snippets/browser/surroundWithSnippet.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts index 917e04e228841..edac26fe64354 100644 --- a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts @@ -134,7 +134,7 @@ registerAction2(class SurroundWithSnippetEditorAction extends EditorAction2 { }); export class SurroundWithSnippetCodeActionProvider extends Disposable implements CodeActionProvider, IWorkbenchContribution { - private static readonly codeAction: CodeAction = { + private static readonly overflowCodeAction: CodeAction = { kind: CodeActionKind.Refactor.value, title: options.title.value, command: { @@ -163,7 +163,7 @@ export class SurroundWithSnippetCodeActionProvider extends Disposable implements return { actions: snippets.length <= MAX_SNIPPETS_ON_CODE_ACTIONS_MENU ? snippets.map(x => makeCodeActionForSnippet(x, model.uri, range)) - : [SurroundWithSnippetCodeActionProvider.codeAction], + : [SurroundWithSnippetCodeActionProvider.overflowCodeAction], dispose: () => { } }; } From 4398625c327bb99f4505e9ce76e076496a26af29 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 15 Jul 2022 09:59:09 +0200 Subject: [PATCH 021/121] * always show top N snippets and conditionally show action for all surroundable snippets * remove `canExecute` which isn't needed - the "framework" makes sure we only called when it makes sense * tweak styles to my preference and lipstick, try to contain things over loose functions and objects, --- .../snippets/browser/surroundWithSnippet.ts | 203 ++++++++---------- 1 file changed, 95 insertions(+), 108 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts index edac26fe64354..2d7a798594dea 100644 --- a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts @@ -14,159 +14,146 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { pickSnippet } from 'vs/workbench/contrib/snippets/browser/snippetPicker'; import { ISnippetsService } from './snippets.contribution'; -import { CancellationToken } from 'vs/base/common/cancellation'; -import { Disposable } from 'vs/base/common/lifecycle'; +import { IDisposable } from 'vs/base/common/lifecycle'; import { ITextModel } from 'vs/editor/common/model'; -import { CodeAction, CodeActionProvider, CodeActionContext, CodeActionList } from 'vs/editor/common/languages'; +import { CodeAction, CodeActionProvider, CodeActionList } from 'vs/editor/common/languages'; import { CodeActionKind } from 'vs/editor/contrib/codeAction/browser/types'; import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; import { Range, IRange } from 'vs/editor/common/core/range'; -import { URI } from 'vs/base/common/uri'; import { Selection } from 'vs/editor/common/core/selection'; import { Snippet } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; import { Registry } from 'vs/platform/registry/common/platform'; import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; import { Position } from 'vs/editor/common/core/position'; -import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { EditorInputCapabilities } from 'vs/workbench/common/editor'; - -const options = { - id: 'editor.action.surroundWithSnippet', - title: { - value: localize('label', 'Surround With Snippet...'), - original: 'Surround With Snippet...' - }, - precondition: ContextKeyExpr.and( - EditorContextKeys.writable, - EditorContextKeys.hasNonEmptySelection - ), - f1: true, -}; - -const MAX_SNIPPETS_ON_CODE_ACTIONS_MENU = 6; - -function makeCodeActionForSnippet(snippet: Snippet, resource: URI, range: IRange): CodeAction { - const title = localize('codeAction', "Surround With Snippet: {0}", snippet.name); - return { - title, - edit: { - edits: [ - { - versionId: undefined, - resource: resource, - textEdit: { - insertAsSnippet: true, - text: snippet.body, - range: range - } - } - ] - } - }; -} - -async function getSurroundableSnippets(accessor: ServicesAccessor, model: ITextModel | null, position: Position | null): Promise { - if (!model) { - return []; - } - const snippetsService = accessor.get(ISnippetsService); +async function getSurroundableSnippets(snippetsService: ISnippetsService, model: ITextModel, position: Position): Promise { - let languageId: string; - if (position) { - const { lineNumber, column } = position; - model.tokenization.tokenizeIfCheap(lineNumber); - languageId = model.getLanguageIdAtPosition(lineNumber, column); - } else { - languageId = model.getLanguageId(); - } + const { lineNumber, column } = position; + model.tokenization.tokenizeIfCheap(lineNumber); + const languageId = model.getLanguageIdAtPosition(lineNumber, column); const allSnippets = await snippetsService.getSnippets(languageId, { includeNoPrefixSnippets: true, includeDisabledSnippets: true }); return allSnippets.filter(snippet => snippet.usesSelection); } -function canExecute(accessor: ServicesAccessor): boolean { - const editorService = accessor.get(IEditorService); +class SurroundWithSnippetEditorAction extends EditorAction2 { - const editor = editorService.activeEditor; - if (!editor || editor.hasCapability(EditorInputCapabilities.Readonly)) { - return false; + static readonly options = { + id: 'editor.action.surroundWithSnippet', + title: { + value: localize('label', 'Surround With Snippet...'), + original: 'Surround With Snippet...' + } + }; + + constructor() { + super({ + ...SurroundWithSnippetEditorAction.options, + precondition: ContextKeyExpr.and( + EditorContextKeys.writable, + EditorContextKeys.hasNonEmptySelection + ), + f1: true, + }); } - const selections = editorService.activeTextEditorControl?.getSelections(); - return !!selections && selections.length > 0; -} -async function surroundWithSnippet(accessor: ServicesAccessor, editor: ICodeEditor) { - const instaService = accessor.get(IInstantiationService); - const clipboardService = accessor.get(IClipboardService); + async runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor) { + if (!editor.hasModel()) { + return; + } - if (!canExecute(accessor)) { - return; - } + const instaService = accessor.get(IInstantiationService); + const snippetsService = accessor.get(ISnippetsService); + const clipboardService = accessor.get(IClipboardService); - const snippets = await getSurroundableSnippets(accessor, editor.getModel(), editor.getPosition()); - if (!snippets.length) { - return; - } + const snippets = await getSurroundableSnippets(snippetsService, editor.getModel(), editor.getPosition()); + if (!snippets.length) { + return; + } - const snippet = await instaService.invokeFunction(pickSnippet, snippets); - if (!snippet) { - return; - } + const snippet = await instaService.invokeFunction(pickSnippet, snippets); + if (!snippet) { + return; + } - let clipboardText: string | undefined; - if (snippet.needsClipboard) { - clipboardText = await clipboardService.readText(); - } + let clipboardText: string | undefined; + if (snippet.needsClipboard) { + clipboardText = await clipboardService.readText(); + } - SnippetController2.get(editor)?.insert(snippet.codeSnippet, { clipboardText }); + SnippetController2.get(editor)?.insert(snippet.codeSnippet, { clipboardText }); + } } -registerAction2(class SurroundWithSnippetEditorAction extends EditorAction2 { - constructor() { - super(options); - } - async runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: any[]) { - await surroundWithSnippet(accessor, editor); - } -}); +class SurroundWithSnippetCodeActionProvider implements CodeActionProvider, IWorkbenchContribution { + + private static readonly _MAX_CODE_ACTIONS = 4; -export class SurroundWithSnippetCodeActionProvider extends Disposable implements CodeActionProvider, IWorkbenchContribution { - private static readonly overflowCodeAction: CodeAction = { + private static readonly _overflowCommandCodeAction: CodeAction = { kind: CodeActionKind.Refactor.value, - title: options.title.value, + title: SurroundWithSnippetEditorAction.options.title.value, command: { - id: options.id, - title: options.title.value, + id: SurroundWithSnippetEditorAction.options.id, + title: SurroundWithSnippetEditorAction.options.title.value, }, }; + private readonly _registration: IDisposable; + constructor( + @ISnippetsService private readonly _snippetService: ISnippetsService, @ILanguageFeaturesService languageFeaturesService: ILanguageFeaturesService, - @IInstantiationService private readonly instaService: IInstantiationService, ) { - super(); - this._register(languageFeaturesService.codeActionProvider.register('*', this)); + this._registration = languageFeaturesService.codeActionProvider.register('*', this); } - async provideCodeActions(model: ITextModel, range: Range | Selection, context: CodeActionContext, token: CancellationToken): Promise { - if (!this.instaService.invokeFunction(canExecute)) { - return { actions: [], dispose: () => { } }; - } + dispose(): void { + this._registration.dispose(); + } - const snippets = await this.instaService.invokeFunction(accessor => getSurroundableSnippets(accessor, model, range.getEndPosition())); + async provideCodeActions(model: ITextModel, range: Range | Selection): Promise { + + const snippets = await getSurroundableSnippets(this._snippetService, model, range.getEndPosition()); if (!snippets.length) { - return { actions: [], dispose: () => { } }; + return undefined; + } + + const actions: CodeAction[] = []; + const hasMore = snippets.length > SurroundWithSnippetCodeActionProvider._MAX_CODE_ACTIONS; + const len = Math.min(snippets.length, SurroundWithSnippetCodeActionProvider._MAX_CODE_ACTIONS); + + for (let i = 0; i < len; i++) { + actions.push(this._makeCodeActionForSnippet(snippets[i], model, range)); + } + if (hasMore) { + actions.push(SurroundWithSnippetCodeActionProvider._overflowCommandCodeAction); } return { - actions: snippets.length <= MAX_SNIPPETS_ON_CODE_ACTIONS_MENU - ? snippets.map(x => makeCodeActionForSnippet(x, model.uri, range)) - : [SurroundWithSnippetCodeActionProvider.overflowCodeAction], - dispose: () => { } + actions, + dispose() { } + }; + } + + private _makeCodeActionForSnippet(snippet: Snippet, model: ITextModel, range: IRange): CodeAction { + return { + title: localize('codeAction', "Surround With: {0}", snippet.name), + kind: CodeActionKind.Refactor.value, + edit: { + edits: [{ + versionId: model.getVersionId(), + resource: model.uri, + textEdit: { + range, + text: snippet.body, + insertAsSnippet: true, + } + }] + } }; } } +registerAction2(SurroundWithSnippetEditorAction); Registry.as(WorkbenchExtensions.Workbench).registerWorkbenchContribution(SurroundWithSnippetCodeActionProvider, LifecyclePhase.Restored); From 56f52a8af6597b3189726bf740f94fc3c2c858bd Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 13 Jul 2022 14:46:48 +0200 Subject: [PATCH 022/121] Closing dialog does not cancel (Manjaro Linux) (fix #154719) (#155049) * Closing dialog does not cancel (Manjaro Linux) (fix #154719) * set `cancelId` --- src/vs/platform/dialogs/common/dialogs.ts | 5 +++++ .../bulkEdit/browser/preview/bulkEdit.contribution.ts | 9 ++++++--- .../contrib/format/browser/formatActionsNone.ts | 5 +++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/vs/platform/dialogs/common/dialogs.ts b/src/vs/platform/dialogs/common/dialogs.ts index ace003cd2b4c5..e0f77e27d482f 100644 --- a/src/vs/platform/dialogs/common/dialogs.ts +++ b/src/vs/platform/dialogs/common/dialogs.ts @@ -273,6 +273,11 @@ export interface IDialogService { /** * Present a modal dialog to the user. * + * @param severity the severity of the message + * @param message the message to show + * @param buttons the buttons to show. By convention, the first button should be the + * primary action and the last button the "Cancel" action. + * * @returns A promise with the selected choice index. If the user refused to choose, * then a promise with index of `cancelId` option is returned. If there is no such * option then promise with index `0` is returned. diff --git a/src/vs/workbench/contrib/bulkEdit/browser/preview/bulkEdit.contribution.ts b/src/vs/workbench/contrib/bulkEdit/browser/preview/bulkEdit.contribution.ts index bad36b7ccadb3..57a34f2c7d063 100644 --- a/src/vs/workbench/contrib/bulkEdit/browser/preview/bulkEdit.contribution.ts +++ b/src/vs/workbench/contrib/bulkEdit/browser/preview/bulkEdit.contribution.ts @@ -122,11 +122,14 @@ class BulkEditPreviewContribution { const choice = await this._dialogService.show( Severity.Info, localize('overlap', "Another refactoring is being previewed."), - [localize('cancel', "Cancel"), localize('continue', "Continue")], - { detail: localize('detail', "Press 'Continue' to discard the previous refactoring and continue with the current refactoring.") } + [localize('continue', "Continue"), localize('cancel', "Cancel")], + { + detail: localize('detail', "Press 'Continue' to discard the previous refactoring and continue with the current refactoring."), + cancelId: 1 + } ); - if (choice.choice === 0) { + if (choice.choice === 1) { // this refactoring is being cancelled return []; } diff --git a/src/vs/workbench/contrib/format/browser/formatActionsNone.ts b/src/vs/workbench/contrib/format/browser/formatActionsNone.ts index b32e1dc76fbd0..0177b09bf8fbc 100644 --- a/src/vs/workbench/contrib/format/browser/formatActionsNone.ts +++ b/src/vs/workbench/contrib/format/browser/formatActionsNone.ts @@ -68,9 +68,10 @@ registerEditorAction(class FormatDocumentMultipleAction extends EditorAction { const res = await dialogService.show( Severity.Info, message, - [nls.localize('cancel', "Cancel"), nls.localize('install.formatter', "Install Formatter...")] + [nls.localize('install.formatter', "Install Formatter..."), nls.localize('cancel', "Cancel")], + { cancelId: 1 } ); - if (res.choice === 1) { + if (res.choice !== 1) { showExtensionQuery(paneCompositeService, `category:formatters ${langName}`); } } From ce243c8b3d0d52efbf022716931e260d37fd5c5c Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 13 Jul 2022 14:55:57 +0200 Subject: [PATCH 023/121] support to hide submenus too (#155063) https://github.com/microsoft/vscode/issues/154804 --- .../browser/menuEntryActionViewItem.ts | 80 +++++++++++-------- src/vs/platform/actions/common/actions.ts | 5 +- src/vs/platform/actions/common/menuService.ts | 22 ++--- 3 files changed, 59 insertions(+), 48 deletions(-) diff --git a/src/vs/platform/actions/browser/menuEntryActionViewItem.ts b/src/vs/platform/actions/browser/menuEntryActionViewItem.ts index a5f2338647d44..e9353c86faab8 100644 --- a/src/vs/platform/actions/browser/menuEntryActionViewItem.ts +++ b/src/vs/platform/actions/browser/menuEntryActionViewItem.ts @@ -26,6 +26,7 @@ import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storag import { IThemeService, ThemeIcon } from 'vs/platform/theme/common/themeService'; import { isDark } from 'vs/platform/theme/common/theme'; import { IHoverDelegate } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate'; +import { assertType } from 'vs/base/common/types'; export function createAndFillInContextMenuActions(menu: IMenu, options: IMenuActionOptions | undefined, target: IAction[] | { primary: IAction[]; secondary: IAction[] }, primaryGroup?: string): IDisposable { const groups = menu.getActions(options); @@ -129,6 +130,23 @@ export interface IMenuEntryActionViewItemOptions { hoverDelegate?: IHoverDelegate; } +function registerConfigureMenu(contextMenuService: IContextMenuService, item: BaseActionViewItem, action: MenuItemAction | SubmenuItemAction): IDisposable { + assertType(item.element); + return addDisposableListener(item.element, 'contextmenu', event => { + if (!action.hideActions) { + return; + } + + event.preventDefault(); + event.stopPropagation(); + + contextMenuService.showContextMenu({ + getAnchor: () => item.element!, + getActions: () => action.hideActions!.asList() + }); + }, true); +} + export class MenuEntryActionViewItem extends ActionViewItem { private _wantsAltCommand: boolean = false; @@ -204,20 +222,7 @@ export class MenuEntryActionViewItem extends ActionViewItem { updateAltState(); })); - - this._register(addDisposableListener(container, 'contextmenu', event => { - if (!this._menuItemAction.hideActions) { - return; - } - - event.preventDefault(); - event.stopPropagation(); - - this._contextMenuService.showContextMenu({ - getAnchor: () => container, - getActions: () => this._menuItemAction.hideActions!.asList() - }); - }, true)); + this._register(registerConfigureMenu(this._contextMenuService, this, this._menuItemAction)); } override updateLabel(): void { @@ -308,7 +313,7 @@ export class SubmenuEntryActionViewItem extends DropdownMenuActionViewItem { constructor( action: SubmenuItemAction, options: IDropdownMenuActionViewItemOptions | undefined, - @IContextMenuService contextMenuService: IContextMenuService, + @IContextMenuService protected _contextMenuService: IContextMenuService, @IThemeService protected _themeService: IThemeService ) { const dropdownOptions = Object.assign({}, options ?? Object.create(null), { @@ -316,32 +321,35 @@ export class SubmenuEntryActionViewItem extends DropdownMenuActionViewItem { classNames: options?.classNames ?? (ThemeIcon.isThemeIcon(action.item.icon) ? ThemeIcon.asClassName(action.item.icon) : undefined), }); - super(action, { getActions: () => action.actions }, contextMenuService, dropdownOptions); + super(action, { getActions: () => action.actions }, _contextMenuService, dropdownOptions); } override render(container: HTMLElement): void { super.render(container); - if (this.element) { - container.classList.add('menu-entry'); - const { icon } = (this._action).item; - if (icon && !ThemeIcon.isThemeIcon(icon)) { - this.element.classList.add('icon'); - const setBackgroundImage = () => { - if (this.element) { - this.element.style.backgroundImage = ( - isDark(this._themeService.getColorTheme().type) - ? asCSSUrl(icon.dark) - : asCSSUrl(icon.light) - ); - } - }; + assertType(this.element); + + container.classList.add('menu-entry'); + const action = this._action; + const { icon } = action.item; + if (icon && !ThemeIcon.isThemeIcon(icon)) { + this.element.classList.add('icon'); + const setBackgroundImage = () => { + if (this.element) { + this.element.style.backgroundImage = ( + isDark(this._themeService.getColorTheme().type) + ? asCSSUrl(icon.dark) + : asCSSUrl(icon.light) + ); + } + }; + setBackgroundImage(); + this._register(this._themeService.onDidColorThemeChange(() => { + // refresh when the theme changes in case we go between dark <-> light setBackgroundImage(); - this._register(this._themeService.onDidColorThemeChange(() => { - // refresh when the theme changes in case we go between dark <-> light - setBackgroundImage(); - })); - } + })); } + + this._register(registerConfigureMenu(this._contextMenuService, this, action)); } } @@ -461,6 +469,8 @@ export class DropdownWithDefaultActionViewItem extends BaseActionViewItem { event.stopPropagation(); } })); + + this._register(registerConfigureMenu(this._contextMenuService, this, (this.action))); } override focus(fromRight?: boolean): void { diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index 461df3221c1a3..79fbc7424c325 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -35,11 +35,11 @@ export interface ISubmenuItem { rememberDefaultAction?: boolean; // for dropdown menu: if true the last executed action is remembered as the default action } -export function isIMenuItem(item: IMenuItem | ISubmenuItem): item is IMenuItem { +export function isIMenuItem(item: any): item is IMenuItem { return (item as IMenuItem).command !== undefined; } -export function isISubmenuItem(item: IMenuItem | ISubmenuItem): item is ISubmenuItem { +export function isISubmenuItem(item: any): item is ISubmenuItem { return (item as ISubmenuItem).submenu !== undefined; } @@ -350,6 +350,7 @@ export class SubmenuItemAction extends SubmenuAction { constructor( readonly item: ISubmenuItem, + readonly hideActions: MenuItemActionManageActions, private readonly _menuService: IMenuService, private readonly _contextKeyService: IContextKeyService, private readonly _options?: IMenuActionOptions diff --git a/src/vs/platform/actions/common/menuService.ts b/src/vs/platform/actions/common/menuService.ts index 5d2092cc1c5bc..fce79d84ad9aa 100644 --- a/src/vs/platform/actions/common/menuService.ts +++ b/src/vs/platform/actions/common/menuService.ts @@ -6,7 +6,7 @@ import { RunOnceScheduler } from 'vs/base/common/async'; import { Emitter, Event } from 'vs/base/common/event'; import { DisposableStore } from 'vs/base/common/lifecycle'; -import { IMenu, IMenuActionOptions, IMenuCreateOptions, IMenuItem, IMenuService, isIMenuItem, ISubmenuItem, MenuId, MenuItemAction, MenuItemActionManageActions, MenuRegistry, SubmenuItemAction } from 'vs/platform/actions/common/actions'; +import { IMenu, IMenuActionOptions, IMenuCreateOptions, IMenuItem, IMenuService, isIMenuItem, isISubmenuItem, ISubmenuItem, MenuId, MenuItemAction, MenuItemActionManageActions, MenuRegistry, SubmenuItemAction } from 'vs/platform/actions/common/actions'; import { ICommandAction, ILocalizedString } from 'vs/platform/action/common/action'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { ContextKeyExpression, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; @@ -251,18 +251,17 @@ class Menu implements IMenu { for (const item of items) { if (this._contextKeyService.contextMatchesRules(item.when)) { let action: MenuItemAction | SubmenuItemAction | undefined; - if (isIMenuItem(item)) { + const isMenuItem = isIMenuItem(item); + const hideActions = new MenuItemActionManageActions(new HideMenuItemAction(this._id, isMenuItem ? item.command : item, this._hiddenStates), allToggleActions); + + if (isMenuItem) { if (!this._hiddenStates.isHidden(this._id, item.command.id)) { - action = new MenuItemAction( - item.command, item.alt, options, - new MenuItemActionManageActions(new HideMenuItemAction(this._id, item.command, this._hiddenStates), allToggleActions), - this._contextKeyService, this._commandService - ); + action = new MenuItemAction(item.command, item.alt, options, hideActions, this._contextKeyService, this._commandService); } // add toggle commmand toggleActions.push(new ToggleMenuItemAction(this._id, item.command, this._hiddenStates)); } else { - action = new SubmenuItemAction(item, this._menuService, this._contextKeyService, options); + action = new SubmenuItemAction(item, hideActions, this._menuService, this._contextKeyService, options); if (action.actions.length === 0) { action.dispose(); action = undefined; @@ -397,10 +396,11 @@ class HideMenuItemAction implements IAction { run: () => void; - constructor(id: MenuId, command: ICommandAction, hiddenStates: PersistedMenuHideState) { - this.id = `hide/${id.id}/${command.id}`; + constructor(menu: MenuId, command: ICommandAction | ISubmenuItem, hiddenStates: PersistedMenuHideState) { + const id = isISubmenuItem(command) ? command.submenu.id : command.id; + this.id = `hide/${menu.id}/${id}`; this.label = localize('hide.label', 'Hide \'{0}\'', typeof command.title === 'string' ? command.title : command.title.value); - this.run = () => { hiddenStates.updateHidden(id, command.id, true); }; + this.run = () => { hiddenStates.updateHidden(menu, id, true); }; } dispose(): void { From 15daddd7af3d86714ff93195d964e0a70f594a2f Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Wed, 13 Jul 2022 16:39:18 +0200 Subject: [PATCH 024/121] git - Add localization comment for Publish Branch action button (#155053) * Add localization comment for Publish Branch action button * Pull request feedback --- extensions/git/src/actionButton.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/git/src/actionButton.ts b/extensions/git/src/actionButton.ts index 0f0741eb78c36..311e9dc84d500 100644 --- a/extensions/git/src/actionButton.ts +++ b/extensions/git/src/actionButton.ts @@ -189,10 +189,10 @@ export class ActionButtonCommand { return { command: { command: 'git.publish', - title: localize('scm publish branch action button title', "{0} Publish Branch", '$(cloud-upload)'), + title: localize({ key: 'scm publish branch action button title', comment: ['{Locked="Branch"}', 'Do not translate "Branch" as it is a git term'] }, "{0} Publish Branch", '$(cloud-upload)'), tooltip: this.state.isSyncInProgress ? - localize('scm button publish branch running', "Publishing Branch...") : - localize('scm button publish branch', "Publish Branch"), + localize({ key: 'scm button publish branch running', comment: ['{Locked="Branch"}', 'Do not translate "Branch" as it is a git term'] }, "Publishing Branch...") : + localize({ key: 'scm button publish branch', comment: ['{Locked="Branch"}', 'Do not translate "Branch" as it is a git term'] }, "Publish Branch"), arguments: [this.repository.sourceControl], }, enabled: !this.state.isSyncInProgress From 3de845b2c941c50833bfe9dc39c38c20a93d73c8 Mon Sep 17 00:00:00 2001 From: Gavin McQuistin Date: Wed, 13 Jul 2022 17:01:25 +0100 Subject: [PATCH 025/121] Fix typo in files.contribution.ts (#155016) --- src/vs/workbench/contrib/files/browser/files.contribution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/files/browser/files.contribution.ts b/src/vs/workbench/contrib/files/browser/files.contribution.ts index 1ebf70ce25758..79e57d4312d58 100644 --- a/src/vs/workbench/contrib/files/browser/files.contribution.ts +++ b/src/vs/workbench/contrib/files/browser/files.contribution.ts @@ -404,7 +404,7 @@ configurationRegistry.registerConfiguration({ }, 'explorer.expandSingleFolderWorkspaces': { 'type': 'boolean', - 'description': nls.localize('expandSingleFolderWorkspaces', "Controls whether the explorer should expand multi-root workspaces containing only one folder during initilization"), + 'description': nls.localize('expandSingleFolderWorkspaces', "Controls whether the explorer should expand multi-root workspaces containing only one folder during initialization"), 'default': true }, 'explorer.sortOrder': { From 0bb10676cb34c2f84cb5af458bbac52c196c264e Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Wed, 13 Jul 2022 12:19:15 -0400 Subject: [PATCH 026/121] Fix #150836 (#155081) --- .../contrib/welcomeGettingStarted/browser/gettingStarted.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.ts b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.ts index 497dfb1165cfe..8467fc4ed8801 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStarted.ts @@ -1193,7 +1193,7 @@ export class GettingStartedPage extends EditorPane { if (isCommand) { const keybindingLabel = this.getKeybindingLabel(command); if (keybindingLabel) { - container.appendChild($('span.shortcut-message', {}, 'Tip: Use keyboard shortcut ', $('span.keybinding', {}, keybindingLabel))); + container.appendChild($('span.shortcut-message', {}, localize('gettingStarted.keyboardTip', 'Tip: Use keyboard shortcut '), $('span.keybinding', {}, keybindingLabel))); } } From 1872598119ae9ab1a200e2db42eb65b10902d609 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Wed, 13 Jul 2022 10:17:01 -0700 Subject: [PATCH 027/121] disable decorations (#154430) --- .../terminal/browser/media/terminal.css | 4 + .../contrib/terminal/browser/terminalView.ts | 33 ++++-- .../terminal/browser/xterm/decorationAddon.ts | 110 +++++++++++++----- .../terminal/common/terminalConfiguration.ts | 19 ++- .../browser/xterm/decorationAddon.test.ts | 9 +- test/automation/src/terminal.ts | 19 +-- .../terminal-shellIntegration.test.ts | 30 ++++- 7 files changed, 169 insertions(+), 55 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/media/terminal.css b/src/vs/workbench/contrib/terminal/browser/media/terminal.css index 17933a5776d8f..16275cb511437 100644 --- a/src/vs/workbench/contrib/terminal/browser/media/terminal.css +++ b/src/vs/workbench/contrib/terminal/browser/media/terminal.css @@ -14,6 +14,10 @@ position: relative; } +.terminal-command-decoration.hide { + visibility: hidden; +} + .monaco-workbench .pane-body.integrated-terminal .terminal-outer-container, .monaco-workbench .pane-body.integrated-terminal .terminal-groups-container, .monaco-workbench .pane-body.integrated-terminal .terminal-group, diff --git a/src/vs/workbench/contrib/terminal/browser/terminalView.ts b/src/vs/workbench/contrib/terminal/browser/terminalView.ts index 9dc9017d20f10..bb3b8225a5f6a 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalView.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalView.ts @@ -46,6 +46,7 @@ import { getTerminalActionBarArgs } from 'vs/workbench/contrib/terminal/browser/ import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey'; import { getShellIntegrationTooltip } from 'vs/workbench/contrib/terminal/browser/terminalTooltip'; import { ServicesAccessor } from 'vs/editor/browser/editorExtensions'; +import { TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities'; export class TerminalViewPane extends ViewPane { private _actions: IAction[] | undefined; @@ -65,7 +66,7 @@ export class TerminalViewPane extends ViewPane { @IKeybindingService keybindingService: IKeybindingService, @IContextKeyService private readonly _contextKeyService: IContextKeyService, @IViewDescriptorService viewDescriptorService: IViewDescriptorService, - @IConfigurationService configurationService: IConfigurationService, + @IConfigurationService private readonly _configurationService: IConfigurationService, @IContextMenuService private readonly _contextMenuService: IContextMenuService, @IInstantiationService private readonly _instantiationService: IInstantiationService, @ITerminalService private readonly _terminalService: ITerminalService, @@ -81,7 +82,7 @@ export class TerminalViewPane extends ViewPane { @ITerminalProfileResolverService private readonly _terminalProfileResolverService: ITerminalProfileResolverService, @IThemeService private readonly _themeService: IThemeService ) { - super(options, keybindingService, _contextMenuService, configurationService, _contextKeyService, viewDescriptorService, _instantiationService, openerService, themeService, telemetryService); + super(options, keybindingService, _contextMenuService, _configurationService, _contextKeyService, viewDescriptorService, _instantiationService, openerService, themeService, telemetryService); this._register(this._terminalService.onDidRegisterProcessSupport(() => { if (this._actions) { for (const action of this._actions) { @@ -111,20 +112,34 @@ export class TerminalViewPane extends ViewPane { this._terminalTabbedView?.rerenderTabs(); } })); - configurationService.onDidChangeConfiguration(e => { - if ((e.affectsConfiguration(TerminalSettingId.ShellIntegrationDecorationsEnabled) && !configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationsEnabled)) || - (e.affectsConfiguration(TerminalSettingId.ShellIntegrationEnabled) && !configurationService.getValue(TerminalSettingId.ShellIntegrationEnabled))) { - this._parentDomElement?.classList.remove('shell-integration'); - } else if (configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationsEnabled) && configurationService.getValue(TerminalSettingId.ShellIntegrationEnabled)) { - this._parentDomElement?.classList.add('shell-integration'); + _configurationService.onDidChangeConfiguration(e => { + if (e.affectsConfiguration(TerminalSettingId.ShellIntegrationDecorationsEnabled) || e.affectsConfiguration(TerminalSettingId.ShellIntegrationEnabled)) { + this._updateForShellIntegration(); } }); + this._register(this._terminalService.onDidCreateInstance((i) => { + i.capabilities.onDidAddCapability(c => { + if (c === TerminalCapability.CommandDetection && !this._gutterDecorationsEnabled()) { + this._parentDomElement?.classList.add('shell-integration'); + } + }); + })); + this._updateForShellIntegration(); + } - if (configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationsEnabled) && configurationService.getValue(TerminalSettingId.ShellIntegrationEnabled)) { + private _updateForShellIntegration() { + if (this._gutterDecorationsEnabled()) { this._parentDomElement?.classList.add('shell-integration'); + } else { + this._parentDomElement?.classList.remove('shell-integration'); } } + private _gutterDecorationsEnabled(): boolean { + const decorationsEnabled = this._configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationsEnabled); + return (decorationsEnabled === 'both' || decorationsEnabled === 'gutter') && this._configurationService.getValue(TerminalSettingId.ShellIntegrationEnabled); + } + override renderBody(container: HTMLElement): void { super.renderBody(container); diff --git a/src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.ts b/src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.ts index 45b820a935ca7..31d764e8de274 100644 --- a/src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.ts +++ b/src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.ts @@ -28,13 +28,14 @@ import { IGenericMarkProperties } from 'vs/platform/terminal/common/terminalProc const enum DecorationSelector { CommandDecoration = 'terminal-command-decoration', + Hide = 'hide', ErrorColor = 'error', DefaultColor = 'default-color', Default = 'default', Codicon = 'codicon', XtermDecoration = 'xterm-decoration', - OverviewRuler = 'xterm-decoration-overview-ruler', - GenericMarkerIcon = 'codicon-circle-small-filled' + GenericMarkerIcon = 'codicon-circle-small-filled', + OverviewRuler = '.xterm-decoration-overview-ruler' } const enum DecorationStyles { @@ -51,6 +52,8 @@ export class DecorationAddon extends Disposable implements ITerminalAddon { private _contextMenuVisible: boolean = false; private _decorations: Map = new Map(); private _placeholderDecoration: IDecoration | undefined; + private _showGutterDecorations?: boolean; + private _showOverviewRulerDecorations?: boolean; private readonly _onDidRequestRunCommand = this._register(new Emitter<{ command: ITerminalCommand; copyAsHtml?: boolean }>()); readonly onDidRequestRunCommand = this._onDidRequestRunCommand.event; @@ -79,9 +82,67 @@ export class DecorationAddon extends Disposable implements ITerminalAddon { this.refreshLayouts(); } else if (e.affectsConfiguration('workbench.colorCustomizations')) { this._refreshStyles(true); + } else if (e.affectsConfiguration(TerminalSettingId.ShellIntegrationDecorationsEnabled)) { + if (this._commandDetectionListeners) { + dispose(this._commandDetectionListeners); + this._commandDetectionListeners = undefined; + } + this._updateDecorationVisibility(); } }); this._themeService.onDidColorThemeChange(() => this._refreshStyles(true)); + this._updateDecorationVisibility(); + this._register(this._capabilities.onDidAddCapability(c => { + if (c === TerminalCapability.CommandDetection) { + this._addCommandDetectionListeners(); + } + })); + this._register(this._capabilities.onDidRemoveCapability(c => { + if (c === TerminalCapability.CommandDetection) { + if (this._commandDetectionListeners) { + dispose(this._commandDetectionListeners); + this._commandDetectionListeners = undefined; + } + } + })); + } + + private _updateDecorationVisibility(): void { + const showDecorations = this._configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationsEnabled); + this._showGutterDecorations = (showDecorations === 'both' || showDecorations === 'gutter'); + this._showOverviewRulerDecorations = (showDecorations === 'both' || showDecorations === 'overviewRuler'); + this._disposeAllDecorations(); + if (this._showGutterDecorations || this._showOverviewRulerDecorations) { + this._attachToCommandCapability(); + this._updateGutterDecorationVisibility(); + } + const currentCommand = this._capabilities.get(TerminalCapability.CommandDetection)?.executingCommandObject; + if (currentCommand) { + this.registerCommandDecoration(currentCommand, true); + } + } + + private _disposeAllDecorations(): void { + this._placeholderDecoration?.dispose(); + for (const value of this._decorations.values()) { + value.decoration.dispose(); + dispose(value.disposables); + } + } + + private _updateGutterDecorationVisibility(): void { + const commandDecorationElements = document.querySelectorAll(DecorationSelector.CommandDecoration); + for (const commandDecorationElement of commandDecorationElements) { + this._updateCommandDecorationVisibility(commandDecorationElement); + } + } + + private _updateCommandDecorationVisibility(commandDecorationElement: Element): void { + if (this._showGutterDecorations) { + commandDecorationElement.classList.remove(DecorationSelector.Hide); + } else { + commandDecorationElement.classList.add(DecorationSelector.Hide); + } } public refreshLayouts(): void { @@ -128,31 +189,14 @@ export class DecorationAddon extends Disposable implements ITerminalAddon { public clearDecorations(): void { this._placeholderDecoration?.marker.dispose(); this._clearPlaceholder(); - for (const value of this._decorations.values()) { - value.decoration.dispose(); - dispose(value.disposables); - } + this._disposeAllDecorations(); this._decorations.clear(); } private _attachToCommandCapability(): void { if (this._capabilities.has(TerminalCapability.CommandDetection)) { this._addCommandDetectionListeners(); - } else { - this._register(this._capabilities.onDidAddCapability(c => { - if (c === TerminalCapability.CommandDetection) { - this._addCommandDetectionListeners(); - } - })); } - this._register(this._capabilities.onDidRemoveCapability(c => { - if (c === TerminalCapability.CommandDetection) { - if (this._commandDetectionListeners) { - dispose(this._commandDetectionListeners); - this._commandDetectionListeners = undefined; - } - } - })); } private _addCommandDetectionListeners(): void { @@ -204,13 +248,12 @@ export class DecorationAddon extends Disposable implements ITerminalAddon { } registerCommandDecoration(command: ITerminalCommand, beforeCommandExecution?: boolean): IDecoration | undefined { - if (!this._terminal || (beforeCommandExecution && command.genericMarkProperties)) { + if (!this._terminal || (beforeCommandExecution && command.genericMarkProperties) || (!this._showGutterDecorations && !this._showOverviewRulerDecorations)) { return undefined; } if (!command.marker) { throw new Error(`cannot add a decoration for a command ${JSON.stringify(command)} with no marker`); } - this._clearPlaceholder(); let color = command.exitCode === undefined ? defaultColor : command.exitCode ? errorColor : successColor; if (color && typeof color !== 'string') { @@ -220,9 +263,9 @@ export class DecorationAddon extends Disposable implements ITerminalAddon { } const decoration = this._terminal.registerDecoration({ marker: command.marker, - overviewRulerOptions: beforeCommandExecution + overviewRulerOptions: this._showOverviewRulerDecorations ? (beforeCommandExecution ? { color, position: 'left' } - : { color, position: command.exitCode ? 'right' : 'left' } + : { color, position: command.exitCode ? 'right' : 'left' }) : undefined }); if (!decoration) { return undefined; @@ -287,20 +330,25 @@ export class DecorationAddon extends Disposable implements ITerminalAddon { element.classList.remove(classes); } element.classList.add(DecorationSelector.CommandDecoration, DecorationSelector.Codicon, DecorationSelector.XtermDecoration); + if (genericMarkProperties) { element.classList.add(DecorationSelector.DefaultColor, DecorationSelector.GenericMarkerIcon); if (!genericMarkProperties.hoverMessage) { //disable the mouse pointer element.classList.add(DecorationSelector.Default); } - } else if (exitCode === undefined) { - element.classList.add(DecorationSelector.DefaultColor, DecorationSelector.Default); - element.classList.add(`codicon-${this._configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationIcon)}`); - } else if (exitCode) { - element.classList.add(DecorationSelector.ErrorColor); - element.classList.add(`codicon-${this._configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationIconError)}`); } else { - element.classList.add(`codicon-${this._configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationIconSuccess)}`); + // command decoration + this._updateCommandDecorationVisibility(element); + if (exitCode === undefined) { + element.classList.add(DecorationSelector.DefaultColor, DecorationSelector.Default); + element.classList.add(`codicon-${this._configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationIcon)}`); + } else if (exitCode) { + element.classList.add(DecorationSelector.ErrorColor); + element.classList.add(`codicon-${this._configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationIconError)}`); + } else { + element.classList.add(`codicon-${this._configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationIconSuccess)}`); + } } } diff --git a/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts b/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts index 3c5513e7c909e..c5b6caee4af99 100644 --- a/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts +++ b/src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts @@ -117,17 +117,17 @@ const terminalConfiguration: IConfigurationNode = { [TerminalSettingId.ShellIntegrationDecorationIconSuccess]: { type: 'string', default: 'primitive-dot', - markdownDescription: localize('terminal.integrated.shellIntegration.decorationIconSuccess', "Controls the icon that will be used for each command in terminals with shell integration enabled that do not have an associated exit code. Set to {0} to hide the icon or disable decorations with {1}.", '`\'\'`', '`#terminal.integrated.shellIntegration.decorationsEnabled#`') + markdownDescription: localize('terminal.integrated.shellIntegration.decorationIconSuccess', "Controls the icon that will be used for each command in terminals with shell integration enabled that do not have an associated exit code. Set to {0} to hide the icon or disable decorations with {1}.", '`\"\"`', '`#terminal.integrated.shellIntegration.decorationsEnabled#`') }, [TerminalSettingId.ShellIntegrationDecorationIconError]: { type: 'string', default: 'error-small', - markdownDescription: localize('terminal.integrated.shellIntegration.decorationIconError', "Controls the icon that will be used for each command in terminals with shell integration enabled that do have an associated exit code. Set to {0} to hide the icon or disable decorations with {1}.", '`\'\'`', '`#terminal.integrated.shellIntegration.decorationsEnabled#`') + markdownDescription: localize('terminal.integrated.shellIntegration.decorationIconError', "Controls the icon that will be used for each command in terminals with shell integration enabled that do have an associated exit code. Set to {0} to hide the icon or disable decorations with {1}.", '`\"\"`', '`#terminal.integrated.shellIntegration.decorationsEnabled#`') }, [TerminalSettingId.ShellIntegrationDecorationIcon]: { type: 'string', default: 'circle-outline', - markdownDescription: localize('terminal.integrated.shellIntegration.decorationIcon', "Controls the icon that will be used for skipped/empty commands. Set to {0} to hide the icon or disable decorations with {1}.", '`\'\'`', '`#terminal.integrated.shellIntegration.decorationsEnabled#`') + markdownDescription: localize('terminal.integrated.shellIntegration.decorationIcon', "Controls the icon that will be used for skipped/empty commands. Set to {0} to hide the icon or disable decorations with {1}.", '`\"\"`', '`#terminal.integrated.shellIntegration.decorationsEnabled#`') }, [TerminalSettingId.TabsFocusMode]: { type: 'string', @@ -546,15 +546,22 @@ const terminalConfiguration: IConfigurationNode = { }, [TerminalSettingId.ShellIntegrationEnabled]: { restricted: true, - markdownDescription: localize('terminal.integrated.shellIntegration.enabled', "Enable features like enhanced command tracking and current working directory detection. \n\nShell integration works by injecting the shell with a startup script. The script gives VS Code insight into what is happening within the terminal.\n\nSupported shells:\n\n- Linux/macOS: bash, pwsh, zsh\n - Windows: pwsh\n\nThis setting applies only when terminals are created, so you will need to restart your terminals for it to take effect.\n\n Note that the script injection may not work if you have custom arguments defined in the terminal profile, a [complex bash `PROMPT_COMMAND`](https://code.visualstudio.com/docs/editor/integrated-terminal#_complex-bash-promptcommand), or other unsupported setup."), + markdownDescription: localize('terminal.integrated.shellIntegration.enabled', "Determines whether or not shell integration is auto-injected to support features like enhanced command tracking and current working directory detection. \n\nShell integration works by injecting the shell with a startup script. The script gives VS Code insight into what is happening within the terminal.\n\nSupported shells:\n\n- Linux/macOS: bash, pwsh, zsh\n - Windows: pwsh\n\nThis setting applies only when terminals are created, so you will need to restart your terminals for it to take effect.\n\n Note that the script injection may not work if you have custom arguments defined in the terminal profile, a [complex bash `PROMPT_COMMAND`](https://code.visualstudio.com/docs/editor/integrated-terminal#_complex-bash-promptcommand), or other unsupported setup. To disable decorations, see {0}", '`#terminal.integrated.shellIntegrations.decorationsEnabled#`'), type: 'boolean', default: true }, [TerminalSettingId.ShellIntegrationDecorationsEnabled]: { restricted: true, markdownDescription: localize('terminal.integrated.shellIntegration.decorationsEnabled', "When shell integration is enabled, adds a decoration for each command."), - type: 'boolean', - default: true + type: 'string', + enum: ['both', 'gutter', 'overviewRuler', 'never'], + enumDescriptions: [ + localize('terminal.integrated.shellIntegration.decorationsEnabled.both', "Show decorations in the gutter (left) and overview ruler (right)"), + localize('terminal.integrated.shellIntegration.decorationsEnabled.gutter', "Show gutter decorations to the left of the terminal"), + localize('terminal.integrated.shellIntegration.decorationsEnabled.overviewRuler', "Show overview ruler decorations to the right of the terminal"), + localize('terminal.integrated.shellIntegration.decorationsEnabled.never', "Do not show decorations"), + ], + default: 'both' }, [TerminalSettingId.ShellIntegrationCommandHistory]: { restricted: true, diff --git a/src/vs/workbench/contrib/terminal/test/browser/xterm/decorationAddon.test.ts b/src/vs/workbench/contrib/terminal/test/browser/xterm/decorationAddon.test.ts index 3ea312e1e1e67..ddcbd66e3b2c1 100644 --- a/src/vs/workbench/contrib/terminal/test/browser/xterm/decorationAddon.test.ts +++ b/src/vs/workbench/contrib/terminal/test/browser/xterm/decorationAddon.test.ts @@ -37,7 +37,14 @@ suite('DecorationAddon', () => { const instantiationService = new TestInstantiationService(); const configurationService = new TestConfigurationService({ workbench: { - hover: { delay: 5 } + hover: { delay: 5 }, + }, + terminal: { + integrated: { + shellIntegration: { + decorationsEnabled: 'both' + } + } } }); instantiationService.stub(IThemeService, new TestThemeService()); diff --git a/test/automation/src/terminal.ts b/test/automation/src/terminal.ts index 73f169e1c056f..67f012bf483a6 100644 --- a/test/automation/src/terminal.ts +++ b/test/automation/src/terminal.ts @@ -25,7 +25,8 @@ export enum Selector { Tabs = '.tabs-list .monaco-list-row', SplitButton = '.editor .codicon-split-horizontal', XtermSplitIndex0 = '#terminal .terminal-groups-container .split-view-view:nth-child(1) .terminal-wrapper', - XtermSplitIndex1 = '#terminal .terminal-groups-container .split-view-view:nth-child(2) .terminal-wrapper' + XtermSplitIndex1 = '#terminal .terminal-groups-container .split-view-view:nth-child(2) .terminal-wrapper', + Hide = '.hide' } /** @@ -226,14 +227,18 @@ export class Terminal { await this.code.waitForElement(Selector.TerminalView, result => result === undefined); } - async assertCommandDecorations(expectedCounts?: ICommandDecorationCounts, customConfig?: { updatedIcon: string; count: number }): Promise { + async assertCommandDecorations(expectedCounts?: ICommandDecorationCounts, customIcon?: { updatedIcon: string; count: number }, showDecorations?: 'both' | 'gutter' | 'overviewRuler' | 'never'): Promise { if (expectedCounts) { - await this.code.waitForElements(Selector.CommandDecorationPlaceholder, true, decorations => decorations && decorations.length === expectedCounts.placeholder); - await this.code.waitForElements(Selector.CommandDecorationSuccess, true, decorations => decorations && decorations.length === expectedCounts.success); - await this.code.waitForElements(Selector.CommandDecorationError, true, decorations => decorations && decorations.length === expectedCounts.error); + const placeholderSelector = showDecorations === 'overviewRuler' ? `${Selector.CommandDecorationPlaceholder}${Selector.Hide}` : Selector.CommandDecorationPlaceholder; + await this.code.waitForElements(placeholderSelector, true, decorations => decorations && decorations.length === expectedCounts.placeholder); + const successSelector = showDecorations === 'overviewRuler' ? `${Selector.CommandDecorationSuccess}${Selector.Hide}` : Selector.CommandDecorationSuccess; + await this.code.waitForElements(successSelector, true, decorations => decorations && decorations.length === expectedCounts.success); + const errorSelector = showDecorations === 'overviewRuler' ? `${Selector.CommandDecorationError}${Selector.Hide}` : Selector.CommandDecorationError; + await this.code.waitForElements(errorSelector, true, decorations => decorations && decorations.length === expectedCounts.error); } - if (customConfig) { - await this.code.waitForElements(`.terminal-command-decoration.codicon-${customConfig.updatedIcon}`, true, decorations => decorations && decorations.length === customConfig.count); + + if (customIcon) { + await this.code.waitForElements(`.terminal-command-decoration.codicon-${customIcon.updatedIcon}`, true, decorations => decorations && decorations.length === customIcon.count); } } diff --git a/test/smoke/src/areas/terminal/terminal-shellIntegration.test.ts b/test/smoke/src/areas/terminal/terminal-shellIntegration.test.ts index b0f4425a1625b..23fb97dda74c7 100644 --- a/test/smoke/src/areas/terminal/terminal-shellIntegration.test.ts +++ b/test/smoke/src/areas/terminal/terminal-shellIntegration.test.ts @@ -36,7 +36,6 @@ export function setup() { }); describe('Decorations', function () { describe('Should show default icons', function () { - it('Placeholder', async () => { await createShellIntegrationProfile(); await terminal.assertCommandDecorations({ placeholder: 1, success: 0, error: 0 }); @@ -62,8 +61,37 @@ export function setup() { await settingsEditor.addUserSetting('terminal.integrated.shellIntegration.decorationIconSuccess', '"zap"'); await settingsEditor.addUserSetting('terminal.integrated.shellIntegration.decorationIconError', '"zap"'); await terminal.assertCommandDecorations(undefined, { updatedIcon: "zap", count: 3 }); + }); + }); + describe('terminal.integrated.shellIntegration.decorationsEnabled should determine gutter and overview ruler decoration visibility', function () { + beforeEach(async () => { + await settingsEditor.clearUserSettings(); + await setTerminalTestSettings(app, [['terminal.integrated.shellIntegration.enabled', 'true']]); + await createShellIntegrationProfile(); + await terminal.assertCommandDecorations({ placeholder: 1, success: 0, error: 0 }); + await terminal.runCommandInTerminal(`echo "foo"`); + await terminal.runCommandInTerminal(`bar`); + await terminal.assertCommandDecorations({ placeholder: 1, success: 1, error: 1 }); + }); + afterEach(async () => { await app.workbench.terminal.runCommand(TerminalCommandId.KillAll); }); + it('never', async () => { + await settingsEditor.addUserSetting('terminal.integrated.shellIntegration.decorationsEnabled', '"never"'); + await terminal.assertCommandDecorations({ placeholder: 0, success: 0, error: 0 }, undefined, 'never'); + }); + it('both', async () => { + await settingsEditor.addUserSetting('terminal.integrated.shellIntegration.decorationsEnabled', '"both"'); + await terminal.assertCommandDecorations({ placeholder: 1, success: 1, error: 1 }, undefined, 'both'); + }); + it('gutter', async () => { + await settingsEditor.addUserSetting('terminal.integrated.shellIntegration.decorationsEnabled', '"gutter"'); + await terminal.assertCommandDecorations({ placeholder: 1, success: 1, error: 1 }, undefined, 'gutter'); + }); + it('overviewRuler', async () => { + await settingsEditor.addUserSetting('terminal.integrated.shellIntegration.decorationsEnabled', '"overviewRuler"'); + await terminal.assertCommandDecorations({ placeholder: 1, success: 1, error: 1 }, undefined, 'overviewRuler'); + }); }); }); }); From d7079d3aaaf23681abda4844fc6f47e6ef720807 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Wed, 13 Jul 2022 13:19:33 -0400 Subject: [PATCH 028/121] Fix #153860 (#155086) --- .../contrib/files/browser/fileCommands.ts | 9 ++++++--- .../common/newFile.contribution.ts | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/files/browser/fileCommands.ts b/src/vs/workbench/contrib/files/browser/fileCommands.ts index 67ab692b6039f..0cea70cc9102a 100644 --- a/src/vs/workbench/contrib/files/browser/fileCommands.ts +++ b/src/vs/workbench/contrib/files/browser/fileCommands.ts @@ -629,7 +629,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ { isOptional: true, name: 'New Untitled File args', - description: 'The editor view type and language ID if known', + description: 'The editor view type, language ID, or resource path if known', schema: { 'type': 'object', 'properties': { @@ -638,17 +638,20 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ }, 'languageId': { 'type': 'string' + }, + 'path': { + 'type': 'string' } } } } ] }, - handler: async (accessor, args?: { languageId?: string; viewType?: string }) => { + handler: async (accessor, args?: { languageId?: string; viewType?: string; path?: string }) => { const editorService = accessor.get(IEditorService); await editorService.openEditor({ - resource: undefined, + resource: args?.path ? URI.from({ scheme: Schemas.untitled, path: `Untitled-${args.path}` }) : undefined, options: { override: args?.viewType, pinned: true diff --git a/src/vs/workbench/contrib/welcomeViews/common/newFile.contribution.ts b/src/vs/workbench/contrib/welcomeViews/common/newFile.contribution.ts index 8b87c52e229f9..02106a3341c46 100644 --- a/src/vs/workbench/contrib/welcomeViews/common/newFile.contribution.ts +++ b/src/vs/workbench/contrib/welcomeViews/common/newFile.contribution.ts @@ -45,7 +45,7 @@ registerAction2(class extends Action2 { } }); -type NewFileItem = { commandID: string; title: string; from: string; group: string }; +type NewFileItem = { commandID: string; title: string; from: string; group: string; commandArgs?: any }; class NewFileTemplatesManager extends Disposable { static Instance: NewFileTemplatesManager | undefined; @@ -162,12 +162,26 @@ class NewFileTemplatesManager extends Disposable { disposables.add(this.menu.onDidChange(() => refreshQp(this.allEntries()))); + disposables.add(qp.onDidChangeValue((val: string) => { + if (val === '') { + return; + } + const currentTextEntry: NewFileItem = { + commandID: 'workbench.action.files.newUntitledFile', + commandArgs: { languageId: undefined, viewType: undefined, path: val }, + title: localize('miNewFileWithName', "New File ({0})", val), + group: 'file', + from: builtInSource, + }; + refreshQp([currentTextEntry, ...entries]); + })); + disposables.add(qp.onDidAccept(async e => { const selected = qp.selectedItems[0] as (IQuickPickItem & NewFileItem); resolveResult(!!selected); qp.hide(); - if (selected) { await this.commandService.executeCommand(selected.commandID); } + if (selected) { await this.commandService.executeCommand(selected.commandID, selected.commandArgs); } })); disposables.add(qp.onDidHide(() => { From 90e5e4a3d4cb63e0c8a1284d5eb978dfaa7e80f3 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Wed, 13 Jul 2022 10:20:38 -0700 Subject: [PATCH 029/121] Add telemetry tracking edit session feature usage (#155084) --- .../browser/editSessions.contribution.ts | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts b/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts index 12f620df779c5..e292a79c0849f 100644 --- a/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts +++ b/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts @@ -85,6 +85,12 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo super(); if (this.environmentService.editSessionId !== undefined) { + type ResumeEvent = {}; + type ResumeClassification = { + owner: 'joyceerhl'; comment: 'Reporting when an action is resumed from an edit session identifier.'; + }; + this.telemetryService.publicLog2('editSessions.continue.resume'); + void this.resumeEditSession(this.environmentService.editSessionId).finally(() => this.environmentService.editSessionId = undefined); } @@ -148,6 +154,12 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo } async run(accessor: ServicesAccessor, workspaceUri: URI | undefined): Promise { + type ContinueEditSessionEvent = {}; + type ContinueEditSessionClassification = { + owner: 'joyceerhl'; comment: 'Reporting when the continue edit session action is run.'; + }; + that.telemetryService.publicLog2('editSessions.continue.store'); + let uri = workspaceUri ?? await that.pickContinueEditSessionDestination(); if (uri === undefined) { return; } @@ -187,7 +199,15 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo await that.progressService.withProgress({ location: ProgressLocation.Notification, title: localize('resuming edit session', 'Resuming edit session...') - }, async () => await that.resumeEditSession()); + }, async () => { + type ResumeEvent = {}; + type ResumeClassification = { + owner: 'joyceerhl'; comment: 'Reporting when the resume edit session action is invoked.'; + }; + that.telemetryService.publicLog2('editSessions.resume'); + + await that.resumeEditSession(); + }); } })); } @@ -208,7 +228,15 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo await that.progressService.withProgress({ location: ProgressLocation.Notification, title: localize('storing edit session', 'Storing edit session...') - }, async () => await that.storeEditSession(true)); + }, async () => { + type StoreEvent = {}; + type StoreClassification = { + owner: 'joyceerhl'; comment: 'Reporting when the store edit session action is invoked.'; + }; + that.telemetryService.publicLog2('editSessions.store'); + + await that.storeEditSession(true); + }); } })); } From ca4831adf65557da35757529b12bbd4e0fec1de3 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Wed, 13 Jul 2022 10:25:25 -0700 Subject: [PATCH 030/121] allow more args in run task (#154854) --- .../tasks/browser/abstractTaskService.ts | 107 ++++++++++++++---- .../contrib/tasks/browser/taskQuickPick.ts | 15 ++- .../tasks/electron-sandbox/taskService.ts | 7 +- 3 files changed, 98 insertions(+), 31 deletions(-) diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index 93cbe879116f3..89ec1896b2669 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -78,7 +78,7 @@ import { ITextEditorSelection, TextEditorSelectionRevealType } from 'vs/platform import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences'; import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation'; import { IViewsService, IViewDescriptorService } from 'vs/workbench/common/views'; -import { isWorkspaceFolder, ITaskQuickPickEntry, QUICKOPEN_DETAIL_CONFIG, TaskQuickPick, QUICKOPEN_SKIP_CONFIG, configureTaskIcon } from 'vs/workbench/contrib/tasks/browser/taskQuickPick'; +import { isWorkspaceFolder, ITaskQuickPickEntry, QUICKOPEN_DETAIL_CONFIG, TaskQuickPick, QUICKOPEN_SKIP_CONFIG, configureTaskIcon, ITaskTwoLevelQuickPickEntry } from 'vs/workbench/contrib/tasks/browser/taskQuickPick'; import { ILogService } from 'vs/platform/log/common/log'; import { once } from 'vs/base/common/functional'; import { IThemeService, ThemeIcon } from 'vs/platform/theme/common/themeService'; @@ -347,7 +347,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer return this.inTerminal(); } - private _registerCommands(): void { + private async _registerCommands(): Promise { CommandsRegistry.registerCommand({ id: 'workbench.action.tasks.runTask', handler: async (accessor, arg) => { @@ -359,8 +359,30 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer description: 'Run Task', args: [{ name: 'args', + isOptional: true, + description: nls.localize('runTask.arg', "Filters the tasks shown in the quickpick"), schema: { - 'type': 'string', + anyOf: [ + { + type: 'string', + description: nls.localize('runTask.label', "The task's label or a term to filter by") + }, + { + type: 'object', + properties: { + type: { + type: 'string', + description: nls.localize('runTask.type', "The contributed task type"), + enum: Array.from(this._providerTypes.values()).map(provider => provider) + }, + taskName: { + type: 'string', + description: nls.localize('runTask.taskName', "The task's label or a term to filter by"), + enum: await this.tasks().then((tasks) => tasks.map(t => t._label)) + } + } + } + ] } }] } @@ -2521,11 +2543,11 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer return entries; } - private async _showTwoLevelQuickPick(placeHolder: string, defaultEntry?: ITaskQuickPickEntry) { - return TaskQuickPick.show(this, this._configurationService, this._quickInputService, this._notificationService, this._dialogService, this._themeService, placeHolder, defaultEntry); + private async _showTwoLevelQuickPick(placeHolder: string, defaultEntry?: ITaskQuickPickEntry, filter?: string) { + return TaskQuickPick.show(this, this._configurationService, this._quickInputService, this._notificationService, this._dialogService, this._themeService, placeHolder, defaultEntry, filter); } - private async _showQuickPick(tasks: Promise | Task[], placeHolder: string, defaultEntry?: ITaskQuickPickEntry, group: boolean = false, sort: boolean = false, selectedEntry?: ITaskQuickPickEntry, additionalEntries?: ITaskQuickPickEntry[]): Promise { + private async _showQuickPick(tasks: Promise | Task[], placeHolder: string, defaultEntry?: ITaskQuickPickEntry, group: boolean = false, sort: boolean = false, selectedEntry?: ITaskQuickPickEntry, additionalEntries?: ITaskQuickPickEntry[], filter?: string): Promise { const tokenSource = new CancellationTokenSource(); const cancellationToken: CancellationToken = tokenSource.token; const createEntries = new Promise[]>((resolve) => { @@ -2564,7 +2586,6 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer const picker: IQuickPick = this._quickInputService.createQuickPick(); picker.placeholder = placeHolder; picker.matchOnDescription = true; - picker.onDidTriggerItemButton(context => { const task = context.item.task; this._quickInputService.cancel(); @@ -2580,7 +2601,9 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer picker.items = entries; }); picker.show(); - + if (filter) { + picker.value = filter; + } return new Promise(resolve => { this._register(picker.onDidAccept(async () => { let selection = picker.selectedItems ? picker.selectedItems[0] : undefined; @@ -2654,12 +2677,20 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer })) === true; } - private _runTaskCommand(arg?: any): void { + private async _runTaskCommand(filter?: { type?: string; taskName?: string } | string): Promise { if (!this._canRunCommand()) { return; } - const identifier = this._getTaskIdentifier(arg); - if (identifier !== undefined) { + + let typeFilter: boolean = false; + if (filter && typeof filter !== 'string') { + // name takes precedence + typeFilter = !filter?.taskName && !!filter?.type; + filter = filter?.taskName || filter?.type; + } + + const taskIdentifier: KeyedTaskIdentifier | undefined | string = this._getTaskIdentifier(filter); + if (taskIdentifier) { this._getGroupedTasks().then(async (grouped) => { const resolver = this._createResolver(grouped); const folderURIs: (URI | string)[] = this._contextService.getWorkspace().folders.map(folder => folder.uri); @@ -2668,7 +2699,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } folderURIs.push(USER_TASKS_GROUP_KEY); for (const uri of folderURIs) { - const task = await resolver.resolve(uri, identifier); + const task = await resolver.resolve(uri, taskIdentifier); if (task) { this.run(task).then(undefined, reason => { // eat the error, it has already been surfaced to the user and we don't care about it here @@ -2676,7 +2707,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer return; } } - this._doRunTaskCommand(grouped.all()); + this._doRunTaskCommand(grouped.all(), typeof taskIdentifier === 'string' ? taskIdentifier : undefined, typeFilter); }, () => { this._doRunTaskCommand(); }); @@ -2716,7 +2747,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer return { tasks, grouped }; } - private _doRunTaskCommand(tasks?: Task[]): void { + private _doRunTaskCommand(tasks?: Task[], filter?: string, typeFilter?: boolean): void { const pickThen = (task: Task | undefined | null) => { if (task === undefined) { return; @@ -2732,28 +2763,58 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer const placeholder = nls.localize('TaskService.pickRunTask', 'Select the task to run'); - this._showIgnoredFoldersMessage().then(() => { + this._showIgnoredFoldersMessage().then(async () => { if (this._configurationService.getValue(USE_SLOW_PICKER)) { let taskResult: { tasks: Promise; grouped: Promise } | undefined = undefined; if (!tasks) { taskResult = this._tasksAndGroupedTasks(); } + if (filter && typeFilter) { + const picker: IQuickPick = this._quickInputService.createQuickPick(); + picker.placeholder = nls.localize('TaskService.pickRunTask', 'Select the task to run'); + picker.matchOnDescription = true; + picker.ignoreFocusOut = false; + const taskQuickPick = new TaskQuickPick(this, this._configurationService, this._quickInputService, this._notificationService, this._themeService, this._dialogService); + const result = await taskQuickPick.doPickerSecondLevel(picker, filter); + if (result?.task) { + pickThen(result.task as Task); + taskQuickPick.dispose(); + } + return; + } this._showQuickPick(tasks ? tasks : taskResult!.tasks, placeholder, { label: '$(plus) ' + nls.localize('TaskService.noEntryToRun', 'Configure a Task'), task: null }, - true). + true, false, undefined, undefined, typeof filter === 'string' ? filter : undefined). then((entry) => { return pickThen(entry ? entry.task : undefined); }); } else { - this._showTwoLevelQuickPick(placeholder, - { - label: '$(plus) ' + nls.localize('TaskService.noEntryToRun', 'Configure a Task'), - task: null - }). - then(pickThen); + if (filter && typeFilter) { + const picker: IQuickPick = this._quickInputService.createQuickPick(); + picker.placeholder = nls.localize('TaskService.pickRunTask', 'Select the task to run'); + picker.matchOnDescription = true; + picker.ignoreFocusOut = false; + const taskQuickPick = new TaskQuickPick(this, this._configurationService, this._quickInputService, this._notificationService, this._themeService, this._dialogService); + const result = await taskQuickPick.doPickerSecondLevel(picker, filter); + if (result?.task) { + pickThen(result.task as Task); + picker.dispose(); + taskQuickPick.dispose(); + return; + } else { + return; + } + } else { + this._showTwoLevelQuickPick(placeholder, + { + label: '$(plus) ' + nls.localize('TaskService.noEntryToRun', 'Configure a Task'), + task: null + }, typeof filter === 'string' ? filter : undefined). + then(pickThen); + } } }); } @@ -3055,7 +3116,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } } - private _getTaskIdentifier(arg?: any): string | KeyedTaskIdentifier | undefined { + private _getTaskIdentifier(arg?: string | ITaskIdentifier): string | KeyedTaskIdentifier | undefined { let result: string | KeyedTaskIdentifier | undefined = undefined; if (Types.isString(arg)) { result = arg; diff --git a/src/vs/workbench/contrib/tasks/browser/taskQuickPick.ts b/src/vs/workbench/contrib/tasks/browser/taskQuickPick.ts index a2cc123e381c7..bf48327fe5d48 100644 --- a/src/vs/workbench/contrib/tasks/browser/taskQuickPick.ts +++ b/src/vs/workbench/contrib/tasks/browser/taskQuickPick.ts @@ -218,12 +218,15 @@ export class TaskQuickPick extends Disposable { return undefined; } - public async show(placeHolder: string, defaultEntry?: ITaskQuickPickEntry, startAtType?: string): Promise { + public async show(placeHolder: string, defaultEntry?: ITaskQuickPickEntry, startAtType?: string, filter?: string): Promise { const picker: IQuickPick = this._quickInputService.createQuickPick(); picker.placeholder = placeHolder; picker.matchOnDescription = true; picker.ignoreFocusOut = false; picker.show(); + if (filter) { + picker.value = filter; + } picker.onDidTriggerItemButton(async (context) => { const task = context.item.task; @@ -268,7 +271,7 @@ export class TaskQuickPick extends Disposable { do { if (Types.isString(firstLevelTask)) { // Proceed to second level of quick pick - const selectedEntry = await this._doPickerSecondLevel(picker, firstLevelTask); + const selectedEntry = await this.doPickerSecondLevel(picker, firstLevelTask); if (selectedEntry && !selectedEntry.settingType && selectedEntry.task === null) { // The user has chosen to go back to the first level firstLevelTask = await this._doPickerFirstLevel(picker, (await this.getTopLevelEntries(defaultEntry)).entries); @@ -302,7 +305,7 @@ export class TaskQuickPick extends Disposable { return firstLevelPickerResult?.task; } - private async _doPickerSecondLevel(picker: IQuickPick, type: string) { + public async doPickerSecondLevel(picker: IQuickPick, type: string) { picker.busy = true; if (type === SHOW_ALL) { const items = (await this._taskService.tasks()).filter(t => !t.configurationProperties.hide).sort((a, b) => this._sorter.compare(a, b)).map(task => this._createTaskEntry(task)); @@ -312,13 +315,13 @@ export class TaskQuickPick extends Disposable { picker.value = ''; picker.items = await this._getEntriesForProvider(type); } + picker.show(); picker.busy = false; const secondLevelPickerResult = await new Promise(resolve => { Event.once(picker.onDidAccept)(async () => { resolve(picker.selectedItems ? picker.selectedItems[0] : undefined); }); }); - return secondLevelPickerResult; } @@ -398,8 +401,8 @@ export class TaskQuickPick extends Disposable { static async show(taskService: ITaskService, configurationService: IConfigurationService, quickInputService: IQuickInputService, notificationService: INotificationService, - dialogService: IDialogService, themeService: IThemeService, placeHolder: string, defaultEntry?: ITaskQuickPickEntry) { + dialogService: IDialogService, themeService: IThemeService, placeHolder: string, defaultEntry?: ITaskQuickPickEntry, filter?: string) { const taskQuickPick = new TaskQuickPick(taskService, configurationService, quickInputService, notificationService, themeService, dialogService); - return taskQuickPick.show(placeHolder, defaultEntry); + return taskQuickPick.show(placeHolder, defaultEntry, undefined, filter); } } diff --git a/src/vs/workbench/contrib/tasks/electron-sandbox/taskService.ts b/src/vs/workbench/contrib/tasks/electron-sandbox/taskService.ts index 0620c9bc2d5ca..050ef08efde7e 100644 --- a/src/vs/workbench/contrib/tasks/electron-sandbox/taskService.ts +++ b/src/vs/workbench/contrib/tasks/electron-sandbox/taskService.ts @@ -44,6 +44,7 @@ import { IWorkspaceTrustManagementService, IWorkspaceTrustRequestService } from import { ITerminalProfileResolverService } from 'vs/workbench/contrib/terminal/common/terminal'; import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite'; import { IThemeService } from 'vs/platform/theme/common/themeService'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; interface IWorkspaceFolderConfigurationResult { workspaceFolder: IWorkspaceFolder; @@ -85,7 +86,8 @@ export class TaskService extends AbstractTaskService { @IWorkspaceTrustRequestService workspaceTrustRequestService: IWorkspaceTrustRequestService, @IWorkspaceTrustManagementService workspaceTrustManagementService: IWorkspaceTrustManagementService, @ILogService logService: ILogService, - @IThemeService themeService: IThemeService) { + @IThemeService themeService: IThemeService, + @IInstantiationService instantiationService: IInstantiationService) { super(configurationService, markerService, outputService, @@ -118,7 +120,8 @@ export class TaskService extends AbstractTaskService { workspaceTrustRequestService, workspaceTrustManagementService, logService, - themeService); + themeService, + ); this._register(lifecycleService.onBeforeShutdown(event => event.veto(this.beforeShutdown(), 'veto.tasks'))); } From d59f874fe053083e0c23c2bbc46882d6dd64b375 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Wed, 13 Jul 2022 11:42:57 -0700 Subject: [PATCH 031/121] Double check IW is the notebook changing when handling scroll events (#155095) * Fix 155092 * Review feedback --- .../contrib/interactive/browser/interactiveEditor.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts index 81992e7547da4..3462892ee8ab7 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts @@ -57,6 +57,7 @@ import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/co import { NOTEBOOK_KERNEL } from 'vs/workbench/contrib/notebook/common/notebookContextKeys'; import { ICursorPositionChangedEvent } from 'vs/editor/common/cursorEvents'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; +import { isEqual } from 'vs/base/common/resources'; const DECORATION_KEY = 'interactiveInputDecoration'; const INTERACTIVE_EDITOR_VIEW_STATE_PREFERENCE_KEY = 'InteractiveEditorViewState'; @@ -152,9 +153,11 @@ export class InteractiveEditor extends EditorPane { codeEditorService.registerDecorationType('interactive-decoration', DECORATION_KEY, {}); this._register(this.#keybindingService.onDidUpdateKeybindings(this.#updateInputDecoration, this)); this._register(this.#notebookExecutionStateService.onDidChangeCellExecution((e) => { - const cell = this.#notebookWidget.value?.getCellByHandle(e.cellHandle); - if (cell && e.changed?.state) { - this.#scrollIfNecessary(cell); + if (isEqual(e.notebook, this.#notebookWidget.value?.viewModel?.notebookDocument.uri)) { + const cell = this.#notebookWidget.value?.getCellByHandle(e.cellHandle); + if (cell && e.changed?.state) { + this.#scrollIfNecessary(cell); + } } })); } From ef3694ec1e5c5db97693fcb75382dd8ad44dd430 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Wed, 13 Jul 2022 19:31:52 +0200 Subject: [PATCH 032/121] Fix #154950 (#155089) --- .../common/abstractExtensionManagementService.ts | 6 +++--- .../common/extensionManagementUtil.ts | 14 +------------- .../extensions/browser/extensionsViewlet.ts | 7 +++---- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/vs/platform/extensionManagement/common/abstractExtensionManagementService.ts b/src/vs/platform/extensionManagement/common/abstractExtensionManagementService.ts index 0e19fa5b37b76..adb137c66f720 100644 --- a/src/vs/platform/extensionManagement/common/abstractExtensionManagementService.ts +++ b/src/vs/platform/extensionManagement/common/abstractExtensionManagementService.ts @@ -17,7 +17,7 @@ import { IExtensionsControlManifest, StatisticType, isTargetPlatformCompatible, TargetPlatformToString, ExtensionManagementErrorCode, IServerExtensionManagementService, ServerInstallOptions, ServerInstallVSIXOptions, ServerUninstallOptions, Metadata, ServerInstallExtensionEvent, ServerInstallExtensionResult, ServerUninstallExtensionEvent, ServerDidUninstallExtensionEvent } from 'vs/platform/extensionManagement/common/extensionManagement'; -import { areSameExtensions, ExtensionKey, getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData, getMaliciousExtensionsSet } from 'vs/platform/extensionManagement/common/extensionManagementUtil'; +import { areSameExtensions, ExtensionKey, getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData } from 'vs/platform/extensionManagement/common/extensionManagementUtil'; import { ExtensionType, IExtensionManifest, isApplicationScopedExtension, TargetPlatform } from 'vs/platform/extensions/common/extensions'; import { ILogService } from 'vs/platform/log/common/log'; import { IProductService } from 'vs/platform/product/common/productService'; @@ -364,8 +364,8 @@ export abstract class AbstractExtensionManagementService extends Disposable impl } private async checkAndGetCompatibleVersion(extension: IGalleryExtension, sameVersion: boolean, installPreRelease: boolean): Promise<{ extension: IGalleryExtension; manifest: IExtensionManifest }> { - const report = await this.getExtensionsControlManifest(); - if (getMaliciousExtensionsSet(report).has(extension.identifier.id)) { + const extensionsControlManifest = await this.getExtensionsControlManifest(); + if (extensionsControlManifest.malicious.some(identifier => areSameExtensions(extension.identifier, identifier))) { throw new ExtensionManagementError(nls.localize('malicious extension', "Can't install '{0}' extension since it was reported to be problematic.", extension.identifier.id), ExtensionManagementErrorCode.Malicious); } diff --git a/src/vs/platform/extensionManagement/common/extensionManagementUtil.ts b/src/vs/platform/extensionManagement/common/extensionManagementUtil.ts index 5c6f438029528..2b143f851779c 100644 --- a/src/vs/platform/extensionManagement/common/extensionManagementUtil.ts +++ b/src/vs/platform/extensionManagement/common/extensionManagementUtil.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { compareIgnoreCase } from 'vs/base/common/strings'; -import { IExtensionIdentifier, IGalleryExtension, ILocalExtension, IExtensionsControlManifest, getTargetPlatform } from 'vs/platform/extensionManagement/common/extensionManagement'; +import { IExtensionIdentifier, IGalleryExtension, ILocalExtension, getTargetPlatform } from 'vs/platform/extensionManagement/common/extensionManagement'; import { ExtensionIdentifier, IExtension, TargetPlatform } from 'vs/platform/extensions/common/extensions'; import { IFileService } from 'vs/platform/files/common/files'; import { isLinux, platform } from 'vs/base/common/platform'; @@ -146,18 +146,6 @@ export function getGalleryExtensionTelemetryData(extension: IGalleryExtension): export const BetterMergeId = new ExtensionIdentifier('pprice.better-merge'); -export function getMaliciousExtensionsSet(manifest: IExtensionsControlManifest): Set { - const result = new Set(); - - if (manifest.malicious) { - for (const extension of manifest.malicious) { - result.add(extension.id); - } - } - - return result; -} - export function getExtensionDependencies(installedExtensions: ReadonlyArray, extension: IExtension): IExtension[] { const dependencies: IExtension[] = []; const extensions = extension.manifest.extensionDependencies?.slice(0) ?? []; diff --git a/src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts b/src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts index 31cc538fa56df..ae27fb19d2bb8 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionsViewlet.ts @@ -33,7 +33,6 @@ import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storag import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { IContextKeyService, ContextKeyExpr, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; -import { getMaliciousExtensionsSet } from 'vs/platform/extensionManagement/common/extensionManagementUtil'; import { ILogService } from 'vs/platform/log/common/log'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { IHostService } from 'vs/workbench/services/host/browser/host'; @@ -60,6 +59,7 @@ import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/b import { coalesce } from 'vs/base/common/arrays'; import { extractEditorsAndFilesDropData } from 'vs/platform/dnd/browser/dnd'; import { extname } from 'vs/base/common/resources'; +import { areSameExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil'; const SearchMarketplaceExtensionsContext = new RawContextKey('searchMarketplaceExtensions', false); const SearchIntalledExtensionsContext = new RawContextKey('searchInstalledExtensions', false); @@ -807,12 +807,11 @@ export class MaliciousExtensionChecker implements IWorkbenchContribution { } private checkForMaliciousExtensions(): Promise { - return this.extensionsManagementService.getExtensionsControlManifest().then(report => { - const maliciousSet = getMaliciousExtensionsSet(report); + return this.extensionsManagementService.getExtensionsControlManifest().then(extensionsControlManifest => { return this.extensionsManagementService.getInstalled(ExtensionType.User).then(installed => { const maliciousExtensions = installed - .filter(e => maliciousSet.has(e.identifier.id)); + .filter(e => extensionsControlManifest.malicious.some(identifier => areSameExtensions(e.identifier, identifier))); if (maliciousExtensions.length) { return Promises.settled(maliciousExtensions.map(e => this.extensionsManagementService.uninstall(e).then(() => { From abde5e3debfacbc49e0ed9a4580fe32eb1b316c8 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 13 Jul 2022 12:49:37 -0700 Subject: [PATCH 033/121] Move md path completions and document links to language server (#155100) --- .../server/package.json | 7 +- .../server/src/protocol.ts | 6 +- .../server/src/server.ts | 66 ++- .../server/src/util/schemes.ts | 8 + .../server/src/workspace.ts | 50 +- .../server/yarn.lock | 10 +- .../markdown-language-features/src/client.ts | 36 +- .../src/extension.shared.ts | 5 +- .../src/languageFeatures/documentLinks.ts | 64 --- .../src/languageFeatures/pathCompletions.ts | 369 ------------ .../src/test/documentLink.test.ts | 8 +- .../src/test/documentLinkProvider.test.ts | 539 ------------------ .../src/test/pathCompletion.test.ts | 313 ---------- .../src/test/util.ts | 17 - 14 files changed, 153 insertions(+), 1345 deletions(-) create mode 100644 extensions/markdown-language-features/server/src/util/schemes.ts delete mode 100644 extensions/markdown-language-features/src/languageFeatures/pathCompletions.ts delete mode 100644 extensions/markdown-language-features/src/test/documentLinkProvider.test.ts delete mode 100644 extensions/markdown-language-features/src/test/pathCompletion.test.ts diff --git a/extensions/markdown-language-features/server/package.json b/extensions/markdown-language-features/server/package.json index f3cfb2292a12d..a71c09195ff62 100644 --- a/extensions/markdown-language-features/server/package.json +++ b/extensions/markdown-language-features/server/package.json @@ -10,17 +10,16 @@ "main": "./out/node/main", "browser": "./dist/browser/main", "dependencies": { - "vscode-languageserver": "^8.0.2-next.4", - "vscode-uri": "^3.0.3", + "vscode-languageserver": "^8.0.2-next.5`", "vscode-languageserver-textdocument": "^1.0.5", "vscode-languageserver-types": "^3.17.1", - "vscode-markdown-languageservice": "microsoft/vscode-markdown-languageservice" + "vscode-markdown-languageservice": "^0.0.0-alpha.5", + "vscode-uri": "^3.0.3" }, "devDependencies": { "@types/node": "16.x" }, "scripts": { - "postinstall": "cd node_modules/vscode-markdown-languageservice && yarn run compile-ext", "compile": "gulp compile-extension:markdown-language-features-server", "watch": "gulp watch-extension:markdown-language-features-server" } diff --git a/extensions/markdown-language-features/server/src/protocol.ts b/extensions/markdown-language-features/server/src/protocol.ts index 9f49c277ae20c..5670228ba302a 100644 --- a/extensions/markdown-language-features/server/src/protocol.ts +++ b/extensions/markdown-language-features/server/src/protocol.ts @@ -6,10 +6,12 @@ import { RequestType } from 'vscode-languageserver'; import * as md from 'vscode-markdown-languageservice'; -declare const TextDecoder: any; - export const parseRequestType: RequestType<{ uri: string }, md.Token[], any> = new RequestType('markdown/parse'); export const readFileRequestType: RequestType<{ uri: string }, number[], any> = new RequestType('markdown/readFile'); +export const statFileRequestType: RequestType<{ uri: string }, md.FileStat | undefined, any> = new RequestType('markdown/statFile'); + +export const readDirectoryRequestType: RequestType<{ uri: string }, [string, md.FileStat][], any> = new RequestType('markdown/readDirectory'); + export const findFilesRequestTypes: RequestType<{}, string[], any> = new RequestType('markdown/findFiles'); diff --git a/extensions/markdown-language-features/server/src/server.ts b/extensions/markdown-language-features/server/src/server.ts index ad2491d968860..043bc435aedae 100644 --- a/extensions/markdown-language-features/server/src/server.ts +++ b/extensions/markdown-language-features/server/src/server.ts @@ -3,27 +3,35 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Connection, InitializeParams, InitializeResult, TextDocuments } from 'vscode-languageserver'; +import { Connection, InitializeParams, InitializeResult, NotebookDocuments, TextDocuments } from 'vscode-languageserver'; import { TextDocument } from 'vscode-languageserver-textdocument'; import * as lsp from 'vscode-languageserver-types'; import * as md from 'vscode-markdown-languageservice'; +import { URI } from 'vscode-uri'; import { LogFunctionLogger } from './logging'; import { parseRequestType } from './protocol'; import { VsCodeClientWorkspace } from './workspace'; -declare const TextDecoder: any; - -export function startServer(connection: Connection) { +export async function startServer(connection: Connection) { const documents = new TextDocuments(TextDocument); - documents.listen(connection); + const notebooks = new NotebookDocuments(documents); - connection.onInitialize((_params: InitializeParams): InitializeResult => { + connection.onInitialize((params: InitializeParams): InitializeResult => { + workspace.workspaceFolders = (params.workspaceFolders ?? []).map(x => URI.parse(x.uri)); return { capabilities: { + documentLinkProvider: { resolveProvider: true }, documentSymbolProvider: true, + completionProvider: { triggerCharacters: ['.', '/', '#'] }, foldingRangeProvider: true, selectionRangeProvider: true, workspaceSymbolProvider: true, + workspace: { + workspaceFolders: { + supported: true, + changeNotifications: true, + }, + } } }; }); @@ -36,15 +44,36 @@ export function startServer(connection: Connection) { } }; - const workspace = new VsCodeClientWorkspace(connection, documents); + const workspace = new VsCodeClientWorkspace(connection, documents, notebooks); const logger = new LogFunctionLogger(connection.console.log.bind(connection.console)); const provider = md.createLanguageService({ workspace, parser, logger }); + connection.onDocumentLinks(async (params, token): Promise => { + try { + const document = documents.get(params.textDocument.uri); + if (document) { + return await provider.getDocumentLinks(document, token); + } + } catch (e) { + console.error(e.stack); + } + return []; + }); + + connection.onDocumentLinkResolve(async (link, token): Promise => { + try { + return await provider.resolveDocumentLink(link, token); + } catch (e) { + console.error(e.stack); + } + return undefined; + }); + connection.onDocumentSymbol(async (params, token): Promise => { try { const document = documents.get(params.textDocument.uri); if (document) { - return await provider.provideDocumentSymbols(document, token); + return await provider.getDocumentSymbols(document, token); } } catch (e) { console.error(e.stack); @@ -56,7 +85,7 @@ export function startServer(connection: Connection) { try { const document = documents.get(params.textDocument.uri); if (document) { - return await provider.provideFoldingRanges(document, token); + return await provider.getFoldingRanges(document, token); } } catch (e) { console.error(e.stack); @@ -68,7 +97,7 @@ export function startServer(connection: Connection) { try { const document = documents.get(params.textDocument.uri); if (document) { - return await provider.provideSelectionRanges(document, params.positions, token); + return await provider.getSelectionRanges(document, params.positions, token); } } catch (e) { console.error(e.stack); @@ -78,13 +107,26 @@ export function startServer(connection: Connection) { connection.onWorkspaceSymbol(async (params, token): Promise => { try { - return await provider.provideWorkspaceSymbols(params.query, token); + return await provider.getWorkspaceSymbols(params.query, token); } catch (e) { console.error(e.stack); } return []; }); + connection.onCompletion(async (params, token): Promise => { + try { + const document = documents.get(params.textDocument.uri); + if (document) { + return await provider.getCompletionItems(document, params.position, params.context!, token); + } + } catch (e) { + console.error(e.stack); + } + return []; + }); + + documents.listen(connection); + notebooks.listen(connection); connection.listen(); } - diff --git a/extensions/markdown-language-features/server/src/util/schemes.ts b/extensions/markdown-language-features/server/src/util/schemes.ts new file mode 100644 index 0000000000000..67b75e0a0d635 --- /dev/null +++ b/extensions/markdown-language-features/server/src/util/schemes.ts @@ -0,0 +1,8 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +export const Schemes = Object.freeze({ + notebookCell: 'vscode-notebook-cell', +}); diff --git a/extensions/markdown-language-features/server/src/workspace.ts b/extensions/markdown-language-features/server/src/workspace.ts index 964ff369d505f..c52d696b429a1 100644 --- a/extensions/markdown-language-features/server/src/workspace.ts +++ b/extensions/markdown-language-features/server/src/workspace.ts @@ -3,15 +3,17 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Connection, Emitter, FileChangeType, TextDocuments } from 'vscode-languageserver'; +import { Connection, Emitter, FileChangeType, NotebookDocuments, TextDocuments } from 'vscode-languageserver'; import { TextDocument } from 'vscode-languageserver-textdocument'; import * as md from 'vscode-markdown-languageservice'; +import { ContainingDocumentContext } from 'vscode-markdown-languageservice/out/workspace'; import { URI } from 'vscode-uri'; import * as protocol from './protocol'; import { coalesce } from './util/arrays'; import { isMarkdownDocument, looksLikeMarkdownPath } from './util/file'; import { Limiter } from './util/limiter'; import { ResourceMap } from './util/resourceMap'; +import { Schemes } from './util/schemes'; declare const TextDecoder: any; @@ -33,6 +35,7 @@ export class VsCodeClientWorkspace implements md.IWorkspace { constructor( private readonly connection: Connection, private readonly documents: TextDocuments, + private readonly notebooks: NotebookDocuments, ) { documents.onDidOpen(e => { this._documentCache.delete(URI.parse(e.document.uri)); @@ -57,14 +60,14 @@ export class VsCodeClientWorkspace implements md.IWorkspace { switch (change.type) { case FileChangeType.Changed: { this._documentCache.delete(resource); - const document = await this.getOrLoadMarkdownDocument(resource); + const document = await this.openMarkdownDocument(resource); if (document) { this._onDidChangeMarkdownDocument.fire(document); } break; } case FileChangeType.Created: { - const document = await this.getOrLoadMarkdownDocument(resource); + const document = await this.openMarkdownDocument(resource); if (document) { this._onDidCreateMarkdownDocument.fire(document); } @@ -80,6 +83,22 @@ export class VsCodeClientWorkspace implements md.IWorkspace { }); } + public listen() { + this.connection.workspace.onDidChangeWorkspaceFolders(async () => { + this.workspaceFolders = (await this.connection.workspace.getWorkspaceFolders() ?? []).map(x => URI.parse(x.uri)); + }); + } + + private _workspaceFolders: readonly URI[] = []; + + get workspaceFolders(): readonly URI[] { + return this._workspaceFolders; + } + + set workspaceFolders(value: readonly URI[]) { + this._workspaceFolders = value; + } + async getAllMarkdownDocuments(): Promise> { const maxConcurrent = 20; @@ -91,7 +110,7 @@ export class VsCodeClientWorkspace implements md.IWorkspace { const onDiskResults = await Promise.all(resources.map(strResource => { return limiter.queue(async () => { const resource = URI.parse(strResource); - const doc = await this.getOrLoadMarkdownDocument(resource); + const doc = await this.openMarkdownDocument(resource); if (doc) { foundFiles.set(resource); } @@ -110,7 +129,7 @@ export class VsCodeClientWorkspace implements md.IWorkspace { return !!this.documents.get(resource.toString()); } - async getOrLoadMarkdownDocument(resource: URI): Promise { + async openMarkdownDocument(resource: URI): Promise { const existing = this._documentCache.get(resource); if (existing) { return existing; @@ -141,12 +160,25 @@ export class VsCodeClientWorkspace implements md.IWorkspace { } } - async pathExists(_resource: URI): Promise { - return false; + stat(resource: URI): Promise { + return this.connection.sendRequest(protocol.statFileRequestType, { uri: resource.toString() }); + } + + async readDirectory(resource: URI): Promise<[string, md.FileStat][]> { + return this.connection.sendRequest(protocol.readDirectoryRequestType, { uri: resource.toString() }); } - async readDirectory(_resource: URI): Promise<[string, { isDir: boolean }][]> { - return []; + getContainingDocument(resource: URI): ContainingDocumentContext | undefined { + if (resource.scheme === Schemes.notebookCell) { + const nb = this.notebooks.findNotebookDocumentForCell(resource.toString()); + if (nb) { + return { + uri: URI.parse(nb.uri), + children: nb.cells.map(cell => ({ uri: URI.parse(cell.document) })), + }; + } + } + return undefined; } private isRelevantMarkdownDocument(doc: TextDocument) { diff --git a/extensions/markdown-language-features/server/yarn.lock b/extensions/markdown-language-features/server/yarn.lock index e46f1b1b8db10..2dea8ce7b5b5b 100644 --- a/extensions/markdown-language-features/server/yarn.lock +++ b/extensions/markdown-language-features/server/yarn.lock @@ -35,17 +35,19 @@ vscode-languageserver-types@^3.17.1: resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.1.tgz#c2d87fa7784f8cac389deb3ff1e2d9a7bef07e16" integrity sha512-K3HqVRPElLZVVPtMeKlsyL9aK0GxGQpvtAUTfX4k7+iJ4mc1M+JM+zQwkgGy2LzY0f0IAafe8MKqIkJrxfGGjQ== -vscode-languageserver@^8.0.2-next.4: +vscode-languageserver@^8.0.2-next.5`: version "8.0.2-next.5" resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-8.0.2-next.5.tgz#39a2dd4c504fb88042375e7ac706a714bdaab4e5" integrity sha512-2ZDb7O/4atS9mJKufPPz637z+51kCyZfgnobFW5eSrUdS3c0UB/nMS4Ng1EavYTX84GVaVMKCrmP0f2ceLmR0A== dependencies: vscode-languageserver-protocol "3.17.2-next.6" -vscode-markdown-languageservice@microsoft/vscode-markdown-languageservice: - version "0.0.0-alpha.2" - resolved "https://codeload.github.com/microsoft/vscode-markdown-languageservice/tar.gz/db497ada376aae9a335519dbfb406c6a1f873446" +vscode-markdown-languageservice@^0.0.0-alpha.5: + version "0.0.0-alpha.5" + resolved "https://registry.yarnpkg.com/vscode-markdown-languageservice/-/vscode-markdown-languageservice-0.0.0-alpha.5.tgz#fb3042f3ee79589606154c19b15565541337bceb" + integrity sha512-vy8UVa1jtm3CwkifRn3fEWM710JC4AYEECNd5KQthSCoFSfT5pOshJNFWs5yzBeVrohiy4deOdhSrfbDMg/Hyg== dependencies: + vscode-languageserver-textdocument "^1.0.5" vscode-languageserver-types "^3.17.1" vscode-uri "^3.0.3" diff --git a/extensions/markdown-language-features/src/client.ts b/extensions/markdown-language-features/src/client.ts index aabd09f463386..551274bc201e1 100644 --- a/extensions/markdown-language-features/src/client.ts +++ b/extensions/markdown-language-features/src/client.ts @@ -5,7 +5,7 @@ import Token = require('markdown-it/lib/token'); import * as vscode from 'vscode'; -import { BaseLanguageClient, LanguageClientOptions, RequestType } from 'vscode-languageclient'; +import { BaseLanguageClient, LanguageClientOptions, NotebookDocumentSyncRegistrationType, RequestType } from 'vscode-languageclient'; import * as nls from 'vscode-nls'; import { IMdParser } from './markdownEngine'; import { markdownFileExtensions } from './util/file'; @@ -14,9 +14,9 @@ import { IMdWorkspace } from './workspace'; const localize = nls.loadMessageBundle(); const parseRequestType: RequestType<{ uri: string }, Token[], any> = new RequestType('markdown/parse'); - const readFileRequestType: RequestType<{ uri: string }, number[], any> = new RequestType('markdown/readFile'); - +const statFileRequestType: RequestType<{ uri: string }, { isDirectory: boolean } | undefined, any> = new RequestType('markdown/statFile'); +const readDirectoryRequestType: RequestType<{ uri: string }, [string, { isDirectory: boolean }][], any> = new RequestType('markdown/readDirectory'); const findFilesRequestTypes: RequestType<{}, string[], any> = new RequestType('markdown/findFiles'); export type LanguageClientConstructor = (name: string, description: string, clientOptions: LanguageClientOptions) => BaseLanguageClient; @@ -33,13 +33,25 @@ export async function startClient(factory: LanguageClientConstructor, workspace: configurationSection: ['markdown'], fileEvents: vscode.workspace.createFileSystemWatcher(mdFileGlob), }, - initializationOptions: {} }; const client = factory('markdown', localize('markdownServer.name', 'Markdown Language Server'), clientOptions); client.registerProposedFeatures(); + const notebookFeature = client.getFeature(NotebookDocumentSyncRegistrationType.method); + if (notebookFeature !== undefined) { + notebookFeature.register({ + id: String(Date.now()), + registerOptions: { + notebookSelector: [{ + notebook: '*', + cells: [{ language: 'markdown' }] + }] + } + }); + } + client.onRequest(parseRequestType, async (e) => { const uri = vscode.Uri.parse(e.uri); const doc = await workspace.getOrLoadMarkdownDocument(uri); @@ -55,6 +67,22 @@ export async function startClient(factory: LanguageClientConstructor, workspace: return Array.from(await vscode.workspace.fs.readFile(uri)); }); + client.onRequest(statFileRequestType, async (e): Promise<{ isDirectory: boolean } | undefined> => { + const uri = vscode.Uri.parse(e.uri); + try { + const stat = await vscode.workspace.fs.stat(uri); + return { isDirectory: stat.type === vscode.FileType.Directory }; + } catch { + return undefined; + } + }); + + client.onRequest(readDirectoryRequestType, async (e): Promise<[string, { isDirectory: boolean }][]> => { + const uri = vscode.Uri.parse(e.uri); + const result = await vscode.workspace.fs.readDirectory(uri); + return result.map(([name, type]) => [name, { isDirectory: type === vscode.FileType.Directory }]); + }); + client.onRequest(findFilesRequestTypes, async (): Promise => { return (await vscode.workspace.findFiles(mdFileGlob, '**/node_modules/**')).map(x => x.toString()); }); diff --git a/extensions/markdown-language-features/src/extension.shared.ts b/extensions/markdown-language-features/src/extension.shared.ts index c5ebe5650c0dd..8d16f394e4a8f 100644 --- a/extensions/markdown-language-features/src/extension.shared.ts +++ b/extensions/markdown-language-features/src/extension.shared.ts @@ -9,10 +9,9 @@ import * as commands from './commands/index'; import { registerPasteSupport } from './languageFeatures/copyPaste'; import { registerDefinitionSupport } from './languageFeatures/definitions'; import { registerDiagnosticSupport } from './languageFeatures/diagnostics'; -import { MdLinkProvider, registerDocumentLinkSupport } from './languageFeatures/documentLinks'; +import { MdLinkProvider } from './languageFeatures/documentLinks'; import { registerDropIntoEditorSupport } from './languageFeatures/dropIntoEditor'; import { registerFindFileReferenceSupport } from './languageFeatures/fileReferences'; -import { registerPathCompletionSupport } from './languageFeatures/pathCompletions'; import { MdReferencesProvider, registerReferencesSupport } from './languageFeatures/references'; import { registerRenameSupport } from './languageFeatures/rename'; import { ILogger } from './logging'; @@ -73,11 +72,9 @@ function registerMarkdownLanguageFeatures( // Language features registerDefinitionSupport(selector, referencesProvider), registerDiagnosticSupport(selector, workspace, linkProvider, commandManager, referencesProvider, tocProvider, logger), - registerDocumentLinkSupport(selector, linkProvider), registerDropIntoEditorSupport(selector), registerFindFileReferenceSupport(commandManager, referencesProvider), registerPasteSupport(selector), - registerPathCompletionSupport(selector, workspace, parser, linkProvider), registerReferencesSupport(selector, referencesProvider), registerRenameSupport(selector, workspace, referencesProvider, parser.slugifier), ); diff --git a/extensions/markdown-language-features/src/languageFeatures/documentLinks.ts b/extensions/markdown-language-features/src/languageFeatures/documentLinks.ts index 6ef76cdb2270d..449be42595b0f 100644 --- a/extensions/markdown-language-features/src/languageFeatures/documentLinks.ts +++ b/extensions/markdown-language-features/src/languageFeatures/documentLinks.ts @@ -4,21 +4,16 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; -import * as nls from 'vscode-nls'; import * as uri from 'vscode-uri'; -import { OpenDocumentLinkCommand } from '../commands/openDocumentLink'; import { ILogger } from '../logging'; import { IMdParser } from '../markdownEngine'; import { getLine, ITextDocument } from '../types/textDocument'; -import { coalesce } from '../util/arrays'; import { noopToken } from '../util/cancellation'; import { Disposable } from '../util/dispose'; import { Schemes } from '../util/schemes'; import { MdDocumentInfoCache } from '../util/workspaceCache'; import { IMdWorkspace } from '../workspace'; -const localize = nls.loadMessageBundle(); - export interface ExternalHref { readonly kind: 'external'; readonly uri: vscode.Uri; @@ -543,62 +538,3 @@ export class LinkDefinitionSet implements Iterable<[string, MdLinkDefinition]> { return this._map.get(ref); } } - -export class MdVsCodeLinkProvider implements vscode.DocumentLinkProvider { - - constructor( - private readonly _linkProvider: MdLinkProvider, - ) { } - - public async provideDocumentLinks( - document: ITextDocument, - token: vscode.CancellationToken - ): Promise { - const { links, definitions } = await this._linkProvider.getLinks(document); - if (token.isCancellationRequested) { - return []; - } - - return coalesce(links.map(data => this.toValidDocumentLink(data, definitions))); - } - - private toValidDocumentLink(link: MdLink, definitionSet: LinkDefinitionSet): vscode.DocumentLink | undefined { - switch (link.href.kind) { - case 'external': { - let target = link.href.uri; - // Normalize VS Code links to target currently running version - if (link.href.uri.scheme === Schemes.vscode || link.href.uri.scheme === Schemes['vscode-insiders']) { - target = target.with({ scheme: vscode.env.uriScheme }); - } - return new vscode.DocumentLink(link.source.hrefRange, link.href.uri); - } - case 'internal': { - const uri = OpenDocumentLinkCommand.createCommandUri(link.source.resource, link.href.path, link.href.fragment); - const documentLink = new vscode.DocumentLink(link.source.hrefRange, uri); - documentLink.tooltip = localize('documentLink.tooltip', 'Follow link'); - return documentLink; - } - case 'reference': { - // We only render reference links in the editor if they are actually defined. - // This matches how reference links are rendered by markdown-it. - const def = definitionSet.lookup(link.href.ref); - if (def) { - const documentLink = new vscode.DocumentLink( - link.source.hrefRange, - vscode.Uri.parse(`command:_markdown.moveCursorToPosition?${encodeURIComponent(JSON.stringify([def.source.hrefRange.start.line, def.source.hrefRange.start.character]))}`)); - documentLink.tooltip = localize('documentLink.referenceTooltip', 'Go to link definition'); - return documentLink; - } else { - return undefined; - } - } - } - } -} - -export function registerDocumentLinkSupport( - selector: vscode.DocumentSelector, - linkProvider: MdLinkProvider, -): vscode.Disposable { - return vscode.languages.registerDocumentLinkProvider(selector, new MdVsCodeLinkProvider(linkProvider)); -} diff --git a/extensions/markdown-language-features/src/languageFeatures/pathCompletions.ts b/extensions/markdown-language-features/src/languageFeatures/pathCompletions.ts deleted file mode 100644 index 82e28faf3a4c9..0000000000000 --- a/extensions/markdown-language-features/src/languageFeatures/pathCompletions.ts +++ /dev/null @@ -1,369 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { dirname, resolve } from 'path'; -import * as vscode from 'vscode'; -import { IMdParser } from '../markdownEngine'; -import { TableOfContents } from '../tableOfContents'; -import { getLine, ITextDocument } from '../types/textDocument'; -import { resolveUriToMarkdownFile } from '../util/openDocumentLink'; -import { Schemes } from '../util/schemes'; -import { IMdWorkspace } from '../workspace'; -import { MdLinkProvider } from './documentLinks'; - -enum CompletionContextKind { - /** `[...](|)` */ - Link, - - /** `[...][|]` */ - ReferenceLink, - - /** `[]: |` */ - LinkDefinition, -} - -interface AnchorContext { - /** - * Link text before the `#`. - * - * For `[text](xy#z|abc)` this is `xy`. - */ - readonly beforeAnchor: string; - - /** - * Text of the anchor before the current position. - * - * For `[text](xy#z|abc)` this is `z`. - */ - readonly anchorPrefix: string; -} - -interface CompletionContext { - readonly kind: CompletionContextKind; - - /** - * Text of the link before the current position - * - * For `[text](xy#z|abc)` this is `xy#z`. - */ - readonly linkPrefix: string; - - /** - * Position of the start of the link. - * - * For `[text](xy#z|abc)` this is the position before `xy`. - */ - readonly linkTextStartPosition: vscode.Position; - - /** - * Text of the link after the current position. - * - * For `[text](xy#z|abc)` this is `abc`. - */ - readonly linkSuffix: string; - - /** - * Info if the link looks like it is for an anchor: `[](#header)` - */ - readonly anchorInfo?: AnchorContext; - - /** - * Indicates that the completion does not require encoding. - */ - readonly skipEncoding?: boolean; -} - -function tryDecodeUriComponent(str: string): string { - try { - return decodeURIComponent(str); - } catch { - return str; - } -} - -/** - * Adds path completions in markdown files by implementing {@link vscode.CompletionItemProvider}. - */ -export class MdVsCodePathCompletionProvider implements vscode.CompletionItemProvider { - - constructor( - private readonly workspace: IMdWorkspace, - private readonly parser: IMdParser, - private readonly linkProvider: MdLinkProvider, - ) { } - - public async provideCompletionItems(document: ITextDocument, position: vscode.Position, _token: vscode.CancellationToken, _context: vscode.CompletionContext): Promise { - if (!this.arePathSuggestionEnabled(document)) { - return []; - } - - const context = this.getPathCompletionContext(document, position); - if (!context) { - return []; - } - - switch (context.kind) { - case CompletionContextKind.ReferenceLink: { - const items: vscode.CompletionItem[] = []; - for await (const item of this.provideReferenceSuggestions(document, position, context)) { - items.push(item); - } - return items; - } - - case CompletionContextKind.LinkDefinition: - case CompletionContextKind.Link: { - const items: vscode.CompletionItem[] = []; - - const isAnchorInCurrentDoc = context.anchorInfo && context.anchorInfo.beforeAnchor.length === 0; - - // Add anchor #links in current doc - if (context.linkPrefix.length === 0 || isAnchorInCurrentDoc) { - const insertRange = new vscode.Range(context.linkTextStartPosition, position); - for await (const item of this.provideHeaderSuggestions(document, position, context, insertRange)) { - items.push(item); - } - } - - if (!isAnchorInCurrentDoc) { - if (context.anchorInfo) { // Anchor to a different document - const rawUri = this.resolveReference(document, context.anchorInfo.beforeAnchor); - if (rawUri) { - const otherDoc = await resolveUriToMarkdownFile(this.workspace, rawUri); - if (otherDoc) { - const anchorStartPosition = position.translate({ characterDelta: -(context.anchorInfo.anchorPrefix.length + 1) }); - const range = new vscode.Range(anchorStartPosition, position); - for await (const item of this.provideHeaderSuggestions(otherDoc, position, context, range)) { - items.push(item); - } - } - } - } else { // Normal path suggestions - for await (const item of this.providePathSuggestions(document, position, context)) { - items.push(item); - } - } - } - - return items; - } - } - } - - private arePathSuggestionEnabled(document: ITextDocument): boolean { - const config = vscode.workspace.getConfiguration('markdown', document.uri); - return config.get('suggest.paths.enabled', true); - } - - /// [...](...| - private readonly linkStartPattern = /\[([^\]]*?)\]\(\s*(<[^\>\)]*|[^\s\(\)]*)$/; - - /// [...][...| - private readonly referenceLinkStartPattern = /\[([^\]]*?)\]\[\s*([^\s\(\)]*)$/; - - /// [id]: | - private readonly definitionPattern = /^\s*\[[\w\-]+\]:\s*([^\s]*)$/m; - - private getPathCompletionContext(document: ITextDocument, position: vscode.Position): CompletionContext | undefined { - const line = getLine(document, position.line); - - const linePrefixText = line.slice(0, position.character); - const lineSuffixText = line.slice(position.character); - - const linkPrefixMatch = linePrefixText.match(this.linkStartPattern); - if (linkPrefixMatch) { - const isAngleBracketLink = linkPrefixMatch[2].startsWith('<'); - const prefix = linkPrefixMatch[2].slice(isAngleBracketLink ? 1 : 0); - if (this.refLooksLikeUrl(prefix)) { - return undefined; - } - - const suffix = lineSuffixText.match(/^[^\)\s][^\)\s\>]*/); - return { - kind: CompletionContextKind.Link, - linkPrefix: tryDecodeUriComponent(prefix), - linkTextStartPosition: position.translate({ characterDelta: -prefix.length }), - linkSuffix: suffix ? suffix[0] : '', - anchorInfo: this.getAnchorContext(prefix), - skipEncoding: isAngleBracketLink, - }; - } - - const definitionLinkPrefixMatch = linePrefixText.match(this.definitionPattern); - if (definitionLinkPrefixMatch) { - const isAngleBracketLink = definitionLinkPrefixMatch[1].startsWith('<'); - const prefix = definitionLinkPrefixMatch[1].slice(isAngleBracketLink ? 1 : 0); - if (this.refLooksLikeUrl(prefix)) { - return undefined; - } - - const suffix = lineSuffixText.match(/^[^\s]*/); - return { - kind: CompletionContextKind.LinkDefinition, - linkPrefix: tryDecodeUriComponent(prefix), - linkTextStartPosition: position.translate({ characterDelta: -prefix.length }), - linkSuffix: suffix ? suffix[0] : '', - anchorInfo: this.getAnchorContext(prefix), - skipEncoding: isAngleBracketLink, - }; - } - - const referenceLinkPrefixMatch = linePrefixText.match(this.referenceLinkStartPattern); - if (referenceLinkPrefixMatch) { - const prefix = referenceLinkPrefixMatch[2]; - const suffix = lineSuffixText.match(/^[^\]\s]*/); - return { - kind: CompletionContextKind.ReferenceLink, - linkPrefix: prefix, - linkTextStartPosition: position.translate({ characterDelta: -prefix.length }), - linkSuffix: suffix ? suffix[0] : '', - }; - } - - return undefined; - } - - /** - * Check if {@param ref} looks like a 'http:' style url. - */ - private refLooksLikeUrl(prefix: string): boolean { - return /^\s*[\w\d\-]+:/.test(prefix); - } - - private getAnchorContext(prefix: string): AnchorContext | undefined { - const anchorMatch = prefix.match(/^(.*)#([\w\d\-]*)$/); - if (!anchorMatch) { - return undefined; - } - return { - beforeAnchor: anchorMatch[1], - anchorPrefix: anchorMatch[2], - }; - } - - private async *provideReferenceSuggestions(document: ITextDocument, position: vscode.Position, context: CompletionContext): AsyncIterable { - const insertionRange = new vscode.Range(context.linkTextStartPosition, position); - const replacementRange = new vscode.Range(insertionRange.start, position.translate({ characterDelta: context.linkSuffix.length })); - - const { definitions } = await this.linkProvider.getLinks(document); - for (const [_, def] of definitions) { - yield { - kind: vscode.CompletionItemKind.Reference, - label: def.ref.text, - range: { - inserting: insertionRange, - replacing: replacementRange, - }, - }; - } - } - - private async *provideHeaderSuggestions(document: ITextDocument, position: vscode.Position, context: CompletionContext, insertionRange: vscode.Range): AsyncIterable { - const toc = await TableOfContents.createForDocumentOrNotebook(this.parser, document); - for (const entry of toc.entries) { - const replacementRange = new vscode.Range(insertionRange.start, position.translate({ characterDelta: context.linkSuffix.length })); - yield { - kind: vscode.CompletionItemKind.Reference, - label: '#' + decodeURIComponent(entry.slug.value), - range: { - inserting: insertionRange, - replacing: replacementRange, - }, - }; - } - } - - private async *providePathSuggestions(document: ITextDocument, position: vscode.Position, context: CompletionContext): AsyncIterable { - const valueBeforeLastSlash = context.linkPrefix.substring(0, context.linkPrefix.lastIndexOf('/') + 1); // keep the last slash - - const parentDir = this.resolveReference(document, valueBeforeLastSlash || '.'); - if (!parentDir) { - return; - } - - const pathSegmentStart = position.translate({ characterDelta: valueBeforeLastSlash.length - context.linkPrefix.length }); - const insertRange = new vscode.Range(pathSegmentStart, position); - - const pathSegmentEnd = position.translate({ characterDelta: context.linkSuffix.length }); - const replacementRange = new vscode.Range(pathSegmentStart, pathSegmentEnd); - - let dirInfo: [string, vscode.FileType][]; - try { - dirInfo = await this.workspace.readDirectory(parentDir); - } catch { - return; - } - - for (const [name, type] of dirInfo) { - // Exclude paths that start with `.` - if (name.startsWith('.')) { - continue; - } - - const isDir = type === vscode.FileType.Directory; - yield { - label: isDir ? name + '/' : name, - insertText: (context.skipEncoding ? name : encodeURIComponent(name)) + (isDir ? '/' : ''), - kind: isDir ? vscode.CompletionItemKind.Folder : vscode.CompletionItemKind.File, - range: { - inserting: insertRange, - replacing: replacementRange, - }, - command: isDir ? { command: 'editor.action.triggerSuggest', title: '' } : undefined, - }; - } - } - - private resolveReference(document: ITextDocument, ref: string): vscode.Uri | undefined { - const docUri = this.getFileUriOfTextDocument(document); - - if (ref.startsWith('/')) { - const workspaceFolder = vscode.workspace.getWorkspaceFolder(docUri); - if (workspaceFolder) { - return vscode.Uri.joinPath(workspaceFolder.uri, ref); - } else { - return this.resolvePath(docUri, ref.slice(1)); - } - } - - return this.resolvePath(docUri, ref); - } - - private resolvePath(root: vscode.Uri, ref: string): vscode.Uri | undefined { - try { - if (root.scheme === Schemes.file) { - return vscode.Uri.file(resolve(dirname(root.fsPath), ref)); - } else { - return root.with({ - path: resolve(dirname(root.path), ref), - }); - } - } catch { - return undefined; - } - } - - private getFileUriOfTextDocument(document: ITextDocument) { - if (document.uri.scheme === 'vscode-notebook-cell') { - const notebook = vscode.workspace.notebookDocuments - .find(notebook => notebook.getCells().some(cell => cell.document === document)); - - if (notebook) { - return notebook.uri; - } - } - - return document.uri; - } -} - -export function registerPathCompletionSupport( - selector: vscode.DocumentSelector, - workspace: IMdWorkspace, - parser: IMdParser, - linkProvider: MdLinkProvider, -): vscode.Disposable { - return vscode.languages.registerCompletionItemProvider(selector, new MdVsCodePathCompletionProvider(workspace, parser, linkProvider), '.', '/', '#'); -} diff --git a/extensions/markdown-language-features/src/test/documentLink.test.ts b/extensions/markdown-language-features/src/test/documentLink.test.ts index 7c280a82bdf87..6902d68976230 100644 --- a/extensions/markdown-language-features/src/test/documentLink.test.ts +++ b/extensions/markdown-language-features/src/test/documentLink.test.ts @@ -24,7 +24,7 @@ function workspaceFile(...segments: string[]) { async function getLinksForFile(file: vscode.Uri): Promise { debugLog('getting links', file.toString(), Date.now()); - const r = (await vscode.commands.executeCommand('vscode.executeLinkProvider', file))!; + const r = (await vscode.commands.executeCommand('vscode.executeLinkProvider', file, /*linkResolveCount*/ 100))!; debugLog('got links', file.toString(), Date.now()); return r; } @@ -134,7 +134,7 @@ async function getLinksForFile(file: vscode.Uri): Promise } }); - test('Should navigate to fragment within current untitled file', async () => { + test.skip('Should navigate to fragment within current untitled file', async () => { // TODO: skip for now for ls migration const testFile = workspaceFile('x.md').with({ scheme: 'untitled' }); await withFileContents(testFile, joinLines( '[](#second)', @@ -171,7 +171,7 @@ async function withFileContents(file: vscode.Uri, contents: string): Promise { - - function getLinksForFile(fileContents: string): Promise { - const doc = new InMemoryDocument(workspacePath('x.md'), fileContents); - const engine = createNewMarkdownEngine(); - const linkProvider = new MdLinkComputer(engine); - return linkProvider.getAllLinks(doc, noopToken); - } - - function assertLinksEqual(actualLinks: readonly MdLink[], expected: ReadonlyArray) { - assert.strictEqual(actualLinks.length, expected.length); - - for (let i = 0; i < actualLinks.length; ++i) { - const exp = expected[i]; - if ('range' in exp) { - assertRangeEqual(actualLinks[i].source.hrefRange, exp.range, `Range ${i} to be equal`); - assert.strictEqual(actualLinks[i].source.hrefText, exp.sourceText, `Source text ${i} to be equal`); - } else { - assertRangeEqual(actualLinks[i].source.hrefRange, exp, `Range ${i} to be equal`); - } - } - } - - test('Should not return anything for empty document', async () => { - const links = await getLinksForFile(''); - assertLinksEqual(links, []); - }); - - test('Should not return anything for simple document without links', async () => { - const links = await getLinksForFile(joinLines( - '# a', - 'fdasfdfsafsa', - )); - assertLinksEqual(links, []); - }); - - test('Should detect basic http links', async () => { - const links = await getLinksForFile('a [b](https://example.com) c'); - assertLinksEqual(links, [ - new vscode.Range(0, 6, 0, 25) - ]); - }); - - test('Should detect basic workspace links', async () => { - { - const links = await getLinksForFile('a [b](./file) c'); - assertLinksEqual(links, [ - new vscode.Range(0, 6, 0, 12) - ]); - } - { - const links = await getLinksForFile('a [b](file.png) c'); - assertLinksEqual(links, [ - new vscode.Range(0, 6, 0, 14) - ]); - } - }); - - test('Should detect links with title', async () => { - const links = await getLinksForFile('a [b](https://example.com "abc") c'); - assertLinksEqual(links, [ - new vscode.Range(0, 6, 0, 25) - ]); - }); - - test('Should handle links with escaped characters in name (#35245)', async () => { - const links = await getLinksForFile('a [b\\]](./file)'); - assertLinksEqual(links, [ - new vscode.Range(0, 8, 0, 14) - ]); - }); - - test('Should handle links with balanced parens', async () => { - { - const links = await getLinksForFile('a [b](https://example.com/a()c) c'); - assertLinksEqual(links, [ - new vscode.Range(0, 6, 0, 30) - ]); - } - { - const links = await getLinksForFile('a [b](https://example.com/a(b)c) c'); - assertLinksEqual(links, [ - new vscode.Range(0, 6, 0, 31) - ]); - } - { - // #49011 - const links = await getLinksForFile('[A link](http://ThisUrlhasParens/A_link(in_parens))'); - assertLinksEqual(links, [ - new vscode.Range(0, 9, 0, 50) - ]); - } - }); - - test('Should ignore bracketed text inside link title (#150921)', async () => { - { - const links = await getLinksForFile('[some [inner] in title](link)'); - assertLinksEqual(links, [ - new vscode.Range(0, 24, 0, 28), - ]); - } - { - const links = await getLinksForFile('[some [inner] in title]()'); - assertLinksEqual(links, [ - new vscode.Range(0, 25, 0, 29), - ]); - } - { - const links = await getLinksForFile('[some [inner with space] in title](link)'); - assertLinksEqual(links, [ - new vscode.Range(0, 35, 0, 39), - ]); - } - { - const links = await getLinksForFile(joinLines( - `# h`, - `[[a]](http://example.com)`, - )); - assertLinksEqual(links, [ - new vscode.Range(1, 6, 1, 24), - ]); - } - }); - - test('Should handle two links without space', async () => { - const links = await getLinksForFile('a ([test](test)[test2](test2)) c'); - assertLinksEqual(links, [ - new vscode.Range(0, 10, 0, 14), - new vscode.Range(0, 23, 0, 28) - ]); - }); - - test('should handle hyperlinked images (#49238)', async () => { - { - const links = await getLinksForFile('[![alt text](image.jpg)](https://example.com)'); - assertLinksEqual(links, [ - new vscode.Range(0, 25, 0, 44), - new vscode.Range(0, 13, 0, 22), - ]); - } - { - const links = await getLinksForFile('[![a]( whitespace.jpg )]( https://whitespace.com )'); - assertLinksEqual(links, [ - new vscode.Range(0, 26, 0, 48), - new vscode.Range(0, 7, 0, 21), - ]); - } - { - const links = await getLinksForFile('[![a](img1.jpg)](file1.txt) text [![a](img2.jpg)](file2.txt)'); - assertLinksEqual(links, [ - new vscode.Range(0, 17, 0, 26), - new vscode.Range(0, 6, 0, 14), - new vscode.Range(0, 50, 0, 59), - new vscode.Range(0, 39, 0, 47), - ]); - } - }); - - test('Should not consider link references starting with ^ character valid (#107471)', async () => { - const links = await getLinksForFile('[^reference]: https://example.com'); - assertLinksEqual(links, []); - }); - - test('Should find definitions links with spaces in angle brackets (#136073)', async () => { - const links = await getLinksForFile(joinLines( - '[a]: ', - '[b]: ', - )); - - assertLinksEqual(links, [ - { range: new vscode.Range(0, 6, 0, 9), sourceText: 'b c' }, - { range: new vscode.Range(1, 6, 1, 8), sourceText: 'cd' }, - ]); - }); - - test('Should only find one link for reference sources [a]: source (#141285)', async () => { - const links = await getLinksForFile(joinLines( - '[Works]: https://example.com', - )); - - assertLinksEqual(links, [ - { range: new vscode.Range(0, 9, 0, 28), sourceText: 'https://example.com' }, - ]); - }); - - test('Should find reference link shorthand (#141285)', async () => { - const links = await getLinksForFile(joinLines( - '[ref]', - '[ref]: https://example.com', - )); - assertLinksEqual(links, [ - { range: new vscode.Range(0, 1, 0, 4), sourceText: 'ref' }, - { range: new vscode.Range(1, 7, 1, 26), sourceText: 'https://example.com' }, - ]); - }); - - test('Should find reference link shorthand using empty closing brackets (#141285)', async () => { - const links = await getLinksForFile(joinLines( - '[ref][]', - )); - assertLinksEqual(links, [ - new vscode.Range(0, 1, 0, 4), - ]); - }); - - test.skip('Should find reference link shorthand for link with space in label (#141285)', async () => { - const links = await getLinksForFile(joinLines( - '[ref with space]', - )); - assertLinksEqual(links, [ - new vscode.Range(0, 7, 0, 26), - ]); - }); - - test('Should not include reference links with escaped leading brackets', async () => { - const links = await getLinksForFile(joinLines( - `\\[bad link][good]`, - `\\[good]`, - `[good]: http://example.com`, - )); - assertLinksEqual(links, [ - new vscode.Range(2, 8, 2, 26) // Should only find the definition - ]); - }); - - test('Should not consider links in code fenced with backticks', async () => { - const links = await getLinksForFile(joinLines( - '```', - '[b](https://example.com)', - '```')); - assertLinksEqual(links, []); - }); - - test('Should not consider links in code fenced with tilde', async () => { - const links = await getLinksForFile(joinLines( - '~~~', - '[b](https://example.com)', - '~~~')); - assertLinksEqual(links, []); - }); - - test('Should not consider links in indented code', async () => { - const links = await getLinksForFile(' [b](https://example.com)'); - assertLinksEqual(links, []); - }); - - test('Should not consider links in inline code span', async () => { - const links = await getLinksForFile('`[b](https://example.com)`'); - assertLinksEqual(links, []); - }); - - test('Should not consider links with code span inside', async () => { - const links = await getLinksForFile('[li`nk](https://example.com`)'); - assertLinksEqual(links, []); - }); - - test('Should not consider links in multiline inline code span', async () => { - const links = await getLinksForFile(joinLines( - '`` ', - '[b](https://example.com)', - '``')); - assertLinksEqual(links, []); - }); - - test('Should not consider link references in code fenced with backticks (#146714)', async () => { - const links = await getLinksForFile(joinLines( - '```', - '[a] [bb]', - '```')); - assertLinksEqual(links, []); - }); - - test('Should not consider reference sources in code fenced with backticks (#146714)', async () => { - const links = await getLinksForFile(joinLines( - '```', - '[a]: http://example.com;', - '[b]: ;', - '[c]: (http://example.com);', - '```')); - assertLinksEqual(links, []); - }); - - test('Should not consider links in multiline inline code span between between text', async () => { - const links = await getLinksForFile(joinLines( - '[b](https://1.com) `[b](https://2.com)', - '[b](https://3.com) ` [b](https://4.com)')); - - assertLinksEqual(links, [ - new vscode.Range(0, 4, 0, 17), - new vscode.Range(1, 25, 1, 38), - ]); - }); - - test('Should not consider links in multiline inline code span with new line after the first backtick', async () => { - const links = await getLinksForFile(joinLines( - '`', - '[b](https://example.com)`')); - assertLinksEqual(links, []); - }); - - test('Should not miss links in invalid multiline inline code span', async () => { - const links = await getLinksForFile(joinLines( - '`` ', - '', - '[b](https://example.com)', - '', - '``')); - assertLinksEqual(links, [ - new vscode.Range(2, 4, 2, 23) - ]); - }); - - test('Should find autolinks', async () => { - const links = await getLinksForFile('pre post'); - assertLinksEqual(links, [ - new vscode.Range(0, 5, 0, 23) - ]); - }); - - test('Should not detect links inside html comment blocks', async () => { - const links = await getLinksForFile(joinLines( - ``, - ``, - ``, - ``, - ``, - ``, - ``, - ``, - ``, - )); - assertLinksEqual(links, []); - }); - - test.skip('Should not detect links inside inline html comments', async () => { - // See #149678 - const links = await getLinksForFile(joinLines( - `text text`, - `text text`, - `text text`, - ``, - `text text`, - ``, - `text text`, - ``, - `text text`, - )); - assertLinksEqual(links, []); - }); - - test('Should not mark checkboxes as links', async () => { - const links = await getLinksForFile(joinLines( - '- [x]', - '- [X]', - '- [ ]', - '* [x]', - '* [X]', - '* [ ]', - ``, - `[x]: http://example.com` - )); - assertLinksEqual(links, [ - new vscode.Range(7, 5, 7, 23) - ]); - }); - - test('Should still find links on line with checkbox', async () => { - const links = await getLinksForFile(joinLines( - '- [x] [x]', - '- [X] [x]', - '- [] [x]', - ``, - `[x]: http://example.com` - )); - - assertLinksEqual(links, [ - new vscode.Range(0, 7, 0, 8), - new vscode.Range(1, 7, 1, 8), - new vscode.Range(2, 6, 2, 7), - new vscode.Range(4, 5, 4, 23), - ]); - }); - - test('Should find link only within angle brackets.', async () => { - const links = await getLinksForFile(joinLines( - `[link]()` - )); - assertLinksEqual(links, [new vscode.Range(0, 8, 0, 12)]); - }); - - test('Should find link within angle brackets even with link title.', async () => { - const links = await getLinksForFile(joinLines( - `[link]( "test title")` - )); - assertLinksEqual(links, [new vscode.Range(0, 8, 0, 12)]); - }); - - test('Should find link within angle brackets even with surrounding spaces.', async () => { - const links = await getLinksForFile(joinLines( - `[link]( )` - )); - assertLinksEqual(links, [new vscode.Range(0, 9, 0, 13)]); - }); - - test('Should find link within angle brackets for image hyperlinks.', async () => { - const links = await getLinksForFile(joinLines( - `![link]()` - )); - assertLinksEqual(links, [new vscode.Range(0, 9, 0, 13)]); - }); - - test('Should find link with spaces in angle brackets for image hyperlinks with titles.', async () => { - const links = await getLinksForFile(joinLines( - `![link](< path > "test")` - )); - assertLinksEqual(links, [new vscode.Range(0, 9, 0, 15)]); - }); - - - test('Should not find link due to incorrect angle bracket notation or usage.', async () => { - const links = await getLinksForFile(joinLines( - `[link]( path>)`, - `[link](> path)`, - )); - assertLinksEqual(links, []); - }); - - test('Should find link within angle brackets even with space inside link.', async () => { - - const links = await getLinksForFile(joinLines( - `[link]()` - )); - - assertLinksEqual(links, [new vscode.Range(0, 8, 0, 13)]); - }); - - test('Should find links with titles', async () => { - const links = await getLinksForFile(joinLines( - `[link]( "text")`, - `[link]( 'text')`, - `[link]( (text))`, - `[link](no-such.md "text")`, - `[link](no-such.md 'text')`, - `[link](no-such.md (text))`, - )); - assertLinksEqual(links, [ - new vscode.Range(0, 8, 0, 18), - new vscode.Range(1, 8, 1, 18), - new vscode.Range(2, 8, 2, 18), - new vscode.Range(3, 7, 3, 17), - new vscode.Range(4, 7, 4, 17), - new vscode.Range(5, 7, 5, 17), - ]); - }); - - test('Should not include link with empty angle bracket', async () => { - const links = await getLinksForFile(joinLines( - `[](<>)`, - `[link](<>)`, - `[link](<> "text")`, - `[link](<> 'text')`, - `[link](<> (text))`, - )); - assertLinksEqual(links, []); - }); -}); - - -suite('Markdown: VS Code DocumentLinkProvider', () => { - - function getLinksForFile(fileContents: string) { - const doc = new InMemoryDocument(workspacePath('x.md'), fileContents); - const workspace = new InMemoryMdWorkspace([doc]); - - const engine = createNewMarkdownEngine(); - const linkProvider = new MdLinkProvider(engine, workspace, nulLogger); - const provider = new MdVsCodeLinkProvider(linkProvider); - return provider.provideDocumentLinks(doc, noopToken); - } - - function assertLinksEqual(actualLinks: readonly vscode.DocumentLink[], expectedRanges: readonly vscode.Range[]) { - assert.strictEqual(actualLinks.length, expectedRanges.length); - - for (let i = 0; i < actualLinks.length; ++i) { - assertRangeEqual(actualLinks[i].range, expectedRanges[i], `Range ${i} to be equal`); - } - } - - test('Should include defined reference links (#141285)', async () => { - const links = await getLinksForFile(joinLines( - '[ref]', - '[ref][]', - '[ref][ref]', - '', - '[ref]: http://example.com' - )); - assertLinksEqual(links, [ - new vscode.Range(0, 1, 0, 4), - new vscode.Range(1, 1, 1, 4), - new vscode.Range(2, 6, 2, 9), - new vscode.Range(4, 7, 4, 25), - ]); - }); - - test('Should not include reference link shorthand when definition does not exist (#141285)', async () => { - const links = await getLinksForFile('[ref]'); - assertLinksEqual(links, []); - }); -}); diff --git a/extensions/markdown-language-features/src/test/pathCompletion.test.ts b/extensions/markdown-language-features/src/test/pathCompletion.test.ts deleted file mode 100644 index f4ee75f2a7466..0000000000000 --- a/extensions/markdown-language-features/src/test/pathCompletion.test.ts +++ /dev/null @@ -1,313 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as assert from 'assert'; -import 'mocha'; -import * as vscode from 'vscode'; -import { MdLinkProvider } from '../languageFeatures/documentLinks'; -import { MdVsCodePathCompletionProvider } from '../languageFeatures/pathCompletions'; -import { noopToken } from '../util/cancellation'; -import { InMemoryDocument } from '../util/inMemoryDocument'; -import { IMdWorkspace } from '../workspace'; -import { createNewMarkdownEngine } from './engine'; -import { InMemoryMdWorkspace } from './inMemoryWorkspace'; -import { nulLogger } from './nulLogging'; -import { CURSOR, getCursorPositions, joinLines, workspacePath } from './util'; - - -async function getCompletionsAtCursor(resource: vscode.Uri, fileContents: string, workspace?: IMdWorkspace) { - const doc = new InMemoryDocument(resource, fileContents); - - const engine = createNewMarkdownEngine(); - const ws = workspace ?? new InMemoryMdWorkspace([doc]); - const linkProvider = new MdLinkProvider(engine, ws, nulLogger); - const provider = new MdVsCodePathCompletionProvider(ws, engine, linkProvider); - const cursorPositions = getCursorPositions(fileContents, doc); - const completions = await provider.provideCompletionItems(doc, cursorPositions[0], noopToken, { - triggerCharacter: undefined, - triggerKind: vscode.CompletionTriggerKind.Invoke, - }); - - return completions.sort((a, b) => (a.label as string).localeCompare(b.label as string)); -} - -function assertCompletionsEqual(actual: readonly vscode.CompletionItem[], expected: readonly { label: string; insertText?: string }[]) { - assert.strictEqual(actual.length, expected.length, 'Completion counts should be equal'); - - for (let i = 0; i < actual.length; ++i) { - assert.strictEqual(actual[i].label, expected[i].label, `Completion labels ${i} should be equal`); - if (typeof expected[i].insertText !== 'undefined') { - assert.strictEqual(actual[i].insertText, expected[i].insertText, `Completion insert texts ${i} should be equal`); - } - } -} - -suite('Markdown: Path completions', () => { - - test('Should not return anything when triggered in empty doc', async () => { - const completions = await getCompletionsAtCursor(workspacePath('new.md'), `${CURSOR}`); - assertCompletionsEqual(completions, []); - }); - - test('Should return anchor completions', async () => { - const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines( - `[](#${CURSOR}`, - ``, - `# A b C`, - `# x y Z`, - )); - - assertCompletionsEqual(completions, [ - { label: '#a-b-c' }, - { label: '#x-y-z' }, - ]); - }); - - test('Should not return suggestions for http links', async () => { - const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines( - `[](http:${CURSOR}`, - ``, - `# http`, - `# http:`, - `# https:`, - )); - - assertCompletionsEqual(completions, []); - }); - - test('Should return relative path suggestions', async () => { - const workspace = new InMemoryMdWorkspace([ - new InMemoryDocument(workspacePath('a.md'), ''), - new InMemoryDocument(workspacePath('b.md'), ''), - new InMemoryDocument(workspacePath('sub/foo.md'), ''), - ]); - const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines( - `[](${CURSOR}`, - ``, - `# A b C`, - ), workspace); - - assertCompletionsEqual(completions, [ - { label: '#a-b-c' }, - { label: 'a.md' }, - { label: 'b.md' }, - { label: 'sub/' }, - ]); - }); - - test('Should return relative path suggestions using ./', async () => { - const workspace = new InMemoryMdWorkspace([ - new InMemoryDocument(workspacePath('a.md'), ''), - new InMemoryDocument(workspacePath('b.md'), ''), - new InMemoryDocument(workspacePath('sub/foo.md'), ''), - ]); - - const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines( - `[](./${CURSOR}`, - ``, - `# A b C`, - ), workspace); - - assertCompletionsEqual(completions, [ - { label: 'a.md' }, - { label: 'b.md' }, - { label: 'sub/' }, - ]); - }); - - test('Should return absolute path suggestions using /', async () => { - const workspace = new InMemoryMdWorkspace([ - new InMemoryDocument(workspacePath('a.md'), ''), - new InMemoryDocument(workspacePath('b.md'), ''), - new InMemoryDocument(workspacePath('sub/c.md'), ''), - ]); - - const completions = await getCompletionsAtCursor(workspacePath('sub', 'new.md'), joinLines( - `[](/${CURSOR}`, - ``, - `# A b C`, - ), workspace); - - assertCompletionsEqual(completions, [ - { label: 'a.md' }, - { label: 'b.md' }, - { label: 'sub/' }, - ]); - }); - - test('Should return anchor suggestions in other file', async () => { - const workspace = new InMemoryMdWorkspace([ - new InMemoryDocument(workspacePath('b.md'), joinLines( - `# b`, - ``, - `[./a](./a)`, - ``, - `# header1`, - )), - ]); - const completions = await getCompletionsAtCursor(workspacePath('sub', 'new.md'), joinLines( - `[](/b.md#${CURSOR}`, - ), workspace); - - assertCompletionsEqual(completions, [ - { label: '#b' }, - { label: '#header1' }, - ]); - }); - - test('Should reference links for current file', async () => { - const completions = await getCompletionsAtCursor(workspacePath('sub', 'new.md'), joinLines( - `[][${CURSOR}`, - ``, - `[ref-1]: bla`, - `[ref-2]: bla`, - )); - - assertCompletionsEqual(completions, [ - { label: 'ref-1' }, - { label: 'ref-2' }, - ]); - }); - - test('Should complete headers in link definitions', async () => { - const completions = await getCompletionsAtCursor(workspacePath('sub', 'new.md'), joinLines( - `# a B c`, - `# x y Z`, - `[ref-1]: ${CURSOR}`, - )); - - assertCompletionsEqual(completions, [ - { label: '#a-b-c' }, - { label: '#x-y-z' }, - { label: 'new.md' }, - ]); - }); - - test('Should complete relative paths in link definitions', async () => { - const workspace = new InMemoryMdWorkspace([ - new InMemoryDocument(workspacePath('a.md'), ''), - new InMemoryDocument(workspacePath('b.md'), ''), - new InMemoryDocument(workspacePath('sub/c.md'), ''), - ]); - - const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines( - `# a B c`, - `[ref-1]: ${CURSOR}`, - ), workspace); - - assertCompletionsEqual(completions, [ - { label: '#a-b-c' }, - { label: 'a.md' }, - { label: 'b.md' }, - { label: 'sub/' }, - ]); - }); - - test('Should escape spaces in path names', async () => { - const workspace = new InMemoryMdWorkspace([ - new InMemoryDocument(workspacePath('a.md'), ''), - new InMemoryDocument(workspacePath('b.md'), ''), - new InMemoryDocument(workspacePath('sub/file with space.md'), ''), - ]); - - const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines( - `[](./sub/${CURSOR})` - ), workspace); - - assertCompletionsEqual(completions, [ - { label: 'file with space.md', insertText: 'file%20with%20space.md' }, - ]); - }); - - test('Should support completions on angle bracket path with spaces', async () => { - const workspace = new InMemoryMdWorkspace([ - new InMemoryDocument(workspacePath('sub with space/a.md'), ''), - new InMemoryDocument(workspacePath('b.md'), ''), - ]); - - const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines( - `[]( { - const workspace = new InMemoryMdWorkspace([ - new InMemoryDocument(workspacePath('sub/file with space.md'), ''), - ]); - - { - const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines( - `[](<./sub/${CURSOR}` - ), workspace); - - assertCompletionsEqual(completions, [ - { label: 'file with space.md', insertText: 'file with space.md' }, - ]); - } - { - const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines( - `[](<./sub/${CURSOR}>` - ), workspace); - - assertCompletionsEqual(completions, [ - { label: 'file with space.md', insertText: 'file with space.md' }, - ]); - } - }); - - test('Should complete paths for path with encoded spaces', async () => { - const workspace = new InMemoryMdWorkspace([ - new InMemoryDocument(workspacePath('a.md'), ''), - new InMemoryDocument(workspacePath('b.md'), ''), - new InMemoryDocument(workspacePath('sub with space/file.md'), ''), - ]); - - const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines( - `[](./sub%20with%20space/${CURSOR})` - ), workspace); - - assertCompletionsEqual(completions, [ - { label: 'file.md', insertText: 'file.md' }, - ]); - }); - - test('Should complete definition path for path with encoded spaces', async () => { - const workspace = new InMemoryMdWorkspace([ - new InMemoryDocument(workspacePath('a.md'), ''), - new InMemoryDocument(workspacePath('b.md'), ''), - new InMemoryDocument(workspacePath('sub with space/file.md'), ''), - ]); - - const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines( - `[def]: ./sub%20with%20space/${CURSOR}` - ), workspace); - - assertCompletionsEqual(completions, [ - { label: 'file.md', insertText: 'file.md' }, - ]); - }); - - test('Should support definition path with angle brackets', async () => { - const workspace = new InMemoryMdWorkspace([ - new InMemoryDocument(workspacePath('a.md'), ''), - new InMemoryDocument(workspacePath('b.md'), ''), - new InMemoryDocument(workspacePath('sub with space/file.md'), ''), - ]); - - const completions = await getCompletionsAtCursor(workspacePath('new.md'), joinLines( - `[def]: <./${CURSOR}>` - ), workspace); - - assertCompletionsEqual(completions, [ - { label: 'a.md', insertText: 'a.md' }, - { label: 'b.md', insertText: 'b.md' }, - { label: 'sub with space/', insertText: 'sub with space/' }, - ]); - }); -}); diff --git a/extensions/markdown-language-features/src/test/util.ts b/extensions/markdown-language-features/src/test/util.ts index b9dc2241090be..220e79e2f6033 100644 --- a/extensions/markdown-language-features/src/test/util.ts +++ b/extensions/markdown-language-features/src/test/util.ts @@ -6,28 +6,11 @@ import * as assert from 'assert'; import * as os from 'os'; import * as vscode from 'vscode'; import { DisposableStore } from '../util/dispose'; -import { InMemoryDocument } from '../util/inMemoryDocument'; export const joinLines = (...args: string[]) => args.join(os.platform() === 'win32' ? '\r\n' : '\n'); -export const CURSOR = '$$CURSOR$$'; - -export function getCursorPositions(contents: string, doc: InMemoryDocument): vscode.Position[] { - const positions: vscode.Position[] = []; - let index = 0; - let wordLength = 0; - while (index !== -1) { - index = contents.indexOf(CURSOR, index + wordLength); - if (index !== -1) { - positions.push(doc.positionAt(index)); - } - wordLength = CURSOR.length; - } - return positions; -} - export function workspacePath(...segments: string[]): vscode.Uri { return vscode.Uri.joinPath(vscode.workspace.workspaceFolders![0].uri, ...segments); } From 5385be5ddb4550ef9734526f51c94322f22a0375 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 13 Jul 2022 12:54:52 -0700 Subject: [PATCH 034/121] Finalize drop into editor api (#155102) Fixes #142990 Fixes #149779 --- .../package.nls.json | 2 +- .../browser/dropIntoEditorContribution.ts | 4 +- .../workbench/api/common/extHost.api.impl.ts | 1 - .../browser/parts/editor/editorDropTarget.ts | 2 +- .../browser/workbench.contribution.ts | 11 ++-- .../common/extensionsApiProposals.ts | 1 - src/vscode-dts/vscode.d.ts | 50 +++++++++++++++ .../vscode.proposed.textEditorDrop.d.ts | 61 ------------------- 8 files changed, 59 insertions(+), 73 deletions(-) delete mode 100644 src/vscode-dts/vscode.proposed.textEditorDrop.d.ts diff --git a/extensions/markdown-language-features/package.nls.json b/extensions/markdown-language-features/package.nls.json index 71c9fedc1a363..7b81507239700 100644 --- a/extensions/markdown-language-features/package.nls.json +++ b/extensions/markdown-language-features/package.nls.json @@ -28,7 +28,7 @@ "configuration.markdown.links.openLocation.currentGroup": "Open links in the active editor group.", "configuration.markdown.links.openLocation.beside": "Open links beside the active editor.", "configuration.markdown.suggest.paths.enabled.description": "Enable/disable path suggestions for markdown links", - "configuration.markdown.editor.drop.enabled": "Enable/disable dropping into the markdown editor to insert shift. Requires enabling `#workbench.experimental.editor.dropIntoEditor.enabled#`.", + "configuration.markdown.editor.drop.enabled": "Enable/disable dropping into the markdown editor to insert shift. Requires enabling `#workbench.editor.dropIntoEditor.enabled#`.", "configuration.markdown.editor.pasteLinks.enabled": "Enable/disable pasting files into a Markdown editor inserts Markdown links. Requires enabling `#editor.experimental.pasteActions.enabled#`.", "configuration.markdown.experimental.validate.enabled.description": "Enable/disable all error reporting in Markdown files.", "configuration.markdown.experimental.validate.referenceLinks.enabled.description": "Validate reference links in Markdown files, e.g. `[link][ref]`. Requires enabling `#markdown.experimental.validate.enabled#`.", diff --git a/src/vs/editor/contrib/dropIntoEditor/browser/dropIntoEditorContribution.ts b/src/vs/editor/contrib/dropIntoEditor/browser/dropIntoEditorContribution.ts index 457d445ad9226..551092627e52e 100644 --- a/src/vs/editor/contrib/dropIntoEditor/browser/dropIntoEditorContribution.ts +++ b/src/vs/editor/contrib/dropIntoEditor/browser/dropIntoEditorContribution.ts @@ -46,7 +46,7 @@ export class DropIntoEditorController extends Disposable implements IEditorContr this._languageFeaturesService.documentOnDropEditProvider.register('*', new DefaultOnDropProvider(workspaceContextService)); this._register(this._configurationService.onDidChangeConfiguration(e => { - if (e.affectsConfiguration('workbench.experimental.editor.dropIntoEditor.enabled')) { + if (e.affectsConfiguration('workbench.editor.dropIntoEditor.enabled')) { this.updateEditorOptions(editor); } })); @@ -56,7 +56,7 @@ export class DropIntoEditorController extends Disposable implements IEditorContr private updateEditorOptions(editor: ICodeEditor) { editor.updateOptions({ - enableDropIntoEditor: this._configurationService.getValue('workbench.experimental.editor.dropIntoEditor.enabled') + enableDropIntoEditor: this._configurationService.getValue('workbench.editor.dropIntoEditor.enabled') }); } diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 82f4a40688dbb..46325230f3c96 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -577,7 +577,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I return extHostLanguages.createLanguageStatusItem(extension, id, selector); }, registerDocumentDropEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentDropEditProvider): vscode.Disposable { - checkProposedApiEnabled(extension, 'textEditorDrop'); return extHostLanguageFeatures.registerDocumentOnDropEditProvider(extension, selector, provider); } }; diff --git a/src/vs/workbench/browser/parts/editor/editorDropTarget.ts b/src/vs/workbench/browser/parts/editor/editorDropTarget.ts index 4d29cc8f1434c..e9686439360ab 100644 --- a/src/vs/workbench/browser/parts/editor/editorDropTarget.ts +++ b/src/vs/workbench/browser/parts/editor/editorDropTarget.ts @@ -32,7 +32,7 @@ interface IDropOperation { } function isDropIntoEditorEnabledGlobally(configurationService: IConfigurationService) { - return configurationService.getValue('workbench.experimental.editor.dropIntoEditor.enabled'); + return configurationService.getValue('workbench.editor.dropIntoEditor.enabled'); } function isDragIntoEditorEvent(e: DragEvent): boolean { diff --git a/src/vs/workbench/browser/workbench.contribution.ts b/src/vs/workbench/browser/workbench.contribution.ts index 5d3a8a9d03732..b042c202d9824 100644 --- a/src/vs/workbench/browser/workbench.contribution.ts +++ b/src/vs/workbench/browser/workbench.contribution.ts @@ -466,6 +466,11 @@ const registry = Registry.as(ConfigurationExtensions.Con 'default': 'both', 'description': localize('layoutControlType', "Controls whether the layout control in the custom title bar is displayed as a single menu button or with multiple UI toggles."), }, + 'workbench.editor.dropIntoEditor.enabled': { + 'type': 'boolean', + 'default': true, + 'markdownDescription': localize('dropIntoEditor', "Controls whether you can drag and drop a file into a text editor by holding down `shift` (instead of opening the file in an editor)."), + }, 'workbench.experimental.layoutControl.enabled': { 'type': 'boolean', 'tags': ['experimental'], @@ -486,12 +491,6 @@ const registry = Registry.as(ConfigurationExtensions.Con 'description': localize('layoutControlType', "Controls whether the layout control in the custom title bar is displayed as a single menu button or with multiple UI toggles."), 'markdownDeprecationMessage': localize({ key: 'layoutControlTypeDeprecation', comment: ['{0} is a placeholder for a setting identifier.'] }, "This setting has been deprecated in favor of {0}", '`#workbench.layoutControl.type#`') }, - 'workbench.experimental.editor.dropIntoEditor.enabled': { - 'type': 'boolean', - 'default': true, - 'tags': ['experimental'], - 'markdownDescription': localize('dropIntoEditor', "Controls whether you can drag and drop a file into a text editor by holding down `shift` (instead of opening the file in an editor)."), - } } }); diff --git a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts index 17ab37e841f57..012e90c93847a 100644 --- a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts +++ b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts @@ -59,7 +59,6 @@ export const allApiProposals = Object.freeze({ terminalExitReason: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.terminalExitReason.d.ts', testCoverage: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.testCoverage.d.ts', testObserver: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.testObserver.d.ts', - textEditorDrop: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.textEditorDrop.d.ts', textSearchProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.textSearchProvider.d.ts', timeline: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.timeline.d.ts', tokenInformation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tokenInformation.d.ts', diff --git a/src/vscode-dts/vscode.d.ts b/src/vscode-dts/vscode.d.ts index bbb03b02dba57..8956456447ae2 100644 --- a/src/vscode-dts/vscode.d.ts +++ b/src/vscode-dts/vscode.d.ts @@ -5407,6 +5407,46 @@ declare module 'vscode' { provideLinkedEditingRanges(document: TextDocument, position: Position, token: CancellationToken): ProviderResult; } + /** + * An edit operation applied {@link DocumentDropEditProvider on drop}. + */ + export class DocumentDropEdit { + /** + * The text or snippet to insert at the drop location. + */ + insertText: string | SnippetString; + + /** + * An optional additional edit to apply on drop. + */ + additionalEdit?: WorkspaceEdit; + + /** + * @param insertText The text or snippet to insert at the drop location. + */ + constructor(insertText: string | SnippetString); + } + + /** + * Provider which handles dropping of resources into a text editor. + * + * The user can drop into a text editor by holding down `shift` while dragging. Requires `workbench.editor.dropIntoEditor.enabled` to be on. + */ + export interface DocumentDropEditProvider { + /** + * Provide edits which inserts the content being dragged and dropped into the document. + * + * @param document The document in which the drop occurred. + * @param position The position in the document where the drop occurred. + * @param dataTransfer A {@link DataTransfer} object that holds data about what is being dragged and dropped. + * @param token A cancellation token. + * + * @return A {@link DocumentDropEdit} or a thenable that resolves to such. The lack of a result can be + * signaled by returning `undefined` or `null`. + */ + provideDocumentDropEdits(document: TextDocument, position: Position, dataTransfer: DataTransfer, token: CancellationToken): ProviderResult; + } + /** * A tuple of two characters, like a pair of * opening and closing brackets. @@ -12785,6 +12825,16 @@ declare module 'vscode' { */ export function registerLinkedEditingRangeProvider(selector: DocumentSelector, provider: LinkedEditingRangeProvider): Disposable; + /** + * Registers a new {@link DocumentDropEditProvider}. + * + * @param selector A selector that defines the documents this provider applies to. + * @param provider A drop provider. + * + * @return A {@link Disposable} that unregisters this provider when disposed of. + */ + export function registerDocumentDropEditProvider(selector: DocumentSelector, provider: DocumentDropEditProvider): Disposable; + /** * Set a {@link LanguageConfiguration language configuration} for a language. * diff --git a/src/vscode-dts/vscode.proposed.textEditorDrop.d.ts b/src/vscode-dts/vscode.proposed.textEditorDrop.d.ts deleted file mode 100644 index 77a9b0781d720..0000000000000 --- a/src/vscode-dts/vscode.proposed.textEditorDrop.d.ts +++ /dev/null @@ -1,61 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -declare module 'vscode' { - - // https://github.com/microsoft/vscode/issues/142990 - - /** - * Provider which handles dropping of resources into a text editor. - * - * The user can drop into a text editor by holding down `shift` while dragging. Requires `workbench.experimental.editor.dropIntoEditor.enabled` to be on. - */ - export interface DocumentDropEditProvider { - /** - * Provide edits which inserts the content being dragged and dropped into the document. - * - * @param document The document in which the drop occurred. - * @param position The position in the document where the drop occurred. - * @param dataTransfer A {@link DataTransfer} object that holds data about what is being dragged and dropped. - * @param token A cancellation token. - * - * @return A {@link DocumentDropEdit} or a thenable that resolves to such. The lack of a result can be - * signaled by returning `undefined` or `null`. - */ - provideDocumentDropEdits(document: TextDocument, position: Position, dataTransfer: DataTransfer, token: CancellationToken): ProviderResult; - } - - /** - * An edit operation applied on drop. - */ - export class DocumentDropEdit { - /** - * The text or snippet to insert at the drop location. - */ - insertText: string | SnippetString; - - /** - * An optional additional edit to apply on drop. - */ - additionalEdit?: WorkspaceEdit; - - /** - * @param insertText The text or snippet to insert at the drop location. - */ - constructor(insertText: string | SnippetString); - } - - export namespace languages { - /** - * Registers a new {@link DocumentDropEditProvider}. - * - * @param selector A selector that defines the documents this provider applies to. - * @param provider A drop provider. - * - * @return A {@link Disposable} that unregisters this provider when disposed of. - */ - export function registerDocumentDropEditProvider(selector: DocumentSelector, provider: DocumentDropEditProvider): Disposable; - } -} From ee7680ac04cb18acf88dcb8b5d95aa56d30ba6fa Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 13 Jul 2022 16:33:51 -0700 Subject: [PATCH 035/121] Add configure decorations ctx menu entry Fixes #155118 --- .../terminal/browser/xterm/decorationAddon.ts | 98 ++++++++++++++++++- 1 file changed, 95 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.ts b/src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.ts index 31d764e8de274..feff72648ca2c 100644 --- a/src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.ts +++ b/src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.ts @@ -25,6 +25,8 @@ import { TERMINAL_COMMAND_DECORATION_DEFAULT_BACKGROUND_COLOR, TERMINAL_COMMAND_ import { Color } from 'vs/base/common/color'; import { IOpenerService } from 'vs/platform/opener/common/opener'; import { IGenericMarkProperties } from 'vs/platform/terminal/common/terminalProcess'; +import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput'; +import { Codicon } from 'vs/base/common/codicons'; const enum DecorationSelector { CommandDecoration = 'terminal-command-decoration', @@ -65,7 +67,8 @@ export class DecorationAddon extends Disposable implements ITerminalAddon { @IHoverService private readonly _hoverService: IHoverService, @IConfigurationService private readonly _configurationService: IConfigurationService, @IThemeService private readonly _themeService: IThemeService, - @IOpenerService private readonly _openerService: IOpenerService + @IOpenerService private readonly _openerService: IOpenerService, + @IQuickInputService private readonly _quickInputService: IQuickInputService ) { super(); this._register(toDisposable(() => this._dispose())); @@ -431,13 +434,102 @@ export class DecorationAddon extends Disposable implements ITerminalAddon { if (actions.length > 0) { actions.push(new Separator()); } - const label = localize("terminal.learnShellIntegration", 'Learn About Shell Integration'); + const labelConfigure = localize("terminal.configureCommandDecorations", 'Configure Command Decorations'); actions.push({ - class: undefined, tooltip: label, dispose: () => { }, id: 'terminal.learnShellIntegration', label, enabled: true, + class: undefined, tooltip: labelConfigure, dispose: () => { }, id: 'terminal.configureCommandDecorations', label: labelConfigure, enabled: true, + run: () => this._showConfigureCommandDecorationsQuickPick() + }); + const labelAbout = localize("terminal.learnShellIntegration", 'Learn About Shell Integration'); + actions.push({ + class: undefined, tooltip: labelAbout, dispose: () => { }, id: 'terminal.learnShellIntegration', label: labelAbout, enabled: true, run: () => this._openerService.open('https://code.visualstudio.com/docs/editor/integrated-terminal#_shell-integration') }); return actions; } + + private async _showConfigureCommandDecorationsQuickPick() { + const quickPick = this._quickInputService.createQuickPick(); + quickPick.items = [ + { id: 'a', label: localize('changeDefaultIcon', 'Change default icon') }, + { id: 'b', label: localize('changeSuccessIcon', 'Change success icon') }, + { id: 'c', label: localize('changeErrorIcon', 'Change error icon') }, + { type: 'separator' }, + { id: 'd', label: localize('toggleVisibility', 'Toggle visibility') }, + ]; + quickPick.canSelectMany = false; + quickPick.onDidAccept(async e => { + quickPick.hide(); + const result = quickPick.activeItems[0]; + let iconSetting: string | undefined; + switch (result.id) { + case 'a': iconSetting = TerminalSettingId.ShellIntegrationDecorationIcon; break; + case 'b': iconSetting = TerminalSettingId.ShellIntegrationDecorationIconSuccess; break; + case 'c': iconSetting = TerminalSettingId.ShellIntegrationDecorationIconError; break; + case 'd': this._showToggleVisibilityQuickPick(); break; + } + if (iconSetting) { + this._showChangeIconQuickPick(iconSetting); + } + }); + quickPick.show(); + } + + private async _showChangeIconQuickPick(iconSetting: string) { + type Item = IQuickPickItem & { icon: Codicon }; + const items: Item[] = []; + for (const icon of Codicon.getAll()) { + items.push({ label: `$(${icon.id})`, description: `${icon.id}`, icon }); + } + const result = await this._quickInputService.pick(items, { + matchOnDescription: true + }); + if (result) { + this._configurationService.updateValue(iconSetting, result.icon.id); + this._showConfigureCommandDecorationsQuickPick(); + } + } + + private _showToggleVisibilityQuickPick() { + const quickPick = this._quickInputService.createQuickPick(); + quickPick.hideInput = true; + quickPick.hideCheckAll = true; + quickPick.canSelectMany = true; + quickPick.title = localize('toggleVisibility', 'Toggle visibility'); + const configValue = this._configurationService.getValue(TerminalSettingId.ShellIntegrationDecorationsEnabled); + const gutterIcon: IQuickPickItem = { + label: localize('gutter', 'Gutter command decorations'), + picked: configValue !== 'never' && configValue !== 'overviewRuler' + }; + const overviewRulerIcon: IQuickPickItem = { + label: localize('overviewRuler', 'Overview ruler command decorations'), + picked: configValue !== 'never' && configValue !== 'gutter' + }; + quickPick.items = [gutterIcon, overviewRulerIcon]; + const selectedItems: IQuickPickItem[] = []; + if (configValue !== 'never') { + if (configValue !== 'gutter') { + selectedItems.push(gutterIcon); + } + if (configValue !== 'overviewRuler') { + selectedItems.push(overviewRulerIcon); + } + } + quickPick.selectedItems = selectedItems; + quickPick.onDidChangeSelection(async e => { + let newValue: 'both' | 'gutter' | 'overviewRuler' | 'never' = 'never'; + if (e.includes(gutterIcon)) { + if (e.includes(overviewRulerIcon)) { + newValue = 'both'; + } else { + newValue = 'gutter'; + } + } else if (e.includes(overviewRulerIcon)) { + newValue = 'overviewRuler'; + } + await this._configurationService.updateValue(TerminalSettingId.ShellIntegrationDecorationsEnabled, newValue); + }); + quickPick.show(); + } } let successColor: string | Color | undefined; let errorColor: string | Color | undefined; From 8539bae4441492a81f7cd4062724fc451e1b935c Mon Sep 17 00:00:00 2001 From: Miguel Solorio Date: Wed, 13 Jul 2022 16:36:38 -0700 Subject: [PATCH 036/121] Add button separator color token (#155103) * Add button separator color token * Fix compilation errors --- src/vs/base/browser/ui/button/button.ts | 4 +++- src/vs/platform/theme/common/colorRegistry.ts | 1 + src/vs/platform/theme/common/styler.ts | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/vs/base/browser/ui/button/button.ts b/src/vs/base/browser/ui/button/button.ts index 489425b6ce438..2b48b94c938e2 100644 --- a/src/vs/base/browser/ui/button/button.ts +++ b/src/vs/base/browser/ui/button/button.ts @@ -28,6 +28,7 @@ export interface IButtonStyles { buttonBackground?: Color; buttonHoverBackground?: Color; buttonForeground?: Color; + buttonSeparator?: Color; buttonSecondaryBackground?: Color; buttonSecondaryHoverBackground?: Color; buttonSecondaryForeground?: Color; @@ -37,6 +38,7 @@ export interface IButtonStyles { const defaultOptions: IButtonStyles = { buttonBackground: Color.fromHex('#0E639C'), buttonHoverBackground: Color.fromHex('#006BB3'), + buttonSeparator: Color.white, buttonForeground: Color.white }; @@ -315,7 +317,7 @@ export class ButtonWithDropdown extends Disposable implements IButton { // Separator this.separatorContainer.style.backgroundColor = styles.buttonBackground?.toString() ?? ''; - this.separator.style.backgroundColor = styles.buttonForeground?.toString() ?? ''; + this.separator.style.backgroundColor = styles.buttonSeparator?.toString() ?? ''; } focus(): void { diff --git a/src/vs/platform/theme/common/colorRegistry.ts b/src/vs/platform/theme/common/colorRegistry.ts index 4f1107e287027..3b7889d5caca5 100644 --- a/src/vs/platform/theme/common/colorRegistry.ts +++ b/src/vs/platform/theme/common/colorRegistry.ts @@ -266,6 +266,7 @@ export const checkboxForeground = registerColor('checkbox.foreground', { dark: s export const checkboxBorder = registerColor('checkbox.border', { dark: selectBorder, light: selectBorder, hcDark: selectBorder, hcLight: selectBorder }, nls.localize('checkbox.border', "Border color of checkbox widget.")); export const buttonForeground = registerColor('button.foreground', { dark: Color.white, light: Color.white, hcDark: Color.white, hcLight: Color.white }, nls.localize('buttonForeground', "Button foreground color.")); +export const buttonSeparator = registerColor('button.separator', { dark: transparent(buttonForeground, .4), light: transparent(buttonForeground, .4), hcDark: transparent(buttonForeground, .4), hcLight: transparent(buttonForeground, .4) }, nls.localize('buttonSeparator', "Button separator color.")); export const buttonBackground = registerColor('button.background', { dark: '#0E639C', light: '#007ACC', hcDark: null, hcLight: '#0F4A85' }, nls.localize('buttonBackground', "Button background color.")); export const buttonHoverBackground = registerColor('button.hoverBackground', { dark: lighten(buttonBackground, 0.2), light: darken(buttonBackground, 0.2), hcDark: null, hcLight: null }, nls.localize('buttonHoverBackground', "Button background color when hovering.")); export const buttonBorder = registerColor('button.border', { dark: contrastBorder, light: contrastBorder, hcDark: contrastBorder, hcLight: contrastBorder }, nls.localize('buttonBorder', "Button border color.")); diff --git a/src/vs/platform/theme/common/styler.ts b/src/vs/platform/theme/common/styler.ts index 2cb2e9440cebe..8a073beaee685 100644 --- a/src/vs/platform/theme/common/styler.ts +++ b/src/vs/platform/theme/common/styler.ts @@ -6,7 +6,7 @@ import { Color } from 'vs/base/common/color'; import { IDisposable } from 'vs/base/common/lifecycle'; import { IThemable, styleFn } from 'vs/base/common/styler'; -import { activeContrastBorder, badgeBackground, badgeForeground, breadcrumbsActiveSelectionForeground, breadcrumbsBackground, breadcrumbsFocusForeground, breadcrumbsForeground, buttonBackground, buttonBorder, buttonForeground, buttonHoverBackground, buttonSecondaryBackground, buttonSecondaryForeground, buttonSecondaryHoverBackground, ColorIdentifier, ColorTransform, ColorValue, contrastBorder, editorWidgetBackground, editorWidgetBorder, editorWidgetForeground, focusBorder, inputActiveOptionBackground, inputActiveOptionBorder, inputActiveOptionForeground, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationInfoForeground, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationWarningForeground, keybindingLabelBackground, keybindingLabelBorder, keybindingLabelBottomBorder, keybindingLabelForeground, listActiveSelectionBackground, listActiveSelectionForeground, listActiveSelectionIconForeground, listDropBackground, listFilterWidgetBackground, listFilterWidgetNoMatchesOutline, listFilterWidgetOutline, listFocusBackground, listFocusForeground, listFocusOutline, listHoverBackground, listHoverForeground, listInactiveFocusBackground, listInactiveFocusOutline, listInactiveSelectionBackground, listInactiveSelectionForeground, listInactiveSelectionIconForeground, menuBackground, menuBorder, menuForeground, menuSelectionBackground, menuSelectionBorder, menuSelectionForeground, menuSeparatorBackground, pickerGroupForeground, problemsErrorIconForeground, problemsInfoIconForeground, problemsWarningIconForeground, progressBarBackground, quickInputListFocusBackground, quickInputListFocusForeground, quickInputListFocusIconForeground, resolveColorValue, scrollbarShadow, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, selectBackground, selectBorder, selectForeground, selectListBackground, checkboxBackground, checkboxBorder, checkboxForeground, tableColumnsBorder, tableOddRowsBackgroundColor, textLinkForeground, treeIndentGuidesStroke, widgetShadow, listFocusAndSelectionOutline } from 'vs/platform/theme/common/colorRegistry'; +import { activeContrastBorder, badgeBackground, badgeForeground, breadcrumbsActiveSelectionForeground, breadcrumbsBackground, breadcrumbsFocusForeground, breadcrumbsForeground, buttonBackground, buttonBorder, buttonForeground, buttonHoverBackground, buttonSecondaryBackground, buttonSecondaryForeground, buttonSecondaryHoverBackground, ColorIdentifier, ColorTransform, ColorValue, contrastBorder, editorWidgetBackground, editorWidgetBorder, editorWidgetForeground, focusBorder, inputActiveOptionBackground, inputActiveOptionBorder, inputActiveOptionForeground, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationInfoForeground, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationWarningForeground, keybindingLabelBackground, keybindingLabelBorder, keybindingLabelBottomBorder, keybindingLabelForeground, listActiveSelectionBackground, listActiveSelectionForeground, listActiveSelectionIconForeground, listDropBackground, listFilterWidgetBackground, listFilterWidgetNoMatchesOutline, listFilterWidgetOutline, listFocusBackground, listFocusForeground, listFocusOutline, listHoverBackground, listHoverForeground, listInactiveFocusBackground, listInactiveFocusOutline, listInactiveSelectionBackground, listInactiveSelectionForeground, listInactiveSelectionIconForeground, menuBackground, menuBorder, menuForeground, menuSelectionBackground, menuSelectionBorder, menuSelectionForeground, menuSeparatorBackground, pickerGroupForeground, problemsErrorIconForeground, problemsInfoIconForeground, problemsWarningIconForeground, progressBarBackground, quickInputListFocusBackground, quickInputListFocusForeground, quickInputListFocusIconForeground, resolveColorValue, scrollbarShadow, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, selectBackground, selectBorder, selectForeground, selectListBackground, checkboxBackground, checkboxBorder, checkboxForeground, tableColumnsBorder, tableOddRowsBackgroundColor, textLinkForeground, treeIndentGuidesStroke, widgetShadow, listFocusAndSelectionOutline, buttonSeparator } from 'vs/platform/theme/common/colorRegistry'; import { isHighContrast } from 'vs/platform/theme/common/theme'; import { IColorTheme, IThemeService } from 'vs/platform/theme/common/themeService'; @@ -225,6 +225,7 @@ export const defaultListStyles: IColorMapping = { export interface IButtonStyleOverrides extends IStyleOverrides { buttonForeground?: ColorIdentifier; + buttonSeparator?: ColorIdentifier; buttonBackground?: ColorIdentifier; buttonHoverBackground?: ColorIdentifier; buttonSecondaryForeground?: ColorIdentifier; @@ -236,6 +237,7 @@ export interface IButtonStyleOverrides extends IStyleOverrides { export function attachButtonStyler(widget: IThemable, themeService: IThemeService, style?: IButtonStyleOverrides): IDisposable { return attachStyler(themeService, { buttonForeground: style?.buttonForeground || buttonForeground, + buttonSeparator: style?.buttonSeparator || buttonSeparator, buttonBackground: style?.buttonBackground || buttonBackground, buttonHoverBackground: style?.buttonHoverBackground || buttonHoverBackground, buttonSecondaryForeground: style?.buttonSecondaryForeground || buttonSecondaryForeground, @@ -349,6 +351,7 @@ export const defaultDialogStyles = { dialogShadow: widgetShadow, dialogBorder: contrastBorder, buttonForeground: buttonForeground, + buttonSeparator: buttonSeparator, buttonBackground: buttonBackground, buttonSecondaryBackground: buttonSecondaryBackground, buttonSecondaryForeground: buttonSecondaryForeground, From 94575b0fb3a7975d521b1f1374d222af3796c5bf Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Wed, 13 Jul 2022 18:16:53 -0700 Subject: [PATCH 037/121] support watch task reconnection (#155120) --- src/vs/platform/terminal/common/terminal.ts | 14 ++- .../terminal/common/terminalProcess.ts | 2 + src/vs/platform/terminal/node/ptyService.ts | 5 +- .../tasks/browser/abstractTaskService.ts | 33 +++-- .../tasks/browser/terminalTaskSystem.ts | 115 +++++++++++------- .../contrib/tasks/common/taskSystem.ts | 1 + .../workbench/contrib/tasks/common/tasks.ts | 3 +- .../contrib/terminal/browser/terminal.ts | 8 +- .../terminal/browser/terminalInstance.ts | 4 +- .../browser/terminalProcessManager.ts | 9 +- .../terminal/browser/terminalService.ts | 19 +++ 11 files changed, 154 insertions(+), 59 deletions(-) diff --git a/src/vs/platform/terminal/common/terminal.ts b/src/vs/platform/terminal/common/terminal.ts index bc20c79294c55..c9c7fcde470f4 100644 --- a/src/vs/platform/terminal/common/terminal.ts +++ b/src/vs/platform/terminal/common/terminal.ts @@ -167,6 +167,8 @@ export interface IPtyHostAttachTarget { icon: TerminalIcon | undefined; fixedDimensions: IFixedTerminalDimensions | undefined; environmentVariableCollections: ISerializableEnvironmentVariableCollections | undefined; + reconnectionOwner?: string; + task?: { label: string; id: string; lastTask?: string; group?: string }; } export enum TitleEventSource { @@ -438,6 +440,11 @@ export interface IShellLaunchConfig { */ ignoreConfigurationCwd?: boolean; + /** + * The owner of this terminal for reconnection. + */ + reconnectionOwner?: string; + /** Whether to wait for a key press before closing the terminal. */ waitOnExit?: boolean | string | ((exitCode: number) => string); @@ -462,7 +469,7 @@ export interface IShellLaunchConfig { /** * This is a terminal that attaches to an already running terminal. */ - attachPersistentProcess?: { id: number; findRevivedId?: boolean; pid: number; title: string; titleSource: TitleEventSource; cwd: string; icon?: TerminalIcon; color?: string; hasChildProcesses?: boolean; fixedDimensions?: IFixedTerminalDimensions; environmentVariableCollections?: ISerializableEnvironmentVariableCollections }; + attachPersistentProcess?: { id: number; findRevivedId?: boolean; pid: number; title: string; titleSource: TitleEventSource; cwd: string; icon?: TerminalIcon; color?: string; hasChildProcesses?: boolean; fixedDimensions?: IFixedTerminalDimensions; environmentVariableCollections?: ISerializableEnvironmentVariableCollections; reconnectionOwner?: string; task?: { label: string; id: string; lastTask?: string; group?: string } }; /** * Whether the terminal process environment should be exactly as provided in @@ -533,6 +540,11 @@ export interface IShellLaunchConfig { * Create a terminal without shell integration even when it's enabled */ ignoreShellIntegration?: boolean; + + /** + * The task associated with this terminal + */ + task?: { lastTask?: string; group?: string; label: string; id: string }; } export interface ICreateContributedTerminalProfileOptions { diff --git a/src/vs/platform/terminal/common/terminalProcess.ts b/src/vs/platform/terminal/common/terminalProcess.ts index 9eedabb333cc7..dbbd128282928 100644 --- a/src/vs/platform/terminal/common/terminalProcess.ts +++ b/src/vs/platform/terminal/common/terminalProcess.ts @@ -60,6 +60,8 @@ export interface IProcessDetails { color: string | undefined; fixedDimensions: IFixedTerminalDimensions | undefined; environmentVariableCollections: ISerializableEnvironmentVariableCollections | undefined; + reconnectionOwner?: string; + task?: { label: string; id: string; lastTask?: string; group?: string }; } export type ITerminalTabLayoutInfoDto = IRawTerminalTabLayoutInfo; diff --git a/src/vs/platform/terminal/node/ptyService.ts b/src/vs/platform/terminal/node/ptyService.ts index c45d75bbb12e4..2b7ad270732bb 100644 --- a/src/vs/platform/terminal/node/ptyService.ts +++ b/src/vs/platform/terminal/node/ptyService.ts @@ -347,6 +347,7 @@ export class PtyService extends Disposable implements IPtyService { } async setTerminalLayoutInfo(args: ISetTerminalLayoutInfoArgs): Promise { + this._logService.trace('ptyService#setLayoutInfo', args.tabs); this._workspaceLayoutInfos.set(args.workspaceId, args); } @@ -408,7 +409,9 @@ export class PtyService extends Disposable implements IPtyService { icon: persistentProcess.icon, color: persistentProcess.color, fixedDimensions: persistentProcess.fixedDimensions, - environmentVariableCollections: persistentProcess.processLaunchOptions.options.environmentVariableCollections + environmentVariableCollections: persistentProcess.processLaunchOptions.options.environmentVariableCollections, + reconnectionOwner: persistentProcess.shellLaunchConfig.reconnectionOwner, + task: persistentProcess.shellLaunchConfig.task }; } diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index 89ec1896b2669..33f885dfe72ef 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -339,6 +339,23 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer this._onDidRegisterSupportedExecutions.fire(); } + private async _restartTasks(): Promise { + const recentlyUsedTasks = await this.readRecentTasks(); + if (!recentlyUsedTasks) { + return; + } + for (const task of recentlyUsedTasks) { + if (ConfiguringTask.is(task)) { + const resolved = await this.tryResolveTask(task); + if (resolved) { + this.run(resolved, undefined, TaskRunSource.Reconnect); + } + } else { + this.run(task, undefined, TaskRunSource.Reconnect); + } + } + } + public get onDidStateChange(): Event { return this._onDidStateChange.event; } @@ -405,7 +422,6 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer this._runTerminateCommand(arg); } }); - CommandsRegistry.registerCommand('workbench.action.tasks.showLog', () => { if (!this._canRunCommand()) { return; @@ -602,7 +618,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer return infosCount > 0; } - public registerTaskSystem(key: string, info: ITaskSystemInfo): void { + public async registerTaskSystem(key: string, info: ITaskSystemInfo): Promise { // Ideally the Web caller of registerRegisterTaskSystem would use the correct key. // However, the caller doesn't know about the workspace folders at the time of the call, even though we know about them here. if (info.platform === Platform.Platform.Web) { @@ -622,6 +638,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer if (this.hasTaskSystemInfo) { this._onDidChangeTaskSystemInfo.fire(); + await this._restartTasks(); } } @@ -661,7 +678,6 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } } } - return result; } @@ -917,7 +933,6 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer map.get(folder).push(task); } } - for (const entry of recentlyUsedTasks.entries()) { const key = entry[0]; const task = JSON.parse(entry[1]); @@ -926,6 +941,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } const readTasksMap: Map = new Map(); + async function readTasks(that: AbstractTaskService, map: Map, isWorkspaceFile: boolean) { for (const key of map.keys()) { const custom: CustomTask[] = []; @@ -954,7 +970,6 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } await readTasks(this, folderToTasksMap, false); await readTasks(this, workspaceToTaskMap, true); - for (const key of recentlyUsedTasks.keys()) { if (readTasksMap.has(key)) { tasks.push(readTasksMap.get(key)!); @@ -1749,8 +1764,11 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer ? await this.getTask(taskFolder, taskIdentifier) : task) ?? task; } await ProblemMatcherRegistry.onReady(); - const executeResult = this._getTaskSystem().run(taskToRun, resolver); - return this._handleExecuteResult(executeResult, runSource); + const executeResult = runSource === TaskRunSource.Reconnect ? this._getTaskSystem().reconnect(taskToRun, resolver) : this._getTaskSystem().run(taskToRun, resolver); + if (executeResult) { + return this._handleExecuteResult(executeResult, runSource); + } + return { exitCode: 0 }; } private async _handleExecuteResult(executeResult: ITaskExecuteResult, runSource?: TaskRunSource): Promise { @@ -1781,6 +1799,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer throw new TaskError(Severity.Warning, nls.localize('TaskSystem.active', 'There is already a task running. Terminate it first before executing another task.'), TaskErrors.RunningTask); } } + this._setRecentlyUsedTask(executeResult.task); return executeResult.promise; } diff --git a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts index 7cfab363b6d06..b46a625ed1009 100644 --- a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts @@ -3,58 +3,52 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as path from 'vs/base/common/path'; -import * as nls from 'vs/nls'; -import * as Objects from 'vs/base/common/objects'; -import * as Types from 'vs/base/common/types'; -import * as Platform from 'vs/base/common/platform'; import * as Async from 'vs/base/common/async'; -import * as resources from 'vs/base/common/resources'; import { IStringDictionary } from 'vs/base/common/collections'; +import { Emitter, Event } from 'vs/base/common/event'; +import { isUNC } from 'vs/base/common/extpath'; +import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; import { LinkedMap, Touch } from 'vs/base/common/map'; +import * as Objects from 'vs/base/common/objects'; +import * as path from 'vs/base/common/path'; +import * as Platform from 'vs/base/common/platform'; +import * as resources from 'vs/base/common/resources'; import Severity from 'vs/base/common/severity'; -import { Event, Emitter } from 'vs/base/common/event'; -import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; -import { isUNC } from 'vs/base/common/extpath'; +import * as Types from 'vs/base/common/types'; +import * as nls from 'vs/nls'; +import { IModelService } from 'vs/editor/common/services/model'; import { IFileService } from 'vs/platform/files/common/files'; import { IMarkerService, MarkerSeverity } from 'vs/platform/markers/common/markers'; -import { IWorkspaceContextService, WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; -import { IModelService } from 'vs/editor/common/services/model'; -import { ProblemMatcher, ProblemMatcherRegistry /*, ProblemPattern, getResource */ } from 'vs/workbench/contrib/tasks/common/problemMatcher'; +import { IWorkspaceContextService, IWorkspaceFolder, WorkbenchState } from 'vs/platform/workspace/common/workspace'; import { Markers } from 'vs/workbench/contrib/markers/common/markers'; +import { ProblemMatcher, ProblemMatcherRegistry /*, ProblemPattern, getResource */ } from 'vs/workbench/contrib/tasks/common/problemMatcher'; -import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; -import { ITerminalProfileResolverService, TERMINAL_VIEW_ID } from 'vs/workbench/contrib/terminal/common/terminal'; -import { ITerminalService, ITerminalInstance, ITerminalGroupService } from 'vs/workbench/contrib/terminal/browser/terminal'; -import { IOutputService } from 'vs/workbench/services/output/common/output'; -import { StartStopProblemCollector, WatchingProblemCollector, ProblemCollectorEventKind, ProblemHandlingStrategy } from 'vs/workbench/contrib/tasks/common/problemCollectors'; -import { - Task, CustomTask, ContributedTask, RevealKind, CommandOptions, IShellConfiguration, RuntimeType, PanelKind, - TaskEvent, TaskEventKind, IShellQuotingOptions, ShellQuoting, CommandString, ICommandConfiguration, IExtensionTaskSource, TaskScope, RevealProblemKind, DependsOrder, TaskSourceKind, InMemoryTask, ITaskEvent, TaskSettingId -} from 'vs/workbench/contrib/tasks/common/tasks'; -import { - ITaskSystem, ITaskSummary, ITaskExecuteResult, TaskExecuteKind, TaskError, TaskErrors, ITaskResolver, - Triggers, ITaskTerminateResponse, ITaskSystemInfoResolver, ITaskSystemInfo, IResolveSet, IResolvedVariables -} from 'vs/workbench/contrib/tasks/common/taskSystem'; -import { URI } from 'vs/base/common/uri'; -import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; +import { Codicon } from 'vs/base/common/codicons'; import { Schemas } from 'vs/base/common/network'; -import { IPathService } from 'vs/workbench/services/path/common/pathService'; -import { IViewsService, IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/common/views'; -import { ILogService } from 'vs/platform/log/common/log'; +import { URI } from 'vs/base/common/uri'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; -import { IShellLaunchConfig, TerminalLocation, TerminalSettingId } from 'vs/platform/terminal/common/terminal'; -import { TerminalProcessExtHostProxy } from 'vs/workbench/contrib/terminal/browser/terminalProcessExtHostProxy'; -import { TaskTerminalStatus } from 'vs/workbench/contrib/tasks/browser/taskTerminalStatus'; -import { ITaskService } from 'vs/workbench/contrib/tasks/common/taskService'; -import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite'; +import { ILogService } from 'vs/platform/log/common/log'; import { INotificationService } from 'vs/platform/notification/common/notification'; -import { ThemeIcon } from 'vs/platform/theme/common/themeService'; +import { IShellLaunchConfig, TerminalLocation, TerminalSettingId } from 'vs/platform/terminal/common/terminal'; import { formatMessageForTerminal } from 'vs/platform/terminal/common/terminalStrings'; +import { ThemeIcon } from 'vs/platform/theme/common/themeService'; +import { IViewDescriptorService, IViewsService, ViewContainerLocation } from 'vs/workbench/common/views'; +import { TaskTerminalStatus } from 'vs/workbench/contrib/tasks/browser/taskTerminalStatus'; +import { ProblemCollectorEventKind, ProblemHandlingStrategy, StartStopProblemCollector, WatchingProblemCollector } from 'vs/workbench/contrib/tasks/common/problemCollectors'; import { GroupKind } from 'vs/workbench/contrib/tasks/common/taskConfiguration'; -import { Codicon } from 'vs/base/common/codicons'; +import { CommandOptions, CommandString, ContributedTask, CustomTask, DependsOrder, ICommandConfiguration, IExtensionTaskSource, InMemoryTask, IShellConfiguration, IShellQuotingOptions, ITaskEvent, PanelKind, RevealKind, RevealProblemKind, RuntimeType, ShellQuoting, Task, TaskEvent, TaskEventKind, TaskScope, TaskSettingId, TaskSourceKind } from 'vs/workbench/contrib/tasks/common/tasks'; +import { ITaskService } from 'vs/workbench/contrib/tasks/common/taskService'; +import { IResolvedVariables, IResolveSet, ITaskExecuteResult, ITaskResolver, ITaskSummary, ITaskSystem, ITaskSystemInfo, ITaskSystemInfoResolver, ITaskTerminateResponse, TaskError, TaskErrors, TaskExecuteKind, Triggers } from 'vs/workbench/contrib/tasks/common/taskSystem'; +import { ITerminalGroupService, ITerminalInstance, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal'; import { VSCodeOscProperty, VSCodeOscPt, VSCodeSequence } from 'vs/workbench/contrib/terminal/browser/terminalEscapeSequences'; +import { TerminalProcessExtHostProxy } from 'vs/workbench/contrib/terminal/browser/terminalProcessExtHostProxy'; +import { ITerminalProfileResolverService, TERMINAL_VIEW_ID } from 'vs/workbench/contrib/terminal/common/terminal'; +import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; +import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; +import { IOutputService } from 'vs/workbench/services/output/common/output'; +import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite'; +import { IPathService } from 'vs/workbench/services/path/common/pathService'; interface ITerminalData { terminal: ITerminalInstance; @@ -205,7 +199,8 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { private _previousTerminalInstance: ITerminalInstance | undefined; private _terminalStatusManager: TaskTerminalStatus; private _terminalCreationQueue: Promise = Promise.resolve(); - + private _hasReconnected: boolean = false; + private _tasksToReconnect: string[] = []; private readonly _onDidStateChange: Emitter; get taskShellIntegrationStartSequence(): string { @@ -245,12 +240,23 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { this._terminals = Object.create(null); this._idleTaskTerminals = new LinkedMap(); this._sameTaskTerminals = Object.create(null); - this._onDidStateChange = new Emitter(); this._taskSystemInfoResolver = taskSystemInfoResolver; this._register(this._terminalStatusManager = new TaskTerminalStatus(taskService)); } + private _reconnectToTerminals(terminals: ITerminalInstance[]): void { + for (const terminal of terminals) { + const taskForTerminal = terminal.shellLaunchConfig.attachPersistentProcess?.task; + if (taskForTerminal?.id && taskForTerminal?.lastTask) { + this._tasksToReconnect.push(taskForTerminal.id); + this._terminals[terminal.instanceId] = { terminal, lastTask: taskForTerminal.lastTask, group: taskForTerminal.group }; + } else { + this._logService.trace(`Could not reconnect to terminal ${terminal.instanceId} with process details ${terminal.shellLaunchConfig.attachPersistentProcess}`); + } + } + } + public get onDidStateChange(): Event { return this._onDidStateChange.event; } @@ -263,6 +269,19 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { this._outputService.showChannel(this._outputChannelId, true); } + public reconnect(task: Task, resolver: ITaskResolver, trigger: string = Triggers.command): ITaskExecuteResult | undefined { + const terminals = this._terminalService.getReconnectedTerminals('Task'); + if (!this._hasReconnected && terminals && terminals.length > 0) { + this._reconnectToTerminals(terminals); + this._hasReconnected = true; + } + if (this._tasksToReconnect.includes(task._id)) { + this._lastTask = new VerifiedTask(task, resolver, trigger); + this.rerun(); + } + return undefined; + } + public run(task: Task, resolver: ITaskResolver, trigger: string = Triggers.command): ITaskExecuteResult { task = task.clone(); // A small amount of task state is stored in the task (instance) and tasks passed in to run may have that set already. const recentTaskKey = task.getRecentlyUsedKey() ?? ''; @@ -1269,7 +1288,18 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { return createdTerminal; } + private _reviveTerminals(): void { + if (Object.entries(this._terminals).length === 0) { + for (const terminal of this._terminalService.instances) { + if (terminal.shellLaunchConfig.attachPersistentProcess?.task?.lastTask) { + this._terminals[terminal.instanceId] = { lastTask: terminal.shellLaunchConfig.attachPersistentProcess.task.lastTask, group: terminal.shellLaunchConfig.attachPersistentProcess.task.group, terminal }; + } + } + } + } + private async _createTerminal(task: CustomTask | ContributedTask, resolver: VariableResolver, workspaceFolder: IWorkspaceFolder | undefined): Promise<[ITerminalInstance | undefined, TaskError | undefined]> { + this._reviveTerminals(); const platform = resolver.taskSystemInfo ? resolver.taskSystemInfo.platform : Platform.platform; const options = await this._resolveOptions(resolver, task.command.options); const presentationOptions = task.command.presentation; @@ -1308,7 +1338,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { }, 'Executing task: {0}', task._label), { excludeLeadingNewLine: true }) : undefined, isFeatureTerminal: true, icon: task.configurationProperties.icon?.id ? ThemeIcon.fromId(task.configurationProperties.icon.id) : undefined, - color: task.configurationProperties.icon?.color || undefined, + color: task.configurationProperties.icon?.color || undefined }; } else { const resolvedResult: { command: CommandString; args: CommandString[] } = await this._resolveCommandAndArgs(resolver, task.command); @@ -1369,9 +1399,10 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { this._terminalCreationQueue = this._terminalCreationQueue.then(() => this._doCreateTerminal(group, launchConfigs!)); const result: ITerminalInstance = (await this._terminalCreationQueue)!; - + result.shellLaunchConfig.task = { lastTask: taskKey, group, label: task._label, id: task._id }; + result.shellLaunchConfig.reconnectionOwner = 'Task'; const terminalKey = result.instanceId.toString(); - result.onDisposed((terminal) => { + result.onDisposed(() => { const terminalData = this._terminals[terminalKey]; if (terminalData) { delete this._terminals[terminalKey]; diff --git a/src/vs/workbench/contrib/tasks/common/taskSystem.ts b/src/vs/workbench/contrib/tasks/common/taskSystem.ts index cd204106e8e08..7b7b67f3a19c6 100644 --- a/src/vs/workbench/contrib/tasks/common/taskSystem.ts +++ b/src/vs/workbench/contrib/tasks/common/taskSystem.ts @@ -102,6 +102,7 @@ export interface ITaskSystemInfoResolver { export interface ITaskSystem { onDidStateChange: Event; run(task: Task, resolver: ITaskResolver): ITaskExecuteResult; + reconnect(task: Task, resolver: ITaskResolver): ITaskExecuteResult | undefined; rerun(): ITaskExecuteResult | undefined; isActive(): Promise; isActiveSync(): boolean; diff --git a/src/vs/workbench/contrib/tasks/common/tasks.ts b/src/vs/workbench/contrib/tasks/common/tasks.ts index 5877beb6437a6..2033ec632d99c 100644 --- a/src/vs/workbench/contrib/tasks/common/tasks.ts +++ b/src/vs/workbench/contrib/tasks/common/tasks.ts @@ -1131,7 +1131,8 @@ export const enum TaskRunSource { System, User, FolderOpen, - ConfigurationChange + ConfigurationChange, + Reconnect } export namespace TaskEvent { diff --git a/src/vs/workbench/contrib/terminal/browser/terminal.ts b/src/vs/workbench/contrib/terminal/browser/terminal.ts index aa125ac3d78f6..45871689f6098 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminal.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminal.ts @@ -133,6 +133,7 @@ export interface ITerminalService extends ITerminalInstanceHost { readonly connectionState: TerminalConnectionState; readonly defaultLocation: TerminalLocation; + initializeTerminals(): Promise; onDidChangeActiveGroup: Event; onDidDisposeGroup: Event; @@ -163,6 +164,11 @@ export interface ITerminalService extends ITerminalInstanceHost { getInstanceFromId(terminalId: number): ITerminalInstance | undefined; getInstanceFromIndex(terminalIndex: number): ITerminalInstance; + /** + * An owner of terminals might be created after reconnection has occurred, + * so store them to be requested/adopted later + */ + getReconnectedTerminals(reconnectionOwner: string): ITerminalInstance[] | undefined; getActiveOrCreateInstance(): Promise; moveToEditor(source: ITerminalInstance): void; @@ -439,7 +445,7 @@ export interface ITerminalInstance { readonly fixedRows?: number; readonly icon?: TerminalIcon; readonly color?: string; - + readonly reconnectionOwner?: string; readonly processName: string; readonly sequence?: string; readonly staticTitle?: string; diff --git a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts index 761739d44a9b7..bbfb4d972071d 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts @@ -276,6 +276,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { // TODO: Should this be an event as it can fire twice? get processReady(): Promise { return this._processManager.ptyProcessReady; } get hasChildProcesses(): boolean { return this.shellLaunchConfig.attachPersistentProcess?.hasChildProcesses || this._processManager.hasChildProcesses; } + get reconnectionOwner(): string | undefined { return this.shellLaunchConfig.attachPersistentProcess?.reconnectionOwner || this.shellLaunchConfig.reconnectionOwner; } get areLinksReady(): boolean { return this._areLinksReady; } get initialDataEvents(): string[] | undefined { return this._initialDataEvents; } get exitCode(): number | undefined { return this._exitCode; } @@ -1726,7 +1727,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { if (this._isExiting) { return; } - const parsedExitResult = parseExitResult(exitCodeOrError, this.shellLaunchConfig, this._processManager.processState, this._initialCwd); if (this._usedShellIntegrationInjection && this._processManager.processState === ProcessState.KilledDuringLaunch && parsedExitResult?.code !== 0) { @@ -2355,7 +2355,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { info.requiresAction && this._configHelper.config.environmentChangesRelaunch && !this._processManager.hasWrittenData && - !this._shellLaunchConfig.isFeatureTerminal && + (this.reconnectionOwner || !this._shellLaunchConfig.isFeatureTerminal) && !this._shellLaunchConfig.customPtyImplementation && !this._shellLaunchConfig.isExtensionOwnedTerminal && !this._shellLaunchConfig.attachPersistentProcess diff --git a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts index ba6540e654cc1..901505cb26a35 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts @@ -113,9 +113,10 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce readonly onRestoreCommands = this._onRestoreCommands.event; get persistentProcessId(): number | undefined { return this._process?.id; } - get shouldPersist(): boolean { return this._process ? this._process.shouldPersist : false; } + get shouldPersist(): boolean { return !!this.reconnectionOwner || (this._process ? this._process.shouldPersist : false); } get hasWrittenData(): boolean { return this._hasWrittenData; } get hasChildProcesses(): boolean { return this._hasChildProcesses; } + get reconnectionOwner(): string | undefined { return this._shellLaunchConfig?.attachPersistentProcess?.reconnectionOwner || this._shellLaunchConfig?.reconnectionOwner || undefined; } constructor( private readonly _instanceId: number, @@ -245,7 +246,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce // this is a copy of what the merged environment collection is on the remote side const env = await this._resolveEnvironment(backend, variableResolver, shellLaunchConfig); - const shouldPersist = !shellLaunchConfig.isFeatureTerminal && this._configHelper.config.enablePersistentSessions && !shellLaunchConfig.isTransient; + const shouldPersist = (!!shellLaunchConfig.reconnectionOwner || !shellLaunchConfig.isFeatureTerminal) && this._configHelper.config.enablePersistentSessions && !shellLaunchConfig.isTransient; if (shellLaunchConfig.attachPersistentProcess) { const result = await backend.attachToProcess(shellLaunchConfig.attachPersistentProcess.id); if (result) { @@ -461,7 +462,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce windowsEnableConpty: this._configHelper.config.windowsEnableConpty && !isScreenReaderModeEnabled, environmentVariableCollections: this._extEnvironmentVariableCollection ? serializeEnvironmentVariableCollections(this._extEnvironmentVariableCollection.collections) : undefined }; - const shouldPersist = this._configHelper.config.enablePersistentSessions && !shellLaunchConfig.isFeatureTerminal; + const shouldPersist = this._configHelper.config.enablePersistentSessions && (!!this.reconnectionOwner || !shellLaunchConfig.isFeatureTerminal); return await backend.createProcess(shellLaunchConfig, initialCwd, cols, rows, this._configHelper.config.unicodeVersion, env, options, shouldPersist); } @@ -494,7 +495,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce this._ptyResponsiveListener?.dispose(); this._ptyResponsiveListener = undefined; if (this._shellLaunchConfig) { - if (this._shellLaunchConfig.isFeatureTerminal) { + if (this._shellLaunchConfig.isFeatureTerminal && !this.reconnectionOwner) { // Indicate the process is exited (and gone forever) only for feature terminals // so they can react to the exit, this is particularly important for tasks so // that it knows that the process is not still active. Note that this is not diff --git a/src/vs/workbench/contrib/terminal/browser/terminalService.ts b/src/vs/workbench/contrib/terminal/browser/terminalService.ts index 7ed18631566ab..f315f11cd3056 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalService.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalService.ts @@ -84,6 +84,12 @@ export class TerminalService implements ITerminalService { return this._terminalGroupService.instances.concat(this._terminalEditorService.instances); } + + private _reconnectedTerminals: Map = new Map(); + getReconnectedTerminals(reconnectionOwner: string): ITerminalInstance[] | undefined { + return this._reconnectedTerminals.get(reconnectionOwner); + } + get defaultLocation(): TerminalLocation { return this.configHelper.config.defaultLocation === TerminalLocationString.Editor ? TerminalLocation.Editor : TerminalLocation.Panel; } private _activeInstance: ITerminalInstance | undefined; @@ -1039,9 +1045,21 @@ export class TerminalService implements ITerminalService { shellLaunchConfig.parentTerminalId = parent.instanceId; instance = group.split(shellLaunchConfig); } + this._addToReconnected(instance); return instance; } + private _addToReconnected(instance: ITerminalInstance): void { + if (instance.reconnectionOwner) { + const reconnectedTerminals = this._reconnectedTerminals.get(instance.reconnectionOwner); + if (reconnectedTerminals) { + reconnectedTerminals.push(instance); + } else { + this._reconnectedTerminals.set(instance.reconnectionOwner, [instance]); + } + } + } + private _createTerminal(shellLaunchConfig: IShellLaunchConfig, location: TerminalLocation, options?: ICreateTerminalOptions): ITerminalInstance { let instance; const editorOptions = this._getEditorOptions(options?.location); @@ -1054,6 +1072,7 @@ export class TerminalService implements ITerminalService { const group = this._terminalGroupService.createGroup(shellLaunchConfig); instance = group.terminalInstances[0]; } + this._addToReconnected(instance); return instance; } From ff0e091de4077979b108ebdf6852ade09805a043 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 14 Jul 2022 05:32:01 -0700 Subject: [PATCH 038/121] xterm@4.20.0-beta.13 Fixes #155035 --- package.json | 6 +++--- remote/package.json | 6 +++--- remote/web/package.json | 4 ++-- remote/web/yarn.lock | 18 +++++++++--------- remote/yarn.lock | 28 ++++++++++++++-------------- yarn.lock | 28 ++++++++++++++-------------- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/package.json b/package.json index 5610e53f7c387..4e425690def36 100644 --- a/package.json +++ b/package.json @@ -85,12 +85,12 @@ "vscode-proxy-agent": "^0.12.0", "vscode-regexpp": "^3.1.0", "vscode-textmate": "7.0.1", - "xterm": "4.20.0-beta.12", + "xterm": "4.20.0-beta.13", "xterm-addon-search": "0.10.0-beta.2", "xterm-addon-serialize": "0.8.0-beta.2", "xterm-addon-unicode11": "0.4.0-beta.3", - "xterm-addon-webgl": "0.13.0-beta.6", - "xterm-headless": "4.20.0-beta.12", + "xterm-addon-webgl": "0.13.0-beta.7", + "xterm-headless": "4.20.0-beta.13", "yauzl": "^2.9.2", "yazl": "^2.4.3" }, diff --git a/remote/package.json b/remote/package.json index c982151596857..10c685468d19c 100644 --- a/remote/package.json +++ b/remote/package.json @@ -24,12 +24,12 @@ "vscode-proxy-agent": "^0.12.0", "vscode-regexpp": "^3.1.0", "vscode-textmate": "7.0.1", - "xterm": "4.20.0-beta.12", + "xterm": "4.20.0-beta.13", "xterm-addon-search": "0.10.0-beta.2", "xterm-addon-serialize": "0.8.0-beta.2", "xterm-addon-unicode11": "0.4.0-beta.3", - "xterm-addon-webgl": "0.13.0-beta.6", - "xterm-headless": "4.20.0-beta.12", + "xterm-addon-webgl": "0.13.0-beta.7", + "xterm-headless": "4.20.0-beta.13", "yauzl": "^2.9.2", "yazl": "^2.4.3" }, diff --git a/remote/web/package.json b/remote/web/package.json index 1b8912dc9e5a7..b44711e8c37d3 100644 --- a/remote/web/package.json +++ b/remote/web/package.json @@ -11,9 +11,9 @@ "tas-client-umd": "0.1.6", "vscode-oniguruma": "1.6.1", "vscode-textmate": "7.0.1", - "xterm": "4.20.0-beta.12", + "xterm": "4.20.0-beta.13", "xterm-addon-search": "0.10.0-beta.2", "xterm-addon-unicode11": "0.4.0-beta.3", - "xterm-addon-webgl": "0.13.0-beta.6" + "xterm-addon-webgl": "0.13.0-beta.7" } } diff --git a/remote/web/yarn.lock b/remote/web/yarn.lock index 419d7ceaeab46..ba1450297488a 100644 --- a/remote/web/yarn.lock +++ b/remote/web/yarn.lock @@ -78,12 +78,12 @@ xterm-addon-unicode11@0.4.0-beta.3: resolved "https://registry.yarnpkg.com/xterm-addon-unicode11/-/xterm-addon-unicode11-0.4.0-beta.3.tgz#f350184155fafd5ad0d6fbf31d13e6ca7dea1efa" integrity sha512-FryZAVwbUjKTmwXnm1trch/2XO60F5JsDvOkZhzobV1hm10sFLVuZpFyHXiUx7TFeeFsvNP+S77LAtWoeT5z+Q== -xterm-addon-webgl@0.13.0-beta.6: - version "0.13.0-beta.6" - resolved "https://registry.yarnpkg.com/xterm-addon-webgl/-/xterm-addon-webgl-0.13.0-beta.6.tgz#44eceb1e15a711159bdf1c2a779422aa11becabc" - integrity sha512-83bo12rqYU04agC6rn+drEui8tarN5Ev66sdu86aGzxM+Ylr8wFqIb/Px/caX9qTqO79TN80ID7EC5P5QyL8XA== - -xterm@4.20.0-beta.12: - version "4.20.0-beta.12" - resolved "https://registry.yarnpkg.com/xterm/-/xterm-4.20.0-beta.12.tgz#02751473b307d6795e6f47abf6798993128a84b7" - integrity sha512-6bqZshNOJsghzQ5f52JIPrZL8MPGW+caQkeQ3aoAPleGvZz775LDQAQH2KzdR9XxOJI5wnJcxx+dk7IjulCsnw== +xterm-addon-webgl@0.13.0-beta.7: + version "0.13.0-beta.7" + resolved "https://registry.yarnpkg.com/xterm-addon-webgl/-/xterm-addon-webgl-0.13.0-beta.7.tgz#9b514fa9792ced755c8321ddd06529f9912db2a1" + integrity sha512-U3sKzkziZRwb13MyNp0eMwt5BWyM938epAv0ZOnI5Vjq06S2naS37GgO/FY+0eu5wuBKkZhT9lNDv7n8rMqd+w== + +xterm@4.20.0-beta.13: + version "4.20.0-beta.13" + resolved "https://registry.yarnpkg.com/xterm/-/xterm-4.20.0-beta.13.tgz#7526e19310daa56a11c26eb81a2706593c1378ec" + integrity sha512-ovXGhvM/qDRNGlGO653WY1pxIZrnI4+ayVM7pCnxO/tRwUIym6LGS3NurYrhGYrXOjoLJZxQ4EjToAfHvAg2Gg== diff --git a/remote/yarn.lock b/remote/yarn.lock index 9d8043ba95087..3076135dad189 100644 --- a/remote/yarn.lock +++ b/remote/yarn.lock @@ -803,20 +803,20 @@ xterm-addon-unicode11@0.4.0-beta.3: resolved "https://registry.yarnpkg.com/xterm-addon-unicode11/-/xterm-addon-unicode11-0.4.0-beta.3.tgz#f350184155fafd5ad0d6fbf31d13e6ca7dea1efa" integrity sha512-FryZAVwbUjKTmwXnm1trch/2XO60F5JsDvOkZhzobV1hm10sFLVuZpFyHXiUx7TFeeFsvNP+S77LAtWoeT5z+Q== -xterm-addon-webgl@0.13.0-beta.6: - version "0.13.0-beta.6" - resolved "https://registry.yarnpkg.com/xterm-addon-webgl/-/xterm-addon-webgl-0.13.0-beta.6.tgz#44eceb1e15a711159bdf1c2a779422aa11becabc" - integrity sha512-83bo12rqYU04agC6rn+drEui8tarN5Ev66sdu86aGzxM+Ylr8wFqIb/Px/caX9qTqO79TN80ID7EC5P5QyL8XA== - -xterm-headless@4.20.0-beta.12: - version "4.20.0-beta.12" - resolved "https://registry.yarnpkg.com/xterm-headless/-/xterm-headless-4.20.0-beta.12.tgz#a8f14127212ef15b1d4e726014daf422d29d06ba" - integrity sha512-MtxrRy1qm/SQl5oTClK30rzip/WELzkGQ837CiOlGLiktj5yA1gK7SA7T532fIPPa9czJ8jBuONvZQJL3M000A== - -xterm@4.20.0-beta.12: - version "4.20.0-beta.12" - resolved "https://registry.yarnpkg.com/xterm/-/xterm-4.20.0-beta.12.tgz#02751473b307d6795e6f47abf6798993128a84b7" - integrity sha512-6bqZshNOJsghzQ5f52JIPrZL8MPGW+caQkeQ3aoAPleGvZz775LDQAQH2KzdR9XxOJI5wnJcxx+dk7IjulCsnw== +xterm-addon-webgl@0.13.0-beta.7: + version "0.13.0-beta.7" + resolved "https://registry.yarnpkg.com/xterm-addon-webgl/-/xterm-addon-webgl-0.13.0-beta.7.tgz#9b514fa9792ced755c8321ddd06529f9912db2a1" + integrity sha512-U3sKzkziZRwb13MyNp0eMwt5BWyM938epAv0ZOnI5Vjq06S2naS37GgO/FY+0eu5wuBKkZhT9lNDv7n8rMqd+w== + +xterm-headless@4.20.0-beta.13: + version "4.20.0-beta.13" + resolved "https://registry.yarnpkg.com/xterm-headless/-/xterm-headless-4.20.0-beta.13.tgz#a7d9d8837e3f78e106006cc94cf63ec13a9fd991" + integrity sha512-y4YI+Ogv2R2I++tsyvx5Q7csAaN7mG2yMMMBb/u4dXnrFmSGYs/R8ZFkeHgAW4Ju4uI3Rizb+ZdwtN1uG043Rw== + +xterm@4.20.0-beta.13: + version "4.20.0-beta.13" + resolved "https://registry.yarnpkg.com/xterm/-/xterm-4.20.0-beta.13.tgz#7526e19310daa56a11c26eb81a2706593c1378ec" + integrity sha512-ovXGhvM/qDRNGlGO653WY1pxIZrnI4+ayVM7pCnxO/tRwUIym6LGS3NurYrhGYrXOjoLJZxQ4EjToAfHvAg2Gg== yallist@^4.0.0: version "4.0.0" diff --git a/yarn.lock b/yarn.lock index 284efbc92f6d3..4ec38e4d90948 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12112,20 +12112,20 @@ xterm-addon-unicode11@0.4.0-beta.3: resolved "https://registry.yarnpkg.com/xterm-addon-unicode11/-/xterm-addon-unicode11-0.4.0-beta.3.tgz#f350184155fafd5ad0d6fbf31d13e6ca7dea1efa" integrity sha512-FryZAVwbUjKTmwXnm1trch/2XO60F5JsDvOkZhzobV1hm10sFLVuZpFyHXiUx7TFeeFsvNP+S77LAtWoeT5z+Q== -xterm-addon-webgl@0.13.0-beta.6: - version "0.13.0-beta.6" - resolved "https://registry.yarnpkg.com/xterm-addon-webgl/-/xterm-addon-webgl-0.13.0-beta.6.tgz#44eceb1e15a711159bdf1c2a779422aa11becabc" - integrity sha512-83bo12rqYU04agC6rn+drEui8tarN5Ev66sdu86aGzxM+Ylr8wFqIb/Px/caX9qTqO79TN80ID7EC5P5QyL8XA== - -xterm-headless@4.20.0-beta.12: - version "4.20.0-beta.12" - resolved "https://registry.yarnpkg.com/xterm-headless/-/xterm-headless-4.20.0-beta.12.tgz#a8f14127212ef15b1d4e726014daf422d29d06ba" - integrity sha512-MtxrRy1qm/SQl5oTClK30rzip/WELzkGQ837CiOlGLiktj5yA1gK7SA7T532fIPPa9czJ8jBuONvZQJL3M000A== - -xterm@4.20.0-beta.12: - version "4.20.0-beta.12" - resolved "https://registry.yarnpkg.com/xterm/-/xterm-4.20.0-beta.12.tgz#02751473b307d6795e6f47abf6798993128a84b7" - integrity sha512-6bqZshNOJsghzQ5f52JIPrZL8MPGW+caQkeQ3aoAPleGvZz775LDQAQH2KzdR9XxOJI5wnJcxx+dk7IjulCsnw== +xterm-addon-webgl@0.13.0-beta.7: + version "0.13.0-beta.7" + resolved "https://registry.yarnpkg.com/xterm-addon-webgl/-/xterm-addon-webgl-0.13.0-beta.7.tgz#9b514fa9792ced755c8321ddd06529f9912db2a1" + integrity sha512-U3sKzkziZRwb13MyNp0eMwt5BWyM938epAv0ZOnI5Vjq06S2naS37GgO/FY+0eu5wuBKkZhT9lNDv7n8rMqd+w== + +xterm-headless@4.20.0-beta.13: + version "4.20.0-beta.13" + resolved "https://registry.yarnpkg.com/xterm-headless/-/xterm-headless-4.20.0-beta.13.tgz#a7d9d8837e3f78e106006cc94cf63ec13a9fd991" + integrity sha512-y4YI+Ogv2R2I++tsyvx5Q7csAaN7mG2yMMMBb/u4dXnrFmSGYs/R8ZFkeHgAW4Ju4uI3Rizb+ZdwtN1uG043Rw== + +xterm@4.20.0-beta.13: + version "4.20.0-beta.13" + resolved "https://registry.yarnpkg.com/xterm/-/xterm-4.20.0-beta.13.tgz#7526e19310daa56a11c26eb81a2706593c1378ec" + integrity sha512-ovXGhvM/qDRNGlGO653WY1pxIZrnI4+ayVM7pCnxO/tRwUIym6LGS3NurYrhGYrXOjoLJZxQ4EjToAfHvAg2Gg== y18n@^3.2.1: version "3.2.2" From 9c1aa833625f548a4983352331ec570ed541255a Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 14 Jul 2022 08:26:56 +0200 Subject: [PATCH 039/121] editors - clarify view state resource (#155136) --- src/vs/workbench/browser/parts/editor/editorWithViewState.ts | 4 +++- .../workbench/contrib/mergeEditor/browser/view/mergeEditor.ts | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/editorWithViewState.ts b/src/vs/workbench/browser/parts/editor/editorWithViewState.ts index b24848b51f9ea..f01bedd8f59e9 100644 --- a/src/vs/workbench/browser/parts/editor/editorWithViewState.ts +++ b/src/vs/workbench/browser/parts/editor/editorWithViewState.ts @@ -208,7 +208,9 @@ export abstract class AbstractEditorWithViewState extends Edit * * @param resource the expected `URI` for the view state. This * should be used as a way to ensure the view state in the - * editor control is matching the resource expected. + * editor control is matching the resource expected, for example + * by comparing with the underlying model (this was a fix for + * https://github.com/microsoft/vscode/issues/40114). */ protected abstract computeEditorViewState(resource: URI): T | undefined; diff --git a/src/vs/workbench/contrib/mergeEditor/browser/view/mergeEditor.ts b/src/vs/workbench/contrib/mergeEditor/browser/view/mergeEditor.ts index abd5efbe468ee..74e3ee14e88e2 100644 --- a/src/vs/workbench/contrib/mergeEditor/browser/view/mergeEditor.ts +++ b/src/vs/workbench/contrib/mergeEditor/browser/view/mergeEditor.ts @@ -452,7 +452,6 @@ export class MergeEditor extends AbstractTextEditor { protected computeEditorViewState(resource: URI): IMergeEditorViewState | undefined { if (!isEqual(this.model?.result.uri, resource)) { - // TODO@bpasero Why not check `input#resource` and don't ask me for "forgein" resources? return undefined; } const result = this.inputResultView.editor.saveViewState(); From c7cb68449af028fa8788093bef8cad0236846799 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 13 Jul 2022 23:27:25 -0700 Subject: [PATCH 040/121] Remove references to finalized drop api (#155128) --- extensions/markdown-language-features/package.json | 1 - extensions/markdown-language-features/tsconfig.json | 1 - 2 files changed, 2 deletions(-) diff --git a/extensions/markdown-language-features/package.json b/extensions/markdown-language-features/package.json index 8cee84a8d74ab..153aa94f98946 100644 --- a/extensions/markdown-language-features/package.json +++ b/extensions/markdown-language-features/package.json @@ -16,7 +16,6 @@ "Programming Languages" ], "enabledApiProposals": [ - "textEditorDrop", "documentPaste" ], "activationEvents": [ diff --git a/extensions/markdown-language-features/tsconfig.json b/extensions/markdown-language-features/tsconfig.json index 5b2636221ffa6..75edc8fdacfae 100644 --- a/extensions/markdown-language-features/tsconfig.json +++ b/extensions/markdown-language-features/tsconfig.json @@ -6,7 +6,6 @@ "include": [ "src/**/*", "../../src/vscode-dts/vscode.d.ts", - "../../src/vscode-dts/vscode.proposed.textEditorDrop.d.ts", "../../src/vscode-dts/vscode.proposed.documentPaste.d.ts" ] } From fe39d5e3a941517e261a4f2a17ace22cdda6ab1a Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 14 Jul 2022 08:30:08 +0200 Subject: [PATCH 041/121] Forking from the extension host fails when running tests (fix #154549) (#155139) --- src/vs/base/node/ps.ts | 2 +- .../platform/extensions/electron-main/extensionHostStarter.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vs/base/node/ps.ts b/src/vs/base/node/ps.ts index 38cd56f7d75b7..8498145bed291 100644 --- a/src/vs/base/node/ps.ts +++ b/src/vs/base/node/ps.ts @@ -52,7 +52,7 @@ export function listProcesses(rootPid: number): Promise { const ISSUE_REPORTER_HINT = /--vscode-window-kind=issue-reporter/; const PROCESS_EXPLORER_HINT = /--vscode-window-kind=process-explorer/; const UTILITY_NETWORK_HINT = /--utility-sub-type=network/; - const UTILITY_EXTENSION_HOST_HINT = /--vscode-utility-kind=extension-host/; + const UTILITY_EXTENSION_HOST_HINT = /--utility-sub-type=node.mojom.NodeService/; const WINDOWS_CRASH_REPORTER = /--crashes-directory/; const WINDOWS_PTY = /\\pipe\\winpty-control/; const WINDOWS_CONSOLE_HOST = /conhost\.exe/; diff --git a/src/vs/platform/extensions/electron-main/extensionHostStarter.ts b/src/vs/platform/extensions/electron-main/extensionHostStarter.ts index 832a28daaa03e..ca52229c32009 100644 --- a/src/vs/platform/extensions/electron-main/extensionHostStarter.ts +++ b/src/vs/platform/extensions/electron-main/extensionHostStarter.ts @@ -324,7 +324,6 @@ class UtilityExtensionHostProcess extends Disposable { const modulePath = FileAccess.asFileUri('bootstrap-fork.js', require).fsPath; const args: string[] = ['--type=extensionHost', '--skipWorkspaceStorageLock']; const execArgv: string[] = opts.execArgv || []; - execArgv.push(`--vscode-utility-kind=extension-host`); const env: { [key: string]: any } = { ...opts.env }; // Make sure all values are strings, otherwise the process will not start From 16fa042bbc753dc999111fde62f12cc5960211db Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 13 Jul 2022 23:32:27 -0700 Subject: [PATCH 042/121] Move MD references, rename, and definition support to md LS (#155127) --- .../markdown-language-features/package.json | 3 +- .../server/.vscode/launch.json | 2 +- .../server/package.json | 2 +- .../server/src/config.ts | 24 + .../server/src/protocol.ts | 9 +- .../server/src/server.ts | 114 ++- .../server/src/util/file.ts | 21 +- .../server/src/workspace.ts | 8 +- .../server/yarn.lock | 8 +- .../markdown-language-features/src/client.ts | 6 +- .../src/extension.browser.ts | 12 +- .../src/extension.shared.ts | 14 +- .../src/extension.ts | 12 +- .../src/languageFeatures/definitions.ts | 27 - .../src/languageFeatures/fileReferences.ts | 14 +- .../src/languageFeatures/references.ts | 24 - .../src/languageFeatures/rename.ts | 281 ------- .../src/protocol.ts | 18 + .../src/test/definitionProvider.test.ts | 144 ---- .../src/test/fileReferences.test.ts | 120 --- .../src/test/references.test.ts | 635 --------------- .../src/test/rename.test.ts | 720 ------------------ .../markdown-language-features/yarn.lock | 5 + 23 files changed, 194 insertions(+), 2029 deletions(-) create mode 100644 extensions/markdown-language-features/server/src/config.ts delete mode 100644 extensions/markdown-language-features/src/languageFeatures/definitions.ts delete mode 100644 extensions/markdown-language-features/src/languageFeatures/rename.ts create mode 100644 extensions/markdown-language-features/src/protocol.ts delete mode 100644 extensions/markdown-language-features/src/test/definitionProvider.test.ts delete mode 100644 extensions/markdown-language-features/src/test/fileReferences.test.ts delete mode 100644 extensions/markdown-language-features/src/test/references.test.ts delete mode 100644 extensions/markdown-language-features/src/test/rename.test.ts diff --git a/extensions/markdown-language-features/package.json b/extensions/markdown-language-features/package.json index 153aa94f98946..0b5d9f8358e8a 100644 --- a/extensions/markdown-language-features/package.json +++ b/extensions/markdown-language-features/package.json @@ -562,7 +562,8 @@ "@types/picomatch": "^2.3.0", "@types/vscode-notebook-renderer": "^1.60.0", "@types/vscode-webview": "^1.57.0", - "lodash.throttle": "^4.1.1" + "lodash.throttle": "^4.1.1", + "vscode-languageserver-types": "^3.17.2" }, "repository": { "type": "git", diff --git a/extensions/markdown-language-features/server/.vscode/launch.json b/extensions/markdown-language-features/server/.vscode/launch.json index 1ea07e048c8c7..a28c18b697364 100644 --- a/extensions/markdown-language-features/server/.vscode/launch.json +++ b/extensions/markdown-language-features/server/.vscode/launch.json @@ -6,7 +6,7 @@ "name": "Attach", "type": "node", "request": "attach", - "port": 7675, + "port": 7692, "sourceMaps": true, "outFiles": ["${workspaceFolder}/out/**/*.js"] } diff --git a/extensions/markdown-language-features/server/package.json b/extensions/markdown-language-features/server/package.json index a71c09195ff62..9543321edab22 100644 --- a/extensions/markdown-language-features/server/package.json +++ b/extensions/markdown-language-features/server/package.json @@ -13,7 +13,7 @@ "vscode-languageserver": "^8.0.2-next.5`", "vscode-languageserver-textdocument": "^1.0.5", "vscode-languageserver-types": "^3.17.1", - "vscode-markdown-languageservice": "^0.0.0-alpha.5", + "vscode-markdown-languageservice": "^0.0.0-alpha.8", "vscode-uri": "^3.0.3" }, "devDependencies": { diff --git a/extensions/markdown-language-features/server/src/config.ts b/extensions/markdown-language-features/server/src/config.ts new file mode 100644 index 0000000000000..8fb952bb9438c --- /dev/null +++ b/extensions/markdown-language-features/server/src/config.ts @@ -0,0 +1,24 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +export interface LsConfiguration { + /** + * List of file extensions should be considered as markdown. + * + * These should not include the leading `.`. + */ + readonly markdownFileExtensions: readonly string[]; +} + +const defaultConfig: LsConfiguration = { + markdownFileExtensions: ['md'], +}; + +export function getLsConfiguration(overrides: Partial): LsConfiguration { + return { + ...defaultConfig, + ...overrides, + }; +} diff --git a/extensions/markdown-language-features/server/src/protocol.ts b/extensions/markdown-language-features/server/src/protocol.ts index 5670228ba302a..206e0fbe8c7f8 100644 --- a/extensions/markdown-language-features/server/src/protocol.ts +++ b/extensions/markdown-language-features/server/src/protocol.ts @@ -5,13 +5,14 @@ import { RequestType } from 'vscode-languageserver'; import * as md from 'vscode-markdown-languageservice'; +import * as lsp from 'vscode-languageserver-types'; +// From server export const parseRequestType: RequestType<{ uri: string }, md.Token[], any> = new RequestType('markdown/parse'); - export const readFileRequestType: RequestType<{ uri: string }, number[], any> = new RequestType('markdown/readFile'); - export const statFileRequestType: RequestType<{ uri: string }, md.FileStat | undefined, any> = new RequestType('markdown/statFile'); - export const readDirectoryRequestType: RequestType<{ uri: string }, [string, md.FileStat][], any> = new RequestType('markdown/readDirectory'); - export const findFilesRequestTypes: RequestType<{}, string[], any> = new RequestType('markdown/findFiles'); + +// To server +export const getReferencesToFileInWorkspace = new RequestType<{ uri: string }, lsp.Location[], any>('markdown/getReferencesToFileInWorkspace'); diff --git a/extensions/markdown-language-features/server/src/server.ts b/extensions/markdown-language-features/server/src/server.ts index 043bc435aedae..b58917125334e 100644 --- a/extensions/markdown-language-features/server/src/server.ts +++ b/extensions/markdown-language-features/server/src/server.ts @@ -3,13 +3,14 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Connection, InitializeParams, InitializeResult, NotebookDocuments, TextDocuments } from 'vscode-languageserver'; +import { CancellationToken, Connection, InitializeParams, InitializeResult, NotebookDocuments, TextDocuments } from 'vscode-languageserver'; import { TextDocument } from 'vscode-languageserver-textdocument'; import * as lsp from 'vscode-languageserver-types'; import * as md from 'vscode-markdown-languageservice'; import { URI } from 'vscode-uri'; +import { getLsConfiguration } from './config'; import { LogFunctionLogger } from './logging'; -import { parseRequestType } from './protocol'; +import * as protocol from './protocol'; import { VsCodeClientWorkspace } from './workspace'; export async function startServer(connection: Connection) { @@ -17,13 +18,36 @@ export async function startServer(connection: Connection) { const notebooks = new NotebookDocuments(documents); connection.onInitialize((params: InitializeParams): InitializeResult => { + const parser = new class implements md.IMdParser { + slugifier = md.githubSlugifier; + + async tokenize(document: md.ITextDocument): Promise { + return await connection.sendRequest(protocol.parseRequestType, { uri: document.uri.toString() }); + } + }; + + const config = getLsConfiguration({ + markdownFileExtensions: params.initializationOptions.markdownFileExtensions, + }); + + const workspace = new VsCodeClientWorkspace(connection, config, documents, notebooks); + const logger = new LogFunctionLogger(connection.console.log.bind(connection.console)); + provider = md.createLanguageService({ + workspace, + parser, + logger, + markdownFileExtensions: config.markdownFileExtensions, + }); + workspace.workspaceFolders = (params.workspaceFolders ?? []).map(x => URI.parse(x.uri)); return { capabilities: { + completionProvider: { triggerCharacters: ['.', '/', '#'] }, + definitionProvider: true, documentLinkProvider: { resolveProvider: true }, documentSymbolProvider: true, - completionProvider: { triggerCharacters: ['.', '/', '#'] }, foldingRangeProvider: true, + renameProvider: { prepareProvider: true, }, selectionRangeProvider: true, workspaceSymbolProvider: true, workspace: { @@ -36,23 +60,14 @@ export async function startServer(connection: Connection) { }; }); - const parser = new class implements md.IMdParser { - slugifier = md.githubSlugifier; - - async tokenize(document: md.ITextDocument): Promise { - return await connection.sendRequest(parseRequestType, { uri: document.uri.toString() }); - } - }; - const workspace = new VsCodeClientWorkspace(connection, documents, notebooks); - const logger = new LogFunctionLogger(connection.console.log.bind(connection.console)); - const provider = md.createLanguageService({ workspace, parser, logger }); + let provider: md.IMdLanguageService | undefined; connection.onDocumentLinks(async (params, token): Promise => { try { const document = documents.get(params.textDocument.uri); if (document) { - return await provider.getDocumentLinks(document, token); + return await provider!.getDocumentLinks(document, token); } } catch (e) { console.error(e.stack); @@ -62,7 +77,7 @@ export async function startServer(connection: Connection) { connection.onDocumentLinkResolve(async (link, token): Promise => { try { - return await provider.resolveDocumentLink(link, token); + return await provider!.resolveDocumentLink(link, token); } catch (e) { console.error(e.stack); } @@ -73,7 +88,7 @@ export async function startServer(connection: Connection) { try { const document = documents.get(params.textDocument.uri); if (document) { - return await provider.getDocumentSymbols(document, token); + return await provider!.getDocumentSymbols(document, token); } } catch (e) { console.error(e.stack); @@ -85,7 +100,7 @@ export async function startServer(connection: Connection) { try { const document = documents.get(params.textDocument.uri); if (document) { - return await provider.getFoldingRanges(document, token); + return await provider!.getFoldingRanges(document, token); } } catch (e) { console.error(e.stack); @@ -97,7 +112,7 @@ export async function startServer(connection: Connection) { try { const document = documents.get(params.textDocument.uri); if (document) { - return await provider.getSelectionRanges(document, params.positions, token); + return await provider!.getSelectionRanges(document, params.positions, token); } } catch (e) { console.error(e.stack); @@ -107,7 +122,7 @@ export async function startServer(connection: Connection) { connection.onWorkspaceSymbol(async (params, token): Promise => { try { - return await provider.getWorkspaceSymbols(params.query, token); + return await provider!.getWorkspaceSymbols(params.query, token); } catch (e) { console.error(e.stack); } @@ -118,7 +133,19 @@ export async function startServer(connection: Connection) { try { const document = documents.get(params.textDocument.uri); if (document) { - return await provider.getCompletionItems(document, params.position, params.context!, token); + return await provider!.getCompletionItems(document, params.position, params.context!, token); + } + } catch (e) { + console.error(e.stack); + } + return []; + }); + + connection.onReferences(async (params, token): Promise => { + try { + const document = documents.get(params.textDocument.uri); + if (document) { + return await provider!.getReferences(document, params.position, params.context, token); } } catch (e) { console.error(e.stack); @@ -126,6 +153,53 @@ export async function startServer(connection: Connection) { return []; }); + connection.onDefinition(async (params, token): Promise => { + try { + const document = documents.get(params.textDocument.uri); + if (document) { + return await provider!.getDefinition(document, params.position, token); + } + } catch (e) { + console.error(e.stack); + } + return undefined; + }); + + connection.onPrepareRename(async (params, token) => { + try { + const document = documents.get(params.textDocument.uri); + if (document) { + return await provider!.prepareRename(document, params.position, token); + } + } catch (e) { + console.error(e.stack); + } + return undefined; + }); + + connection.onRenameRequest(async (params, token) => { + try { + const document = documents.get(params.textDocument.uri); + if (document) { + const edit = await provider!.getRenameEdit(document, params.position, params.newName, token); + console.log(JSON.stringify(edit)); + return edit; + } + } catch (e) { + console.error(e.stack); + } + return undefined; + }); + + connection.onRequest(protocol.getReferencesToFileInWorkspace, (async (params: { uri: string }, token: CancellationToken) => { + try { + return await provider!.getFileReferences(URI.parse(params.uri), token); + } catch (e) { + console.error(e.stack); + } + return undefined; + })); + documents.listen(connection); notebooks.listen(connection); connection.listen(); diff --git a/extensions/markdown-language-features/server/src/util/file.ts b/extensions/markdown-language-features/server/src/util/file.ts index 45b072a82dcbb..b8d1286a42c1e 100644 --- a/extensions/markdown-language-features/server/src/util/file.ts +++ b/extensions/markdown-language-features/server/src/util/file.ts @@ -4,24 +4,13 @@ *--------------------------------------------------------------------------------------------*/ import { TextDocument } from 'vscode-languageserver-textdocument'; -import * as URI from 'vscode-uri'; +import { URI, Utils } from 'vscode-uri'; +import { LsConfiguration } from '../config'; -const markdownFileExtensions = Object.freeze([ - '.md', - '.mkd', - '.mdwn', - '.mdown', - '.markdown', - '.markdn', - '.mdtxt', - '.mdtext', - '.workbook', -]); - -export function looksLikeMarkdownPath(resolvedHrefPath: URI.URI) { - return markdownFileExtensions.includes(URI.Utils.extname(URI.URI.from(resolvedHrefPath)).toLowerCase()); +export function looksLikeMarkdownPath(config: LsConfiguration, resolvedHrefPath: URI) { + return config.markdownFileExtensions.includes(Utils.extname(URI.from(resolvedHrefPath)).toLowerCase().replace('.', '')); } -export function isMarkdownDocument(document: TextDocument): boolean { +export function isMarkdownFile(document: TextDocument) { return document.languageId === 'markdown'; } diff --git a/extensions/markdown-language-features/server/src/workspace.ts b/extensions/markdown-language-features/server/src/workspace.ts index c52d696b429a1..7838c20f32895 100644 --- a/extensions/markdown-language-features/server/src/workspace.ts +++ b/extensions/markdown-language-features/server/src/workspace.ts @@ -8,9 +8,10 @@ import { TextDocument } from 'vscode-languageserver-textdocument'; import * as md from 'vscode-markdown-languageservice'; import { ContainingDocumentContext } from 'vscode-markdown-languageservice/out/workspace'; import { URI } from 'vscode-uri'; +import { LsConfiguration } from './config'; import * as protocol from './protocol'; import { coalesce } from './util/arrays'; -import { isMarkdownDocument, looksLikeMarkdownPath } from './util/file'; +import { isMarkdownFile, looksLikeMarkdownPath } from './util/file'; import { Limiter } from './util/limiter'; import { ResourceMap } from './util/resourceMap'; import { Schemes } from './util/schemes'; @@ -34,6 +35,7 @@ export class VsCodeClientWorkspace implements md.IWorkspace { constructor( private readonly connection: Connection, + private readonly config: LsConfiguration, private readonly documents: TextDocuments, private readonly notebooks: NotebookDocuments, ) { @@ -141,7 +143,7 @@ export class VsCodeClientWorkspace implements md.IWorkspace { return matchingDocument; } - if (!looksLikeMarkdownPath(resource)) { + if (!looksLikeMarkdownPath(this.config, resource)) { return undefined; } @@ -182,6 +184,6 @@ export class VsCodeClientWorkspace implements md.IWorkspace { } private isRelevantMarkdownDocument(doc: TextDocument) { - return isMarkdownDocument(doc) && URI.parse(doc.uri).scheme !== 'vscode-bulkeditpreview'; + return isMarkdownFile(doc) && URI.parse(doc.uri).scheme !== 'vscode-bulkeditpreview'; } } diff --git a/extensions/markdown-language-features/server/yarn.lock b/extensions/markdown-language-features/server/yarn.lock index 2dea8ce7b5b5b..e930ffa60edbb 100644 --- a/extensions/markdown-language-features/server/yarn.lock +++ b/extensions/markdown-language-features/server/yarn.lock @@ -42,10 +42,10 @@ vscode-languageserver@^8.0.2-next.5`: dependencies: vscode-languageserver-protocol "3.17.2-next.6" -vscode-markdown-languageservice@^0.0.0-alpha.5: - version "0.0.0-alpha.5" - resolved "https://registry.yarnpkg.com/vscode-markdown-languageservice/-/vscode-markdown-languageservice-0.0.0-alpha.5.tgz#fb3042f3ee79589606154c19b15565541337bceb" - integrity sha512-vy8UVa1jtm3CwkifRn3fEWM710JC4AYEECNd5KQthSCoFSfT5pOshJNFWs5yzBeVrohiy4deOdhSrfbDMg/Hyg== +vscode-markdown-languageservice@^0.0.0-alpha.8: + version "0.0.0-alpha.8" + resolved "https://registry.yarnpkg.com/vscode-markdown-languageservice/-/vscode-markdown-languageservice-0.0.0-alpha.8.tgz#05d4f86cf0514fd71479847eef742fcc8cdbe87f" + integrity sha512-si8weZsY4LtyonyZwxpFYk8WucRFiKJisErNTt1HDjUCglSDIZqsMNuMIcz3t0nVNfG0LrpdMFVLGhmET5D71Q== dependencies: vscode-languageserver-textdocument "^1.0.5" vscode-languageserver-types "^3.17.1" diff --git a/extensions/markdown-language-features/src/client.ts b/extensions/markdown-language-features/src/client.ts index 551274bc201e1..96b43406961c6 100644 --- a/extensions/markdown-language-features/src/client.ts +++ b/extensions/markdown-language-features/src/client.ts @@ -24,15 +24,17 @@ export type LanguageClientConstructor = (name: string, description: string, clie export async function startClient(factory: LanguageClientConstructor, workspace: IMdWorkspace, parser: IMdParser): Promise { - const documentSelector = ['markdown']; const mdFileGlob = `**/*.{${markdownFileExtensions.join(',')}}`; const clientOptions: LanguageClientOptions = { - documentSelector, + documentSelector: [{ language: 'markdown' }], synchronize: { configurationSection: ['markdown'], fileEvents: vscode.workspace.createFileSystemWatcher(mdFileGlob), }, + initializationOptions: { + markdownFileExtensions, + } }; const client = factory('markdown', localize('markdownServer.name', 'Markdown Language Server'), clientOptions); diff --git a/extensions/markdown-language-features/src/extension.browser.ts b/extensions/markdown-language-features/src/extension.browser.ts index 717d1c5ccc903..d582a33606b69 100644 --- a/extensions/markdown-language-features/src/extension.browser.ts +++ b/extensions/markdown-language-features/src/extension.browser.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; -import { LanguageClient, LanguageClientOptions } from 'vscode-languageclient/browser'; +import { BaseLanguageClient, LanguageClient, LanguageClientOptions } from 'vscode-languageclient/browser'; import { startClient } from './client'; import { activateShared } from './extension.shared'; import { VsCodeOutputLogger } from './logging'; @@ -13,7 +13,7 @@ import { getMarkdownExtensionContributions } from './markdownExtensions'; import { githubSlugifier } from './slugify'; import { IMdWorkspace, VsCodeMdWorkspace } from './workspace'; -export function activate(context: vscode.ExtensionContext) { +export async function activate(context: vscode.ExtensionContext) { const contributions = getMarkdownExtensionContributions(context); context.subscriptions.push(contributions); @@ -25,15 +25,15 @@ export function activate(context: vscode.ExtensionContext) { const workspace = new VsCodeMdWorkspace(); context.subscriptions.push(workspace); - activateShared(context, workspace, engine, logger, contributions); - startServer(context, workspace, engine); + const client = await startServer(context, workspace, engine); + activateShared(context, client, workspace, engine, logger, contributions); } -async function startServer(context: vscode.ExtensionContext, workspace: IMdWorkspace, parser: IMdParser): Promise { +function startServer(context: vscode.ExtensionContext, workspace: IMdWorkspace, parser: IMdParser): Promise { const serverMain = vscode.Uri.joinPath(context.extensionUri, 'server/dist/browser/main.js'); const worker = new Worker(serverMain.toString()); - await startClient((id: string, name: string, clientOptions: LanguageClientOptions) => { + return startClient((id: string, name: string, clientOptions: LanguageClientOptions) => { return new LanguageClient(id, name, clientOptions, worker); }, workspace, parser); } diff --git a/extensions/markdown-language-features/src/extension.shared.ts b/extensions/markdown-language-features/src/extension.shared.ts index 8d16f394e4a8f..e3a2e2bd253b2 100644 --- a/extensions/markdown-language-features/src/extension.shared.ts +++ b/extensions/markdown-language-features/src/extension.shared.ts @@ -4,16 +4,15 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; +import { BaseLanguageClient } from 'vscode-languageclient'; import { CommandManager } from './commandManager'; import * as commands from './commands/index'; import { registerPasteSupport } from './languageFeatures/copyPaste'; -import { registerDefinitionSupport } from './languageFeatures/definitions'; import { registerDiagnosticSupport } from './languageFeatures/diagnostics'; import { MdLinkProvider } from './languageFeatures/documentLinks'; import { registerDropIntoEditorSupport } from './languageFeatures/dropIntoEditor'; import { registerFindFileReferenceSupport } from './languageFeatures/fileReferences'; -import { MdReferencesProvider, registerReferencesSupport } from './languageFeatures/references'; -import { registerRenameSupport } from './languageFeatures/rename'; +import { MdReferencesProvider } from './languageFeatures/references'; import { ILogger } from './logging'; import { IMdParser, MarkdownItEngine, MdParsingProvider } from './markdownEngine'; import { MarkdownContributionProvider } from './markdownExtensions'; @@ -26,6 +25,7 @@ import { IMdWorkspace } from './workspace'; export function activateShared( context: vscode.ExtensionContext, + client: BaseLanguageClient, workspace: IMdWorkspace, engine: MarkdownItEngine, logger: ILogger, @@ -45,7 +45,7 @@ export function activateShared( const previewManager = new MarkdownPreviewManager(contentProvider, workspace, logger, contributions, tocProvider); context.subscriptions.push(previewManager); - context.subscriptions.push(registerMarkdownLanguageFeatures(parser, workspace, commandManager, tocProvider, logger)); + context.subscriptions.push(registerMarkdownLanguageFeatures(client, parser, workspace, commandManager, tocProvider, logger)); context.subscriptions.push(registerMarkdownCommands(commandManager, previewManager, telemetryReporter, cspArbiter, engine, tocProvider)); context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(() => { @@ -54,6 +54,7 @@ export function activateShared( } function registerMarkdownLanguageFeatures( + client: BaseLanguageClient, parser: IMdParser, workspace: IMdWorkspace, commandManager: CommandManager, @@ -70,13 +71,10 @@ function registerMarkdownLanguageFeatures( referencesProvider, // Language features - registerDefinitionSupport(selector, referencesProvider), registerDiagnosticSupport(selector, workspace, linkProvider, commandManager, referencesProvider, tocProvider, logger), registerDropIntoEditorSupport(selector), - registerFindFileReferenceSupport(commandManager, referencesProvider), + registerFindFileReferenceSupport(commandManager, client), registerPasteSupport(selector), - registerReferencesSupport(selector, referencesProvider), - registerRenameSupport(selector, workspace, referencesProvider, parser.slugifier), ); } diff --git a/extensions/markdown-language-features/src/extension.ts b/extensions/markdown-language-features/src/extension.ts index 45dba90d3ca2a..ff591b3bd2f3d 100644 --- a/extensions/markdown-language-features/src/extension.ts +++ b/extensions/markdown-language-features/src/extension.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; -import { LanguageClient, ServerOptions, TransportKind } from 'vscode-languageclient/node'; +import { BaseLanguageClient, LanguageClient, ServerOptions, TransportKind } from 'vscode-languageclient/node'; import { startClient } from './client'; import { activateShared } from './extension.shared'; import { VsCodeOutputLogger } from './logging'; @@ -13,7 +13,7 @@ import { getMarkdownExtensionContributions } from './markdownExtensions'; import { githubSlugifier } from './slugify'; import { IMdWorkspace, VsCodeMdWorkspace } from './workspace'; -export function activate(context: vscode.ExtensionContext) { +export async function activate(context: vscode.ExtensionContext) { const contributions = getMarkdownExtensionContributions(context); context.subscriptions.push(contributions); @@ -25,11 +25,11 @@ export function activate(context: vscode.ExtensionContext) { const workspace = new VsCodeMdWorkspace(); context.subscriptions.push(workspace); - activateShared(context, workspace, engine, logger, contributions); - startServer(context, workspace, engine); + const client = await startServer(context, workspace, engine); + activateShared(context, client, workspace, engine, logger, contributions); } -async function startServer(context: vscode.ExtensionContext, workspace: IMdWorkspace, parser: IMdParser): Promise { +function startServer(context: vscode.ExtensionContext, workspace: IMdWorkspace, parser: IMdParser): Promise { const clientMain = vscode.extensions.getExtension('vscode.markdown-language-features')?.packageJSON?.main || ''; const serverMain = `./server/${clientMain.indexOf('/dist/') !== -1 ? 'dist' : 'out'}/node/main`; @@ -44,7 +44,7 @@ async function startServer(context: vscode.ExtensionContext, workspace: IMdWorks run: { module: serverModule, transport: TransportKind.ipc }, debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions } }; - await startClient((id, name, clientOptions) => { + return startClient((id, name, clientOptions) => { return new LanguageClient(id, name, serverOptions, clientOptions); }, workspace, parser); } diff --git a/extensions/markdown-language-features/src/languageFeatures/definitions.ts b/extensions/markdown-language-features/src/languageFeatures/definitions.ts deleted file mode 100644 index d080dcaab1a8c..0000000000000 --- a/extensions/markdown-language-features/src/languageFeatures/definitions.ts +++ /dev/null @@ -1,27 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -import * as vscode from 'vscode'; -import { ITextDocument } from '../types/textDocument'; -import { MdReferencesProvider } from './references'; - -export class MdVsCodeDefinitionProvider implements vscode.DefinitionProvider { - - constructor( - private readonly referencesProvider: MdReferencesProvider, - ) { } - - async provideDefinition(document: ITextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise { - const allRefs = await this.referencesProvider.getReferencesAtPosition(document, position, token); - - return allRefs.find(ref => ref.kind === 'link' && ref.isDefinition)?.location; - } -} - -export function registerDefinitionSupport( - selector: vscode.DocumentSelector, - referencesProvider: MdReferencesProvider, -): vscode.Disposable { - return vscode.languages.registerDefinitionProvider(selector, new MdVsCodeDefinitionProvider(referencesProvider)); -} diff --git a/extensions/markdown-language-features/src/languageFeatures/fileReferences.ts b/extensions/markdown-language-features/src/languageFeatures/fileReferences.ts index 4eea510d8124f..7c6338ede98a1 100644 --- a/extensions/markdown-language-features/src/languageFeatures/fileReferences.ts +++ b/extensions/markdown-language-features/src/languageFeatures/fileReferences.ts @@ -4,9 +4,10 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; +import { BaseLanguageClient } from 'vscode-languageclient'; import * as nls from 'vscode-nls'; import { Command, CommandManager } from '../commandManager'; -import { MdReferencesProvider } from './references'; +import { getReferencesToFileInWorkspace } from '../protocol'; const localize = nls.loadMessageBundle(); @@ -16,7 +17,7 @@ export class FindFileReferencesCommand implements Command { public readonly id = 'markdown.findAllFileReferences'; constructor( - private readonly referencesProvider: MdReferencesProvider, + private readonly client: BaseLanguageClient, ) { } public async execute(resource?: vscode.Uri) { @@ -33,8 +34,9 @@ export class FindFileReferencesCommand implements Command { location: vscode.ProgressLocation.Window, title: localize('progress.title', "Finding file references") }, async (_progress, token) => { - const references = await this.referencesProvider.getReferencesToFileInWorkspace(resource!, token); - const locations = references.map(ref => ref.location); + const locations = (await this.client.sendRequest(getReferencesToFileInWorkspace, { uri: resource!.toString() }, token)).map(loc => { + return new vscode.Location(vscode.Uri.parse(loc.uri), new vscode.Range(loc.range.start.line, loc.range.start.character, loc.range.end.line, loc.range.end.character)); + }); const config = vscode.workspace.getConfiguration('references'); const existingSetting = config.inspect('preferredLocation'); @@ -51,7 +53,7 @@ export class FindFileReferencesCommand implements Command { export function registerFindFileReferenceSupport( commandManager: CommandManager, - referencesProvider: MdReferencesProvider + client: BaseLanguageClient, ): vscode.Disposable { - return commandManager.register(new FindFileReferencesCommand(referencesProvider)); + return commandManager.register(new FindFileReferencesCommand(client)); } diff --git a/extensions/markdown-language-features/src/languageFeatures/references.ts b/extensions/markdown-language-features/src/languageFeatures/references.ts index 51b7e7b92a1e3..5aada05300e05 100644 --- a/extensions/markdown-language-features/src/languageFeatures/references.ts +++ b/extensions/markdown-language-features/src/languageFeatures/references.ts @@ -312,30 +312,6 @@ export class MdReferencesProvider extends Disposable { } } -/** - * Implements {@link vscode.ReferenceProvider} for markdown documents. - */ -export class MdVsCodeReferencesProvider implements vscode.ReferenceProvider { - - public constructor( - private readonly referencesProvider: MdReferencesProvider - ) { } - - async provideReferences(document: ITextDocument, position: vscode.Position, context: vscode.ReferenceContext, token: vscode.CancellationToken): Promise { - const allRefs = await this.referencesProvider.getReferencesAtPosition(document, position, token); - return allRefs - .filter(ref => context.includeDeclaration || !ref.isDefinition) - .map(ref => ref.location); - } -} - -export function registerReferencesSupport( - selector: vscode.DocumentSelector, - referencesProvider: MdReferencesProvider, -): vscode.Disposable { - return vscode.languages.registerReferenceProvider(selector, new MdVsCodeReferencesProvider(referencesProvider)); -} - export async function tryResolveLinkPath(originalUri: vscode.Uri, workspace: IMdWorkspace): Promise { if (await workspace.pathExists(originalUri)) { return originalUri; diff --git a/extensions/markdown-language-features/src/languageFeatures/rename.ts b/extensions/markdown-language-features/src/languageFeatures/rename.ts deleted file mode 100644 index 44870e33ff1ca..0000000000000 --- a/extensions/markdown-language-features/src/languageFeatures/rename.ts +++ /dev/null @@ -1,281 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -import * as path from 'path'; -import * as vscode from 'vscode'; -import * as nls from 'vscode-nls'; -import * as URI from 'vscode-uri'; -import { Slugifier } from '../slugify'; -import { ITextDocument } from '../types/textDocument'; -import { Disposable } from '../util/dispose'; -import { resolveDocumentLink } from '../util/openDocumentLink'; -import { IMdWorkspace } from '../workspace'; -import { InternalHref } from './documentLinks'; -import { MdHeaderReference, MdLinkReference, MdReference, MdReferencesProvider, tryResolveLinkPath } from './references'; - -const localize = nls.loadMessageBundle(); - - -export interface MdReferencesResponse { - references: MdReference[]; - triggerRef: MdReference; -} - -interface MdFileRenameEdit { - readonly from: vscode.Uri; - readonly to: vscode.Uri; -} - -/** - * Type with additional metadata about the edits for testing - * - * This is needed since `vscode.WorkspaceEdit` does not expose info on file renames. - */ -export interface MdWorkspaceEdit { - readonly edit: vscode.WorkspaceEdit; - - readonly fileRenames?: ReadonlyArray; -} - -function tryDecodeUri(str: string): string { - try { - return decodeURI(str); - } catch { - return str; - } -} - -export class MdVsCodeRenameProvider extends Disposable implements vscode.RenameProvider { - - private cachedRefs?: { - readonly resource: vscode.Uri; - readonly version: number; - readonly position: vscode.Position; - readonly triggerRef: MdReference; - readonly references: MdReference[]; - } | undefined; - - private readonly renameNotSupportedText = localize('invalidRenameLocation', "Rename not supported at location"); - - public constructor( - private readonly workspace: IMdWorkspace, - private readonly referencesProvider: MdReferencesProvider, - private readonly slugifier: Slugifier, - ) { - super(); - } - - public async prepareRename(document: ITextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise { - const allRefsInfo = await this.getAllReferences(document, position, token); - if (token.isCancellationRequested) { - return undefined; - } - - if (!allRefsInfo || !allRefsInfo.references.length) { - throw new Error(this.renameNotSupportedText); - } - - const triggerRef = allRefsInfo.triggerRef; - switch (triggerRef.kind) { - case 'header': { - return { range: triggerRef.headerTextLocation.range, placeholder: triggerRef.headerText }; - } - case 'link': { - if (triggerRef.link.kind === 'definition') { - // We may have been triggered on the ref or the definition itself - if (triggerRef.link.ref.range.contains(position)) { - return { range: triggerRef.link.ref.range, placeholder: triggerRef.link.ref.text }; - } - } - - if (triggerRef.link.href.kind === 'external') { - return { range: triggerRef.link.source.hrefRange, placeholder: document.getText(triggerRef.link.source.hrefRange) }; - } - - // See if we are renaming the fragment or the path - const { fragmentRange } = triggerRef.link.source; - if (fragmentRange?.contains(position)) { - const declaration = this.findHeaderDeclaration(allRefsInfo.references); - if (declaration) { - return { range: fragmentRange, placeholder: declaration.headerText }; - } - return { range: fragmentRange, placeholder: document.getText(fragmentRange) }; - } - - const range = this.getFilePathRange(triggerRef); - if (!range) { - throw new Error(this.renameNotSupportedText); - } - return { range, placeholder: tryDecodeUri(document.getText(range)) }; - } - } - } - - private getFilePathRange(ref: MdLinkReference): vscode.Range { - if (ref.link.source.fragmentRange) { - return ref.link.source.hrefRange.with(undefined, ref.link.source.fragmentRange.start.translate(0, -1)); - } - return ref.link.source.hrefRange; - } - - private findHeaderDeclaration(references: readonly MdReference[]): MdHeaderReference | undefined { - return references.find(ref => ref.isDefinition && ref.kind === 'header') as MdHeaderReference | undefined; - } - - public async provideRenameEdits(document: ITextDocument, position: vscode.Position, newName: string, token: vscode.CancellationToken): Promise { - return (await this.provideRenameEditsImpl(document, position, newName, token))?.edit; - } - - public async provideRenameEditsImpl(document: ITextDocument, position: vscode.Position, newName: string, token: vscode.CancellationToken): Promise { - const allRefsInfo = await this.getAllReferences(document, position, token); - if (token.isCancellationRequested || !allRefsInfo || !allRefsInfo.references.length) { - return undefined; - } - - const triggerRef = allRefsInfo.triggerRef; - - if (triggerRef.kind === 'link' && ( - (triggerRef.link.kind === 'definition' && triggerRef.link.ref.range.contains(position)) || triggerRef.link.href.kind === 'reference' - )) { - return this.renameReferenceLinks(allRefsInfo, newName); - } else if (triggerRef.kind === 'link' && triggerRef.link.href.kind === 'external') { - return this.renameExternalLink(allRefsInfo, newName); - } else if (triggerRef.kind === 'header' || (triggerRef.kind === 'link' && triggerRef.link.source.fragmentRange?.contains(position) && (triggerRef.link.kind === 'definition' || triggerRef.link.kind === 'link' && triggerRef.link.href.kind === 'internal'))) { - return this.renameFragment(allRefsInfo, newName); - } else if (triggerRef.kind === 'link' && !triggerRef.link.source.fragmentRange?.contains(position) && (triggerRef.link.kind === 'link' || triggerRef.link.kind === 'definition') && triggerRef.link.href.kind === 'internal') { - return this.renameFilePath(triggerRef.link.source.resource, triggerRef.link.href, allRefsInfo, newName); - } - - return undefined; - } - - private async renameFilePath(triggerDocument: vscode.Uri, triggerHref: InternalHref, allRefsInfo: MdReferencesResponse, newName: string): Promise { - const edit = new vscode.WorkspaceEdit(); - const fileRenames: MdFileRenameEdit[] = []; - - const targetUri = await tryResolveLinkPath(triggerHref.path, this.workspace) ?? triggerHref.path; - - const rawNewFilePath = resolveDocumentLink(newName, triggerDocument); - let resolvedNewFilePath = rawNewFilePath; - if (!URI.Utils.extname(resolvedNewFilePath)) { - // If the newly entered path doesn't have a file extension but the original file did - // tack on a .md file extension - if (URI.Utils.extname(targetUri)) { - resolvedNewFilePath = resolvedNewFilePath.with({ - path: resolvedNewFilePath.path + '.md' - }); - } - } - - // First rename the file - if (await this.workspace.pathExists(targetUri)) { - fileRenames.push({ from: targetUri, to: resolvedNewFilePath }); - edit.renameFile(targetUri, resolvedNewFilePath); - } - - // Then update all refs to it - for (const ref of allRefsInfo.references) { - if (ref.kind === 'link') { - // Try to preserve style of existing links - let newPath: string; - if (ref.link.source.hrefText.startsWith('/')) { - const root = resolveDocumentLink('/', ref.link.source.resource); - newPath = '/' + path.relative(root.toString(true), rawNewFilePath.toString(true)); - } else { - const rootDir = URI.Utils.dirname(ref.link.source.resource); - if (rootDir.scheme === rawNewFilePath.scheme && rootDir.scheme !== 'untitled') { - newPath = path.relative(rootDir.toString(true), rawNewFilePath.toString(true)); - if (newName.startsWith('./') && !newPath.startsWith('../') || newName.startsWith('.\\') && !newPath.startsWith('..\\')) { - newPath = './' + newPath; - } - } else { - newPath = newName; - } - } - edit.replace(ref.link.source.resource, this.getFilePathRange(ref), encodeURI(newPath.replace(/\\/g, '/'))); - } - } - - return { edit, fileRenames }; - } - - private renameFragment(allRefsInfo: MdReferencesResponse, newName: string): MdWorkspaceEdit { - const slug = this.slugifier.fromHeading(newName).value; - - const edit = new vscode.WorkspaceEdit(); - for (const ref of allRefsInfo.references) { - switch (ref.kind) { - case 'header': - edit.replace(ref.location.uri, ref.headerTextLocation.range, newName); - break; - - case 'link': - edit.replace(ref.link.source.resource, ref.link.source.fragmentRange ?? ref.location.range, !ref.link.source.fragmentRange || ref.link.href.kind === 'external' ? newName : slug); - break; - } - } - return { edit }; - } - - private renameExternalLink(allRefsInfo: MdReferencesResponse, newName: string): MdWorkspaceEdit { - const edit = new vscode.WorkspaceEdit(); - for (const ref of allRefsInfo.references) { - if (ref.kind === 'link') { - edit.replace(ref.link.source.resource, ref.location.range, newName); - } - } - return { edit }; - } - - private renameReferenceLinks(allRefsInfo: MdReferencesResponse, newName: string): MdWorkspaceEdit { - const edit = new vscode.WorkspaceEdit(); - for (const ref of allRefsInfo.references) { - if (ref.kind === 'link') { - if (ref.link.kind === 'definition') { - edit.replace(ref.link.source.resource, ref.link.ref.range, newName); - } else { - edit.replace(ref.link.source.resource, ref.link.source.fragmentRange ?? ref.location.range, newName); - } - } - } - return { edit }; - } - - private async getAllReferences(document: ITextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise { - const version = document.version; - - if (this.cachedRefs - && this.cachedRefs.resource.fsPath === document.uri.fsPath - && this.cachedRefs.version === document.version - && this.cachedRefs.position.isEqual(position) - ) { - return this.cachedRefs; - } - - const references = await this.referencesProvider.getReferencesAtPosition(document, position, token); - const triggerRef = references.find(ref => ref.isTriggerLocation); - if (!triggerRef) { - return undefined; - } - - this.cachedRefs = { - resource: document.uri, - version, - position, - references, - triggerRef - }; - return this.cachedRefs; - } -} - - -export function registerRenameSupport( - selector: vscode.DocumentSelector, - workspace: IMdWorkspace, - referencesProvider: MdReferencesProvider, - slugifier: Slugifier, -): vscode.Disposable { - return vscode.languages.registerRenameProvider(selector, new MdVsCodeRenameProvider(workspace, referencesProvider, slugifier)); -} diff --git a/extensions/markdown-language-features/src/protocol.ts b/extensions/markdown-language-features/src/protocol.ts new file mode 100644 index 0000000000000..75b8162cf8c0b --- /dev/null +++ b/extensions/markdown-language-features/src/protocol.ts @@ -0,0 +1,18 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import Token = require('markdown-it/lib/token'); +import { RequestType } from 'vscode-languageclient'; +import type * as lsp from 'vscode-languageserver-types'; + +// From server +export const parseRequestType: RequestType<{ uri: string }, Token[], any> = new RequestType('markdown/parse'); +export const readFileRequestType: RequestType<{ uri: string }, number[], any> = new RequestType('markdown/readFile'); +export const statFileRequestType: RequestType<{ uri: string }, { isDirectory: boolean } | undefined, any> = new RequestType('markdown/statFile'); +export const readDirectoryRequestType: RequestType<{ uri: string }, [string, { isDirectory: boolean }][], any> = new RequestType('markdown/readDirectory'); +export const findFilesRequestTypes = new RequestType<{}, string[], any>('markdown/findFiles'); + +// To server +export const getReferencesToFileInWorkspace = new RequestType<{ uri: string }, lsp.Location[], any>('markdown/getReferencesToFileInWorkspace'); diff --git a/extensions/markdown-language-features/src/test/definitionProvider.test.ts b/extensions/markdown-language-features/src/test/definitionProvider.test.ts deleted file mode 100644 index 66c8919b5ba91..0000000000000 --- a/extensions/markdown-language-features/src/test/definitionProvider.test.ts +++ /dev/null @@ -1,144 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as assert from 'assert'; -import 'mocha'; -import * as vscode from 'vscode'; -import { MdVsCodeDefinitionProvider } from '../languageFeatures/definitions'; -import { MdReferencesProvider } from '../languageFeatures/references'; -import { MdTableOfContentsProvider } from '../tableOfContents'; -import { noopToken } from '../util/cancellation'; -import { DisposableStore } from '../util/dispose'; -import { InMemoryDocument } from '../util/inMemoryDocument'; -import { IMdWorkspace } from '../workspace'; -import { createNewMarkdownEngine } from './engine'; -import { InMemoryMdWorkspace } from './inMemoryWorkspace'; -import { nulLogger } from './nulLogging'; -import { joinLines, withStore, workspacePath } from './util'; - - -function getDefinition(store: DisposableStore, doc: InMemoryDocument, pos: vscode.Position, workspace: IMdWorkspace) { - const engine = createNewMarkdownEngine(); - const tocProvider = store.add(new MdTableOfContentsProvider(engine, workspace, nulLogger)); - const referencesProvider = store.add(new MdReferencesProvider(engine, workspace, tocProvider, nulLogger)); - const provider = new MdVsCodeDefinitionProvider(referencesProvider); - return provider.provideDefinition(doc, pos, noopToken); -} - -function assertDefinitionsEqual(actualDef: vscode.Definition, ...expectedDefs: { uri: vscode.Uri; line: number; startCharacter?: number; endCharacter?: number }[]) { - const actualDefsArr = Array.isArray(actualDef) ? actualDef : [actualDef]; - - assert.strictEqual(actualDefsArr.length, expectedDefs.length, `Definition counts should match`); - - for (let i = 0; i < actualDefsArr.length; ++i) { - const actual = actualDefsArr[i]; - const expected = expectedDefs[i]; - assert.strictEqual(actual.uri.toString(), expected.uri.toString(), `Definition '${i}' has expected document`); - assert.strictEqual(actual.range.start.line, expected.line, `Definition '${i}' has expected start line`); - assert.strictEqual(actual.range.end.line, expected.line, `Definition '${i}' has expected end line`); - if (typeof expected.startCharacter !== 'undefined') { - assert.strictEqual(actual.range.start.character, expected.startCharacter, `Definition '${i}' has expected start character`); - } - if (typeof expected.endCharacter !== 'undefined') { - assert.strictEqual(actual.range.end.character, expected.endCharacter, `Definition '${i}' has expected end character`); - } - } -} - -suite('markdown: Go to definition', () => { - test('Should not return definition when on link text', withStore(async (store) => { - const doc = new InMemoryDocument(workspacePath('doc.md'), joinLines( - `[ref](#abc)`, - `[ref]: http://example.com`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const defs = await getDefinition(store, doc, new vscode.Position(0, 1), workspace); - assert.deepStrictEqual(defs, undefined); - })); - - test('Should find definition links within file from link', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const doc = new InMemoryDocument(docUri, joinLines( - `[link 1][abc]`, // trigger here - ``, - `[abc]: https://example.com`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const defs = await getDefinition(store, doc, new vscode.Position(0, 12), workspace); - assertDefinitionsEqual(defs!, - { uri: docUri, line: 2 }, - ); - })); - - test('Should find definition links using shorthand', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const doc = new InMemoryDocument(docUri, joinLines( - `[ref]`, // trigger 1 - ``, - `[yes][ref]`, // trigger 2 - ``, - `[ref]: /Hello.md` // trigger 3 - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - { - const defs = await getDefinition(store, doc, new vscode.Position(0, 2), workspace); - assertDefinitionsEqual(defs!, - { uri: docUri, line: 4 }, - ); - } - { - const defs = await getDefinition(store, doc, new vscode.Position(2, 7), workspace); - assertDefinitionsEqual(defs!, - { uri: docUri, line: 4 }, - ); - } - { - const defs = await getDefinition(store, doc, new vscode.Position(4, 2), workspace); - assertDefinitionsEqual(defs!, - { uri: docUri, line: 4 }, - ); - } - })); - - test('Should find definition links within file from definition', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const doc = new InMemoryDocument(docUri, joinLines( - `[link 1][abc]`, - ``, - `[abc]: https://example.com`, // trigger here - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const defs = await getDefinition(store, doc, new vscode.Position(2, 3), workspace); - assertDefinitionsEqual(defs!, - { uri: docUri, line: 2 }, - ); - })); - - test('Should not find definition links across files', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const doc = new InMemoryDocument(docUri, joinLines( - `[link 1][abc]`, - ``, - `[abc]: https://example.com`, - )); - const workspace = store.add(new InMemoryMdWorkspace([ - doc, - new InMemoryDocument(workspacePath('other.md'), joinLines( - `[link 1][abc]`, - ``, - `[abc]: https://example.com?bad` - )) - ])); - - const defs = await getDefinition(store, doc, new vscode.Position(0, 12), workspace); - assertDefinitionsEqual(defs!, - { uri: docUri, line: 2 }, - ); - })); -}); diff --git a/extensions/markdown-language-features/src/test/fileReferences.test.ts b/extensions/markdown-language-features/src/test/fileReferences.test.ts deleted file mode 100644 index 3b49e7790ea51..0000000000000 --- a/extensions/markdown-language-features/src/test/fileReferences.test.ts +++ /dev/null @@ -1,120 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as assert from 'assert'; -import 'mocha'; -import * as vscode from 'vscode'; -import { MdReference, MdReferencesProvider } from '../languageFeatures/references'; -import { MdTableOfContentsProvider } from '../tableOfContents'; -import { noopToken } from '../util/cancellation'; -import { DisposableStore } from '../util/dispose'; -import { InMemoryDocument } from '../util/inMemoryDocument'; -import { IMdWorkspace } from '../workspace'; -import { createNewMarkdownEngine } from './engine'; -import { InMemoryMdWorkspace } from './inMemoryWorkspace'; -import { nulLogger } from './nulLogging'; -import { joinLines, withStore, workspacePath } from './util'; - - -function getFileReferences(store: DisposableStore, resource: vscode.Uri, workspace: IMdWorkspace) { - const engine = createNewMarkdownEngine(); - const tocProvider = store.add(new MdTableOfContentsProvider(engine, workspace, nulLogger)); - const computer = store.add(new MdReferencesProvider(engine, workspace, tocProvider, nulLogger)); - return computer.getReferencesToFileInWorkspace(resource, noopToken); -} - -function assertReferencesEqual(actualRefs: readonly MdReference[], ...expectedRefs: { uri: vscode.Uri; line: number }[]) { - assert.strictEqual(actualRefs.length, expectedRefs.length, `Reference counts should match`); - - for (let i = 0; i < actualRefs.length; ++i) { - const actual = actualRefs[i].location; - const expected = expectedRefs[i]; - assert.strictEqual(actual.uri.toString(), expected.uri.toString(), `Ref '${i}' has expected document`); - assert.strictEqual(actual.range.start.line, expected.line, `Ref '${i}' has expected start line`); - assert.strictEqual(actual.range.end.line, expected.line, `Ref '${i}' has expected end line`); - } -} - -suite('markdown: find file references', () => { - - test('Should find basic references', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const otherUri = workspacePath('other.md'); - const workspace = store.add(new InMemoryMdWorkspace([ - new InMemoryDocument(docUri, joinLines( - `# header`, - `[link 1](./other.md)`, - `[link 2](./other.md)` - )), - new InMemoryDocument(otherUri, joinLines( - `# header`, - `pre`, - `[link 3](./other.md)`, - `post` - )), - ])); - - const refs = await getFileReferences(store, otherUri, workspace); - assertReferencesEqual(refs, - { uri: docUri, line: 1 }, - { uri: docUri, line: 2 }, - { uri: otherUri, line: 2 }, - ); - })); - - test('Should find references with and without file extensions', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const otherUri = workspacePath('other.md'); - const workspace = store.add(new InMemoryMdWorkspace([ - new InMemoryDocument(docUri, joinLines( - `# header`, - `[link 1](./other.md)`, - `[link 2](./other)` - )), - new InMemoryDocument(otherUri, joinLines( - `# header`, - `pre`, - `[link 3](./other.md)`, - `[link 4](./other)`, - `post` - )), - ])); - - const refs = await getFileReferences(store, otherUri, workspace); - assertReferencesEqual(refs, - { uri: docUri, line: 1 }, - { uri: docUri, line: 2 }, - { uri: otherUri, line: 2 }, - { uri: otherUri, line: 3 }, - ); - })); - - test('Should find references with headers on links', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const otherUri = workspacePath('other.md'); - const workspace = store.add(new InMemoryMdWorkspace([ - new InMemoryDocument(docUri, joinLines( - `# header`, - `[link 1](./other.md#sub-bla)`, - `[link 2](./other#sub-bla)` - )), - new InMemoryDocument(otherUri, joinLines( - `# header`, - `pre`, - `[link 3](./other.md#sub-bla)`, - `[link 4](./other#sub-bla)`, - `post` - )), - ])); - - const refs = await getFileReferences(store, otherUri, workspace); - assertReferencesEqual(refs, - { uri: docUri, line: 1 }, - { uri: docUri, line: 2 }, - { uri: otherUri, line: 2 }, - { uri: otherUri, line: 3 }, - ); - })); -}); diff --git a/extensions/markdown-language-features/src/test/references.test.ts b/extensions/markdown-language-features/src/test/references.test.ts deleted file mode 100644 index 087ede3523903..0000000000000 --- a/extensions/markdown-language-features/src/test/references.test.ts +++ /dev/null @@ -1,635 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as assert from 'assert'; -import 'mocha'; -import * as vscode from 'vscode'; -import { MdReferencesProvider, MdVsCodeReferencesProvider } from '../languageFeatures/references'; -import { MdTableOfContentsProvider } from '../tableOfContents'; -import { noopToken } from '../util/cancellation'; -import { DisposableStore } from '../util/dispose'; -import { InMemoryDocument } from '../util/inMemoryDocument'; -import { IMdWorkspace } from '../workspace'; -import { createNewMarkdownEngine } from './engine'; -import { InMemoryMdWorkspace } from './inMemoryWorkspace'; -import { nulLogger } from './nulLogging'; -import { joinLines, withStore, workspacePath } from './util'; - - -async function getReferences(store: DisposableStore, doc: InMemoryDocument, pos: vscode.Position, workspace: IMdWorkspace) { - const engine = createNewMarkdownEngine(); - const tocProvider = store.add(new MdTableOfContentsProvider(engine, workspace, nulLogger)); - const computer = store.add(new MdReferencesProvider(engine, workspace, tocProvider, nulLogger)); - const provider = new MdVsCodeReferencesProvider(computer); - const refs = await provider.provideReferences(doc, pos, { includeDeclaration: true }, noopToken); - return refs.sort((a, b) => { - const pathCompare = a.uri.toString().localeCompare(b.uri.toString()); - if (pathCompare !== 0) { - return pathCompare; - } - return a.range.start.compareTo(b.range.start); - }); -} - -function assertReferencesEqual(actualRefs: readonly vscode.Location[], ...expectedRefs: { uri: vscode.Uri; line: number; startCharacter?: number; endCharacter?: number }[]) { - assert.strictEqual(actualRefs.length, expectedRefs.length, `Reference counts should match`); - - for (let i = 0; i < actualRefs.length; ++i) { - const actual = actualRefs[i]; - const expected = expectedRefs[i]; - assert.strictEqual(actual.uri.toString(), expected.uri.toString(), `Ref '${i}' has expected document`); - assert.strictEqual(actual.range.start.line, expected.line, `Ref '${i}' has expected start line`); - assert.strictEqual(actual.range.end.line, expected.line, `Ref '${i}' has expected end line`); - if (typeof expected.startCharacter !== 'undefined') { - assert.strictEqual(actual.range.start.character, expected.startCharacter, `Ref '${i}' has expected start character`); - } - if (typeof expected.endCharacter !== 'undefined') { - assert.strictEqual(actual.range.end.character, expected.endCharacter, `Ref '${i}' has expected end character`); - } - } -} - -suite('Markdown: Find all references', () => { - test('Should not return references when not on header or link', withStore(async (store) => { - const doc = new InMemoryDocument(workspacePath('doc.md'), joinLines( - `# abc`, - ``, - `[link 1](#abc)`, - `text`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - { - const refs = await getReferences(store, doc, new vscode.Position(1, 0), workspace); - assert.deepStrictEqual(refs, []); - } - { - const refs = await getReferences(store, doc, new vscode.Position(3, 2), workspace); - assert.deepStrictEqual(refs, []); - } - })); - - test('Should find references from header within same file', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `# abc`, - ``, - `[link 1](#abc)`, - `[not link](#noabc)`, - `[link 2](#abc)`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 3), workspace); - assertReferencesEqual(refs!, - { uri, line: 0 }, - { uri, line: 2 }, - { uri, line: 4 }, - ); - })); - - test('Should not return references when on link text', withStore(async (store) => { - const doc = new InMemoryDocument(workspacePath('doc.md'), joinLines( - `[ref](#abc)`, - `[ref]: http://example.com`, - )); - - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 1), workspace); - assert.deepStrictEqual(refs, []); - })); - - test('Should find references using normalized slug', withStore(async (store) => { - const doc = new InMemoryDocument(workspacePath('doc.md'), joinLines( - `# a B c`, - `[simple](#a-b-c)`, - `[start underscore](#_a-b-c)`, - `[different case](#a-B-C)`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - { - // Trigger header - - const refs = await getReferences(store, doc, new vscode.Position(0, 0), workspace); - assert.deepStrictEqual(refs!.length, 4); - } - { - // Trigger on line 1 - const refs = await getReferences(store, doc, new vscode.Position(1, 12), workspace); - assert.deepStrictEqual(refs!.length, 4); - } - { - // Trigger on line 2 - const refs = await getReferences(store, doc, new vscode.Position(2, 24), workspace); - assert.deepStrictEqual(refs!.length, 4); - } - { - // Trigger on line 3 - const refs = await getReferences(store, doc, new vscode.Position(3, 20), workspace); - assert.deepStrictEqual(refs!.length, 4); - } - })); - - test('Should find references from header across files', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const other1Uri = workspacePath('sub', 'other.md'); - const other2Uri = workspacePath('zOther2.md'); - - const doc = new InMemoryDocument(docUri, joinLines( - `# abc`, - ``, - `[link 1](#abc)`, - )); - - const workspace = store.add(new InMemoryMdWorkspace([ - doc, - new InMemoryDocument(other1Uri, joinLines( - `[not link](#abc)`, - `[not link](/doc.md#abz)`, - `[link](/doc.md#abc)` - )), - new InMemoryDocument(other2Uri, joinLines( - `[not link](#abc)`, - `[not link](./doc.md#abz)`, - `[link](./doc.md#abc)` - )) - ])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 3), workspace); - - assertReferencesEqual(refs!, - { uri: docUri, line: 0 }, // Header definition - { uri: docUri, line: 2 }, - { uri: other1Uri, line: 2 }, - { uri: other2Uri, line: 2 }, - ); - })); - - test('Should find references from header to link definitions ', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `# abc`, - ``, - `[bla]: #abc` - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 3), workspace); - assertReferencesEqual(refs!, - { uri, line: 0 }, // Header definition - { uri, line: 2 }, - ); - })); - - test('Should find header references from link definition', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `# A b C`, - `[text][bla]`, - `[bla]: #a-b-c`, // trigger here - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const refs = await getReferences(store, doc, new vscode.Position(2, 9), workspace); - assertReferencesEqual(refs!, - { uri, line: 0 }, // Header definition - { uri, line: 2 }, - ); - })); - - test('Should find references from link within same file', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `# abc`, - ``, - `[link 1](#abc)`, - `[not link](#noabc)`, - `[link 2](#abc)`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const refs = await getReferences(store, doc, new vscode.Position(2, 10), workspace); - assertReferencesEqual(refs!, - { uri, line: 0 }, // Header definition - { uri, line: 2 }, - { uri, line: 4 }, - ); - })); - - test('Should find references from link across files', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const other1Uri = workspacePath('sub', 'other.md'); - const other2Uri = workspacePath('zOther2.md'); - - const doc = new InMemoryDocument(docUri, joinLines( - `# abc`, - ``, - `[link 1](#abc)`, - )); - const workspace = store.add(new InMemoryMdWorkspace([ - doc, - new InMemoryDocument(other1Uri, joinLines( - `[not link](#abc)`, - `[not link](/doc.md#abz)`, - `[with ext](/doc.md#abc)`, - `[without ext](/doc#abc)` - )), - new InMemoryDocument(other2Uri, joinLines( - `[not link](#abc)`, - `[not link](./doc.md#abz)`, - `[link](./doc.md#abc)` - )) - ])); - - const refs = await getReferences(store, doc, new vscode.Position(2, 10), workspace); - assertReferencesEqual(refs!, - { uri: docUri, line: 0 }, // Header definition - { uri: docUri, line: 2 }, - { uri: other1Uri, line: 2 }, // Other with ext - { uri: other1Uri, line: 3 }, // Other without ext - { uri: other2Uri, line: 2 }, // Other2 - ); - })); - - test('Should find references without requiring file extensions', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const other1Uri = workspacePath('other.md'); - - const doc = new InMemoryDocument(docUri, joinLines( - `# a B c`, - ``, - `[link 1](#a-b-c)`, - )); - const workspace = store.add(new InMemoryMdWorkspace([ - doc, - new InMemoryDocument(other1Uri, joinLines( - `[not link](#a-b-c)`, - `[not link](/doc.md#a-b-z)`, - `[with ext](/doc.md#a-b-c)`, - `[without ext](/doc#a-b-c)`, - `[rel with ext](./doc.md#a-b-c)`, - `[rel without ext](./doc#a-b-c)` - )), - ])); - - const refs = await getReferences(store, doc, new vscode.Position(2, 10), workspace); - assertReferencesEqual(refs!, - { uri: docUri, line: 0 }, // Header definition - { uri: docUri, line: 2 }, - { uri: other1Uri, line: 2 }, // Other with ext - { uri: other1Uri, line: 3 }, // Other without ext - { uri: other1Uri, line: 4 }, // Other relative link with ext - { uri: other1Uri, line: 5 }, // Other relative link without ext - ); - })); - - test('Should find references from link across files when triggered on link without file extension', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const other1Uri = workspacePath('sub', 'other.md'); - - const doc = new InMemoryDocument(docUri, joinLines( - `[with ext](./sub/other#header)`, - `[without ext](./sub/other.md#header)`, - )); - - const workspace = store.add(new InMemoryMdWorkspace([ - doc, - new InMemoryDocument(other1Uri, joinLines( - `pre`, - `# header`, - `post` - )), - ])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 23), workspace); - assertReferencesEqual(refs!, - { uri: docUri, line: 0 }, - { uri: docUri, line: 1 }, - { uri: other1Uri, line: 1 }, // Header definition - ); - })); - - test('Should include header references when triggered on file link', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const otherUri = workspacePath('sub', 'other.md'); - - const doc = new InMemoryDocument(docUri, joinLines( - `[with ext](./sub/other)`, - `[with ext](./sub/other#header)`, - `[without ext](./sub/other.md#no-such-header)`, - )); - const workspace = store.add(new InMemoryMdWorkspace([ - doc, - new InMemoryDocument(otherUri, joinLines( - `pre`, - `# header`, - `post` - )), - ])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 15), workspace); - assertReferencesEqual(refs!, - { uri: docUri, line: 0 }, - { uri: docUri, line: 1 }, - { uri: docUri, line: 2 }, - ); - })); - - test('Should not include refs from other file to own header', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const otherUri = workspacePath('sub', 'other.md'); - - const doc = new InMemoryDocument(docUri, joinLines( - `[other](./sub/other)`, // trigger here - )); - - const workspace = store.add(new InMemoryMdWorkspace([ - doc, - new InMemoryDocument(otherUri, joinLines( - `# header`, // Definition should not be included since we triggered on a file link - `[text](#header)`, // Ref should not be included since it is to own file - )), - ])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 15), workspace); - assertReferencesEqual(refs!, - { uri: docUri, line: 0 }, - ); - })); - - test('Should find explicit references to own file ', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[bare](doc.md)`, // trigger here - `[rel](./doc.md)`, - `[abs](/doc.md)`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 12), workspace); - assertReferencesEqual(refs!, - { uri, line: 0 }, - { uri, line: 1 }, - { uri, line: 2 }, - ); - })); - - test('Should support finding references to http uri', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[1](http://example.com)`, - `[no](https://example.com)`, - `[2](http://example.com)`, - `[3]: http://example.com`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 13), workspace); - assertReferencesEqual(refs!, - { uri, line: 0 }, - { uri, line: 2 }, - { uri, line: 3 }, - ); - })); - - test('Should consider authority, scheme and paths when finding references to http uri', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[1](http://example.com/cat)`, - `[2](http://example.com)`, - `[3](http://example.com/dog)`, - `[4](http://example.com/cat/looong)`, - `[5](http://example.com/cat)`, - `[6](http://other.com/cat)`, - `[7](https://example.com/cat)`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 13), workspace); - assertReferencesEqual(refs!, - { uri, line: 0 }, - { uri, line: 4 }, - ); - })); - - test('Should support finding references to http uri across files', withStore(async (store) => { - const uri1 = workspacePath('doc.md'); - const uri2 = workspacePath('doc2.md'); - const doc = new InMemoryDocument(uri1, joinLines( - `[1](http://example.com)`, - `[3]: http://example.com`, - )); - const workspace = store.add(new InMemoryMdWorkspace([ - doc, - new InMemoryDocument(uri2, joinLines( - `[other](http://example.com)` - )) - ])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 13), workspace); - assertReferencesEqual(refs!, - { uri: uri1, line: 0 }, - { uri: uri1, line: 1 }, - { uri: uri2, line: 0 }, - ); - })); - - test('Should support finding references to autolinked http links', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[1](http://example.com)`, - ``, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 13), workspace); - assertReferencesEqual(refs!, - { uri, line: 0 }, - { uri, line: 1 }, - ); - })); - - test('Should distinguish between references to file and to header within file', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const other1Uri = workspacePath('sub', 'other.md'); - - const doc = new InMemoryDocument(docUri, joinLines( - `# abc`, - ``, - `[link 1](#abc)`, - )); - const otherDoc = new InMemoryDocument(other1Uri, joinLines( - `[link](/doc.md#abc)`, - `[link no text](/doc#abc)`, - )); - const workspace = store.add(new InMemoryMdWorkspace([ - doc, - otherDoc, - ])); - - { - // Check refs to header fragment - const headerRefs = await getReferences(store, otherDoc, new vscode.Position(0, 16), workspace); - assertReferencesEqual(headerRefs, - { uri: docUri, line: 0 }, // Header definition - { uri: docUri, line: 2 }, - { uri: other1Uri, line: 0 }, - { uri: other1Uri, line: 1 }, - ); - } - { - // Check refs to file itself from link with ext - const fileRefs = await getReferences(store, otherDoc, new vscode.Position(0, 9), workspace); - assertReferencesEqual(fileRefs, - { uri: other1Uri, line: 0, endCharacter: 14 }, - { uri: other1Uri, line: 1, endCharacter: 19 }, - ); - } - { - // Check refs to file itself from link without ext - const fileRefs = await getReferences(store, otherDoc, new vscode.Position(1, 17), workspace); - assertReferencesEqual(fileRefs, - { uri: other1Uri, line: 0 }, - { uri: other1Uri, line: 1 }, - ); - } - })); - - test('Should support finding references to unknown file', withStore(async (store) => { - const uri1 = workspacePath('doc1.md'); - const doc1 = new InMemoryDocument(uri1, joinLines( - `![img](/images/more/image.png)`, - ``, - `[ref]: /images/more/image.png`, - )); - - const uri2 = workspacePath('sub', 'doc2.md'); - const doc2 = new InMemoryDocument(uri2, joinLines( - `![img](/images/more/image.png)`, - )); - - const workspace = store.add(new InMemoryMdWorkspace([doc1, doc2])); - - const refs = await getReferences(store, doc1, new vscode.Position(0, 10), workspace); - assertReferencesEqual(refs!, - { uri: uri1, line: 0 }, - { uri: uri1, line: 2 }, - { uri: uri2, line: 0 }, - ); - })); - - suite('Reference links', () => { - test('Should find reference links within file from link', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const doc = new InMemoryDocument(docUri, joinLines( - `[link 1][abc]`, // trigger here - ``, - `[abc]: https://example.com`, - )); - - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 12), workspace); - assertReferencesEqual(refs!, - { uri: docUri, line: 0 }, - { uri: docUri, line: 2 }, - ); - })); - - test('Should find reference links using shorthand', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const doc = new InMemoryDocument(docUri, joinLines( - `[ref]`, // trigger 1 - ``, - `[yes][ref]`, // trigger 2 - ``, - `[ref]: /Hello.md` // trigger 3 - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - { - const refs = await getReferences(store, doc, new vscode.Position(0, 2), workspace); - assertReferencesEqual(refs!, - { uri: docUri, line: 0 }, - { uri: docUri, line: 2 }, - { uri: docUri, line: 4 }, - ); - } - { - const refs = await getReferences(store, doc, new vscode.Position(2, 7), workspace); - assertReferencesEqual(refs!, - { uri: docUri, line: 0 }, - { uri: docUri, line: 2 }, - { uri: docUri, line: 4 }, - ); - } - { - const refs = await getReferences(store, doc, new vscode.Position(4, 2), workspace); - assertReferencesEqual(refs!, - { uri: docUri, line: 0 }, - { uri: docUri, line: 2 }, - { uri: docUri, line: 4 }, - ); - } - })); - - test('Should find reference links within file from definition', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const doc = new InMemoryDocument(docUri, joinLines( - `[link 1][abc]`, - ``, - `[abc]: https://example.com`, // trigger here - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const refs = await getReferences(store, doc, new vscode.Position(2, 3), workspace); - assertReferencesEqual(refs!, - { uri: docUri, line: 0 }, - { uri: docUri, line: 2 }, - ); - })); - - test('Should not find reference links across files', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const doc = new InMemoryDocument(docUri, joinLines( - `[link 1][abc]`, - ``, - `[abc]: https://example.com`, - )); - - const workspace = store.add(new InMemoryMdWorkspace([ - doc, - new InMemoryDocument(workspacePath('other.md'), joinLines( - `[link 1][abc]`, - ``, - `[abc]: https://example.com?bad` - )) - ])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 12), workspace); - assertReferencesEqual(refs!, - { uri: docUri, line: 0 }, - { uri: docUri, line: 2 }, - ); - })); - - test('Should not consider checkboxes as reference links', withStore(async (store) => { - const docUri = workspacePath('doc.md'); - const doc = new InMemoryDocument(docUri, joinLines( - `- [x]`, - `- [X]`, - `- [ ]`, - ``, - `[x]: https://example.com` - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const refs = await getReferences(store, doc, new vscode.Position(0, 4), workspace); - assert.strictEqual(refs?.length!, 0); - })); - }); -}); diff --git a/extensions/markdown-language-features/src/test/rename.test.ts b/extensions/markdown-language-features/src/test/rename.test.ts deleted file mode 100644 index 48e8d99032158..0000000000000 --- a/extensions/markdown-language-features/src/test/rename.test.ts +++ /dev/null @@ -1,720 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as assert from 'assert'; -import 'mocha'; -import * as vscode from 'vscode'; -import { MdReferencesProvider } from '../languageFeatures/references'; -import { MdVsCodeRenameProvider, MdWorkspaceEdit } from '../languageFeatures/rename'; -import { githubSlugifier } from '../slugify'; -import { MdTableOfContentsProvider } from '../tableOfContents'; -import { noopToken } from '../util/cancellation'; -import { DisposableStore } from '../util/dispose'; -import { InMemoryDocument } from '../util/inMemoryDocument'; -import { IMdWorkspace } from '../workspace'; -import { createNewMarkdownEngine } from './engine'; -import { InMemoryMdWorkspace } from './inMemoryWorkspace'; -import { nulLogger } from './nulLogging'; -import { assertRangeEqual, joinLines, withStore, workspacePath } from './util'; - - -/** - * Get prepare rename info. - */ -function prepareRename(store: DisposableStore, doc: InMemoryDocument, pos: vscode.Position, workspace: IMdWorkspace): Promise { - const engine = createNewMarkdownEngine(); - const tocProvider = store.add(new MdTableOfContentsProvider(engine, workspace, nulLogger)); - const referenceComputer = store.add(new MdReferencesProvider(engine, workspace, tocProvider, nulLogger)); - const renameProvider = store.add(new MdVsCodeRenameProvider(workspace, referenceComputer, githubSlugifier)); - return renameProvider.prepareRename(doc, pos, noopToken); -} - -/** - * Get all the edits for the rename. - */ -function getRenameEdits(store: DisposableStore, doc: InMemoryDocument, pos: vscode.Position, newName: string, workspace: IMdWorkspace): Promise { - const engine = createNewMarkdownEngine(); - const tocProvider = store.add(new MdTableOfContentsProvider(engine, workspace, nulLogger)); - const referencesProvider = store.add(new MdReferencesProvider(engine, workspace, tocProvider, nulLogger)); - const renameProvider = store.add(new MdVsCodeRenameProvider(workspace, referencesProvider, githubSlugifier)); - return renameProvider.provideRenameEditsImpl(doc, pos, newName, noopToken); -} - -interface ExpectedTextEdit { - readonly uri: vscode.Uri; - readonly edits: readonly vscode.TextEdit[]; -} - -interface ExpectedFileRename { - readonly originalUri: vscode.Uri; - readonly newUri: vscode.Uri; -} - -function assertEditsEqual(actualEdit: MdWorkspaceEdit, ...expectedEdits: ReadonlyArray) { - // Check file renames - const expectedFileRenames = expectedEdits.filter(expected => 'originalUri' in expected) as ExpectedFileRename[]; - const actualFileRenames = actualEdit.fileRenames ?? []; - assert.strictEqual(actualFileRenames.length, expectedFileRenames.length, `File rename count should match`); - for (let i = 0; i < actualFileRenames.length; ++i) { - const expected = expectedFileRenames[i]; - const actual = actualFileRenames[i]; - assert.strictEqual(actual.from.toString(), expected.originalUri.toString(), `File rename '${i}' should have expected 'from' resource`); - assert.strictEqual(actual.to.toString(), expected.newUri.toString(), `File rename '${i}' should have expected 'to' resource`); - } - - // Check text edits - const actualTextEdits = actualEdit.edit.entries(); - const expectedTextEdits = expectedEdits.filter(expected => 'edits' in expected) as ExpectedTextEdit[]; - assert.strictEqual(actualTextEdits.length, expectedTextEdits.length, `Reference counts should match`); - for (let i = 0; i < actualTextEdits.length; ++i) { - const expected = expectedTextEdits[i]; - const actual = actualTextEdits[i]; - - if ('edits' in expected) { - assert.strictEqual(actual[0].toString(), expected.uri.toString(), `Ref '${i}' has expected document`); - - const actualEditForDoc = actual[1]; - const expectedEditsForDoc = expected.edits; - assert.strictEqual(actualEditForDoc.length, expectedEditsForDoc.length, `Edit counts for '${actual[0]}' should match`); - - for (let g = 0; g < actualEditForDoc.length; ++g) { - assertRangeEqual(actualEditForDoc[g].range, expectedEditsForDoc[g].range, `Edit '${g}' of '${actual[0]}' has expected expected range. Expected range: ${JSON.stringify(actualEditForDoc[g].range)}. Actual range: ${JSON.stringify(expectedEditsForDoc[g].range)}`); - assert.strictEqual(actualEditForDoc[g].newText, expectedEditsForDoc[g].newText, `Edit '${g}' of '${actual[0]}' has expected edits`); - } - } - } -} - -suite('markdown: rename', () => { - - setup(async () => { - // the tests make the assumption that link providers are already registered - await vscode.extensions.getExtension('vscode.markdown-language-features')!.activate(); - }); - - test('Rename on header should not include leading #', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `# abc` - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const info = await prepareRename(store, doc, new vscode.Position(0, 0), workspace); - assertRangeEqual(info!.range, new vscode.Range(0, 2, 0, 5)); - - const edit = await getRenameEdits(store, doc, new vscode.Position(0, 0), "New Header", workspace); - assertEditsEqual(edit!, { - uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 2, 0, 5), 'New Header') - ] - }); - })); - - test('Rename on header should include leading or trailing #s', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `### abc ###` - )); - - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const info = await prepareRename(store, doc, new vscode.Position(0, 0), workspace); - assertRangeEqual(info!.range, new vscode.Range(0, 4, 0, 7)); - - const edit = await getRenameEdits(store, doc, new vscode.Position(0, 0), "New Header", workspace); - assertEditsEqual(edit!, { - uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 4, 0, 7), 'New Header') - ] - }); - })); - - test('Rename on header should pick up links in doc', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `### A b C`, // rename here - `[text](#a-b-c)`, - )); - - const workspace = store.add(new InMemoryMdWorkspace([doc])); - const edit = await getRenameEdits(store, doc, new vscode.Position(0, 0), "New Header", workspace); - assertEditsEqual(edit!, { - uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 4, 0, 9), 'New Header'), - new vscode.TextEdit(new vscode.Range(1, 8, 1, 13), 'new-header'), - ] - }); - })); - - test('Rename on link should use slug for link', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `### A b C`, - `[text](#a-b-c)`, // rename here - )); - - const workspace = store.add(new InMemoryMdWorkspace([doc])); - const edit = await getRenameEdits(store, doc, new vscode.Position(1, 10), "New Header", workspace); - assertEditsEqual(edit!, { - uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 4, 0, 9), 'New Header'), - new vscode.TextEdit(new vscode.Range(1, 8, 1, 13), 'new-header'), - ] - }); - })); - - test('Rename on link definition should work', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `### A b C`, - `[text](#a-b-c)`, - `[ref]: #a-b-c`// rename here - )); - - const workspace = store.add(new InMemoryMdWorkspace([doc])); - const edit = await getRenameEdits(store, doc, new vscode.Position(2, 10), "New Header", workspace); - assertEditsEqual(edit!, { - uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 4, 0, 9), 'New Header'), - new vscode.TextEdit(new vscode.Range(1, 8, 1, 13), 'new-header'), - new vscode.TextEdit(new vscode.Range(2, 8, 2, 13), 'new-header'), - ] - }); - })); - - test('Rename on header should pick up links across files', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const otherUri = workspacePath('other.md'); - const doc = new InMemoryDocument(uri, joinLines( - `### A b C`, // rename here - `[text](#a-b-c)`, - )); - - const edit = await getRenameEdits(store, doc, new vscode.Position(0, 0), "New Header", new InMemoryMdWorkspace([ - doc, - new InMemoryDocument(otherUri, joinLines( - `[text](#a-b-c)`, // Should not find this - `[text](./doc.md#a-b-c)`, // But should find this - `[text](./doc#a-b-c)`, // And this - )) - ])); - assertEditsEqual(edit!, { - uri: uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 4, 0, 9), 'New Header'), - new vscode.TextEdit(new vscode.Range(1, 8, 1, 13), 'new-header'), - ] - }, { - uri: otherUri, edits: [ - new vscode.TextEdit(new vscode.Range(1, 16, 1, 21), 'new-header'), - new vscode.TextEdit(new vscode.Range(2, 13, 2, 18), 'new-header'), - ] - }); - })); - - test('Rename on link should pick up links across files', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const otherUri = workspacePath('other.md'); - const doc = new InMemoryDocument(uri, joinLines( - `### A b C`, - `[text](#a-b-c)`, // rename here - )); - - const edit = await getRenameEdits(store, doc, new vscode.Position(1, 10), "New Header", new InMemoryMdWorkspace([ - doc, - new InMemoryDocument(otherUri, joinLines( - `[text](#a-b-c)`, // Should not find this - `[text](./doc.md#a-b-c)`, // But should find this - `[text](./doc#a-b-c)`, // And this - )) - ])); - assertEditsEqual(edit!, { - uri: uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 4, 0, 9), 'New Header'), - new vscode.TextEdit(new vscode.Range(1, 8, 1, 13), 'new-header'), - ] - }, { - uri: otherUri, edits: [ - new vscode.TextEdit(new vscode.Range(1, 16, 1, 21), 'new-header'), - new vscode.TextEdit(new vscode.Range(2, 13, 2, 18), 'new-header'), - ] - }); - })); - - test('Rename on link in other file should pick up all refs', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const otherUri = workspacePath('other.md'); - const doc = new InMemoryDocument(uri, joinLines( - `### A b C`, - `[text](#a-b-c)`, - )); - - const otherDoc = new InMemoryDocument(otherUri, joinLines( - `[text](#a-b-c)`, - `[text](./doc.md#a-b-c)`, - `[text](./doc#a-b-c)` - )); - - const expectedEdits = [ - { - uri: uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 4, 0, 9), 'New Header'), - new vscode.TextEdit(new vscode.Range(1, 8, 1, 13), 'new-header'), - ] - }, { - uri: otherUri, edits: [ - new vscode.TextEdit(new vscode.Range(1, 16, 1, 21), 'new-header'), - new vscode.TextEdit(new vscode.Range(2, 13, 2, 18), 'new-header'), - ] - } - ]; - - { - // Rename on header with file extension - const edit = await getRenameEdits(store, otherDoc, new vscode.Position(1, 17), "New Header", new InMemoryMdWorkspace([ - doc, - otherDoc - ])); - assertEditsEqual(edit!, ...expectedEdits); - } - { - // Rename on header without extension - const edit = await getRenameEdits(store, otherDoc, new vscode.Position(2, 15), "New Header", new InMemoryMdWorkspace([ - doc, - otherDoc - ])); - assertEditsEqual(edit!, ...expectedEdits); - } - })); - - test('Rename on reference should rename references and definition', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[text][ref]`, // rename here - `[other][ref]`, - ``, - `[ref]: https://example.com`, - )); - - const workspace = store.add(new InMemoryMdWorkspace([doc])); - const edit = await getRenameEdits(store, doc, new vscode.Position(0, 8), "new ref", workspace); - assertEditsEqual(edit!, { - uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 7, 0, 10), 'new ref'), - new vscode.TextEdit(new vscode.Range(1, 8, 1, 11), 'new ref'), - new vscode.TextEdit(new vscode.Range(3, 1, 3, 4), 'new ref'), - ] - }); - })); - - test('Rename on definition should rename references and definitions', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[text][ref]`, - `[other][ref]`, - ``, - `[ref]: https://example.com`, // rename here - )); - - const workspace = store.add(new InMemoryMdWorkspace([doc])); - const edit = await getRenameEdits(store, doc, new vscode.Position(3, 3), "new ref", workspace); - assertEditsEqual(edit!, { - uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 7, 0, 10), 'new ref'), - new vscode.TextEdit(new vscode.Range(1, 8, 1, 11), 'new ref'), - new vscode.TextEdit(new vscode.Range(3, 1, 3, 4), 'new ref'), - ] - }); - })); - - test('Rename on definition entry should rename header and references', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `# a B c`, - `[ref text][ref]`, - `[direct](#a-b-c)`, - `[ref]: #a-b-c`, // rename here - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const preparedInfo = await prepareRename(store, doc, new vscode.Position(3, 10), workspace); - assert.strictEqual(preparedInfo!.placeholder, 'a B c'); - assertRangeEqual(preparedInfo!.range, new vscode.Range(3, 8, 3, 13)); - - const edit = await getRenameEdits(store, doc, new vscode.Position(3, 10), "x Y z", workspace); - assertEditsEqual(edit!, { - uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 2, 0, 7), 'x Y z'), - new vscode.TextEdit(new vscode.Range(2, 10, 2, 15), 'x-y-z'), - new vscode.TextEdit(new vscode.Range(3, 8, 3, 13), 'x-y-z'), - ] - }); - })); - - test('Rename should not be supported on link text', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `# Header`, - `[text](#header)`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - await assert.rejects(prepareRename(store, doc, new vscode.Position(1, 2), workspace)); - })); - - test('Path rename should use file path as range', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[text](./doc.md)`, - `[ref]: ./doc.md`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const info = await prepareRename(store, doc, new vscode.Position(0, 10), workspace); - assert.strictEqual(info!.placeholder, './doc.md'); - assertRangeEqual(info!.range, new vscode.Range(0, 7, 0, 15)); - })); - - test('Path rename\'s range should excludes fragment', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[text](./doc.md#some-header)`, - `[ref]: ./doc.md#some-header`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const info = await prepareRename(store, doc, new vscode.Position(0, 10), workspace); - assert.strictEqual(info!.placeholder, './doc.md'); - assertRangeEqual(info!.range, new vscode.Range(0, 7, 0, 15)); - })); - - test('Path rename should update file and all refs', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[text](./doc.md)`, - `[ref]: ./doc.md`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const edit = await getRenameEdits(store, doc, new vscode.Position(0, 10), './sub/newDoc.md', workspace); - assertEditsEqual(edit!, { - originalUri: uri, - newUri: workspacePath('sub', 'newDoc.md'), - }, { - uri: uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 7, 0, 15), './sub/newDoc.md'), - new vscode.TextEdit(new vscode.Range(1, 7, 1, 15), './sub/newDoc.md'), - ] - }); - })); - - test('Path rename using absolute file path should anchor to workspace root', withStore(async (store) => { - const uri = workspacePath('sub', 'doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[text](/sub/doc.md)`, - `[ref]: /sub/doc.md`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const edit = await getRenameEdits(store, doc, new vscode.Position(0, 10), '/newSub/newDoc.md', workspace); - assertEditsEqual(edit!, { - originalUri: uri, - newUri: workspacePath('newSub', 'newDoc.md'), - }, { - uri: uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 7, 0, 18), '/newSub/newDoc.md'), - new vscode.TextEdit(new vscode.Range(1, 7, 1, 18), '/newSub/newDoc.md'), - ] - }); - })); - - test('Path rename should use un-encoded paths as placeholder', withStore(async (store) => { - const uri = workspacePath('sub', 'doc with spaces.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[text](/sub/doc%20with%20spaces.md)`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const info = await prepareRename(store, doc, new vscode.Position(0, 10), workspace); - assert.strictEqual(info!.placeholder, '/sub/doc with spaces.md'); - })); - - test('Path rename should encode paths', withStore(async (store) => { - const uri = workspacePath('sub', 'doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[text](/sub/doc.md)`, - `[ref]: /sub/doc.md`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const edit = await getRenameEdits(store, doc, new vscode.Position(0, 10), '/NEW sub/new DOC.md', workspace); - assertEditsEqual(edit!, { - originalUri: uri, - newUri: workspacePath('NEW sub', 'new DOC.md'), - }, { - uri: uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 7, 0, 18), '/NEW%20sub/new%20DOC.md'), - new vscode.TextEdit(new vscode.Range(1, 7, 1, 18), '/NEW%20sub/new%20DOC.md'), - ] - }); - })); - - test('Path rename should work with unknown files', withStore(async (store) => { - const uri1 = workspacePath('doc1.md'); - const doc1 = new InMemoryDocument(uri1, joinLines( - `![img](/images/more/image.png)`, - ``, - `[ref]: /images/more/image.png`, - )); - - const uri2 = workspacePath('sub', 'doc2.md'); - const doc2 = new InMemoryDocument(uri2, joinLines( - `![img](/images/more/image.png)`, - )); - - const workspace = store.add(new InMemoryMdWorkspace([ - doc1, - doc2 - ])); - - const edit = await getRenameEdits(store, doc1, new vscode.Position(0, 10), '/img/test/new.png', workspace); - assertEditsEqual(edit!, - // Should not have file edits since the files don't exist here - { - uri: uri1, edits: [ - new vscode.TextEdit(new vscode.Range(0, 7, 0, 29), '/img/test/new.png'), - new vscode.TextEdit(new vscode.Range(2, 7, 2, 29), '/img/test/new.png'), - ] - }, - { - uri: uri2, edits: [ - new vscode.TextEdit(new vscode.Range(0, 7, 0, 29), '/img/test/new.png'), - ] - }); - })); - - test('Path rename should use .md extension on extension-less link', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[text](/doc#header)`, - `[ref]: /doc#other`, - )); - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const edit = await getRenameEdits(store, doc, new vscode.Position(0, 10), '/new File', workspace); - assertEditsEqual(edit!, { - originalUri: uri, - newUri: workspacePath('new File.md'), // Rename on disk should use file extension - }, { - uri: uri, edits: [ - new vscode.TextEdit(new vscode.Range(0, 7, 0, 11), '/new%20File'), // Links should continue to use extension-less paths - new vscode.TextEdit(new vscode.Range(1, 7, 1, 11), '/new%20File'), - ] - }); - })); - - // TODO: fails on windows - test.skip('Path rename should use correctly resolved paths across files', withStore(async (store) => { - const uri1 = workspacePath('sub', 'doc.md'); - const doc1 = new InMemoryDocument(uri1, joinLines( - `[text](./doc.md)`, - `[ref]: ./doc.md`, - )); - - const uri2 = workspacePath('doc2.md'); - const doc2 = new InMemoryDocument(uri2, joinLines( - `[text](./sub/doc.md)`, - `[ref]: ./sub/doc.md`, - )); - - const uri3 = workspacePath('sub2', 'doc3.md'); - const doc3 = new InMemoryDocument(uri3, joinLines( - `[text](../sub/doc.md)`, - `[ref]: ../sub/doc.md`, - )); - - const uri4 = workspacePath('sub2', 'doc4.md'); - const doc4 = new InMemoryDocument(uri4, joinLines( - `[text](/sub/doc.md)`, - `[ref]: /sub/doc.md`, - )); - - const workspace = store.add(new InMemoryMdWorkspace([ - doc1, doc2, doc3, doc4, - ])); - - const edit = await getRenameEdits(store, doc1, new vscode.Position(0, 10), './new/new-doc.md', workspace); - assertEditsEqual(edit!, { - originalUri: uri1, - newUri: workspacePath('sub', 'new', 'new-doc.md'), - }, { - uri: uri1, edits: [ - new vscode.TextEdit(new vscode.Range(0, 7, 0, 15), './new/new-doc.md'), - new vscode.TextEdit(new vscode.Range(1, 7, 1, 15), './new/new-doc.md'), - ] - }, { - uri: uri2, edits: [ - new vscode.TextEdit(new vscode.Range(0, 7, 0, 19), './sub/new/new-doc.md'), - new vscode.TextEdit(new vscode.Range(1, 7, 1, 19), './sub/new/new-doc.md'), - ] - }, { - uri: uri3, edits: [ - new vscode.TextEdit(new vscode.Range(0, 7, 0, 20), '../sub/new/new-doc.md'), - new vscode.TextEdit(new vscode.Range(1, 7, 1, 20), '../sub/new/new-doc.md'), - ] - }, { - uri: uri4, edits: [ - new vscode.TextEdit(new vscode.Range(0, 7, 0, 18), '/sub/new/new-doc.md'), - new vscode.TextEdit(new vscode.Range(1, 7, 1, 18), '/sub/new/new-doc.md'), - ] - }); - })); - - test('Path rename should resolve on links without prefix', withStore(async (store) => { - const uri1 = workspacePath('sub', 'doc.md'); - const doc1 = new InMemoryDocument(uri1, joinLines( - `![text](sub2/doc3.md)`, - )); - - const uri2 = workspacePath('doc2.md'); - const doc2 = new InMemoryDocument(uri2, joinLines( - `![text](sub/sub2/doc3.md)`, - )); - - const uri3 = workspacePath('sub', 'sub2', 'doc3.md'); - const doc3 = new InMemoryDocument(uri3, joinLines()); - - const workspace = store.add(new InMemoryMdWorkspace([ - doc1, doc2, doc3 - ])); - - const edit = await getRenameEdits(store, doc1, new vscode.Position(0, 10), 'sub2/cat.md', workspace); - assertEditsEqual(edit!, { - originalUri: workspacePath('sub', 'sub2', 'doc3.md'), - newUri: workspacePath('sub', 'sub2', 'cat.md'), - }, { - uri: uri1, edits: [new vscode.TextEdit(new vscode.Range(0, 8, 0, 20), 'sub2/cat.md')] - }, { - uri: uri2, edits: [new vscode.TextEdit(new vscode.Range(0, 8, 0, 24), 'sub/sub2/cat.md')] - }); - })); - - test('Rename on link should use header text as placeholder', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `### a B c ###`, - `[text](#a-b-c)`, - )); - - const workspace = store.add(new InMemoryMdWorkspace([doc])); - const info = await prepareRename(store, doc, new vscode.Position(1, 10), workspace); - assert.strictEqual(info!.placeholder, 'a B c'); - assertRangeEqual(info!.range, new vscode.Range(1, 8, 1, 13)); - })); - - test('Rename on http uri should work', withStore(async (store) => { - const uri1 = workspacePath('doc.md'); - const uri2 = workspacePath('doc2.md'); - const doc = new InMemoryDocument(uri1, joinLines( - `[1](http://example.com)`, - `[2]: http://example.com`, - ``, - )); - - const workspace = store.add(new InMemoryMdWorkspace([ - doc, - new InMemoryDocument(uri2, joinLines( - `[4](http://example.com)` - )) - ])); - - const edit = await getRenameEdits(store, doc, new vscode.Position(1, 10), "https://example.com/sub", workspace); - assertEditsEqual(edit!, { - uri: uri1, edits: [ - new vscode.TextEdit(new vscode.Range(0, 4, 0, 22), 'https://example.com/sub'), - new vscode.TextEdit(new vscode.Range(1, 5, 1, 23), 'https://example.com/sub'), - new vscode.TextEdit(new vscode.Range(2, 1, 2, 19), 'https://example.com/sub'), - ] - }, { - uri: uri2, edits: [ - new vscode.TextEdit(new vscode.Range(0, 4, 0, 22), 'https://example.com/sub'), - ] - }); - })); - - test('Rename on definition path should update all references to path', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[ref text][ref]`, - `[direct](/file)`, - `[ref]: /file`, // rename here - )); - - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const preparedInfo = await prepareRename(store, doc, new vscode.Position(2, 10), workspace); - assert.strictEqual(preparedInfo!.placeholder, '/file'); - assertRangeEqual(preparedInfo!.range, new vscode.Range(2, 7, 2, 12)); - - const edit = await getRenameEdits(store, doc, new vscode.Position(2, 10), "/newFile", workspace); - assertEditsEqual(edit!, { - uri, edits: [ - new vscode.TextEdit(new vscode.Range(1, 9, 1, 14), '/newFile'), - new vscode.TextEdit(new vscode.Range(2, 7, 2, 12), '/newFile'), - ] - }); - })); - - test('Rename on definition path where file exists should also update file', withStore(async (store) => { - const uri1 = workspacePath('doc.md'); - const doc1 = new InMemoryDocument(uri1, joinLines( - `[ref text][ref]`, - `[direct](/doc2)`, - `[ref]: /doc2`, // rename here - )); - - const uri2 = workspacePath('doc2.md'); - const doc2 = new InMemoryDocument(uri2, joinLines()); - - const workspace = store.add(new InMemoryMdWorkspace([doc1, doc2])); - - const preparedInfo = await prepareRename(store, doc1, new vscode.Position(2, 10), workspace); - assert.strictEqual(preparedInfo!.placeholder, '/doc2'); - assertRangeEqual(preparedInfo!.range, new vscode.Range(2, 7, 2, 12)); - - const edit = await getRenameEdits(store, doc1, new vscode.Position(2, 10), "/new-doc", workspace); - assertEditsEqual(edit!, { - uri: uri1, edits: [ - new vscode.TextEdit(new vscode.Range(1, 9, 1, 14), '/new-doc'), - new vscode.TextEdit(new vscode.Range(2, 7, 2, 12), '/new-doc'), - ] - }, { - originalUri: uri2, - newUri: workspacePath('new-doc.md') - }); - })); - - test('Rename on definition path header should update all references to header', withStore(async (store) => { - const uri = workspacePath('doc.md'); - const doc = new InMemoryDocument(uri, joinLines( - `[ref text][ref]`, - `[direct](/file#header)`, - `[ref]: /file#header`, // rename here - )); - - const workspace = store.add(new InMemoryMdWorkspace([doc])); - - const preparedInfo = await prepareRename(store, doc, new vscode.Position(2, 16), workspace); - assert.strictEqual(preparedInfo!.placeholder, 'header'); - assertRangeEqual(preparedInfo!.range, new vscode.Range(2, 13, 2, 19)); - - const edit = await getRenameEdits(store, doc, new vscode.Position(2, 16), "New Header", workspace); - assertEditsEqual(edit!, { - uri, edits: [ - new vscode.TextEdit(new vscode.Range(1, 15, 1, 21), 'new-header'), - new vscode.TextEdit(new vscode.Range(2, 13, 2, 19), 'new-header'), - ] - }); - })); -}); diff --git a/extensions/markdown-language-features/yarn.lock b/extensions/markdown-language-features/yarn.lock index 13eeca2f9da3f..12c6af02b5fb3 100644 --- a/extensions/markdown-language-features/yarn.lock +++ b/extensions/markdown-language-features/yarn.lock @@ -242,6 +242,11 @@ vscode-languageserver-types@3.17.1: resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.1.tgz#c2d87fa7784f8cac389deb3ff1e2d9a7bef07e16" integrity sha512-K3HqVRPElLZVVPtMeKlsyL9aK0GxGQpvtAUTfX4k7+iJ4mc1M+JM+zQwkgGy2LzY0f0IAafe8MKqIkJrxfGGjQ== +vscode-languageserver-types@^3.17.2: + version "3.17.2" + resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.2.tgz#b2c2e7de405ad3d73a883e91989b850170ffc4f2" + integrity sha512-zHhCWatviizPIq9B7Vh9uvrH6x3sK8itC84HkamnBWoDFJtzBf7SWlpLCZUit72b3os45h6RWQNC9xHRDF8dRA== + vscode-nls@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-5.0.0.tgz#99f0da0bd9ea7cda44e565a74c54b1f2bc257840" From 60c34692f2f8d6cc94724cfa1912b3eef8d6cdf9 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Thu, 14 Jul 2022 02:34:23 -0400 Subject: [PATCH 043/121] Throw error on legacy walkthrough (#155104) Remove old walkthrough format --- .../browser/gettingStartedService.ts | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedService.ts b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedService.ts index dcbddfc40971e..210f171d0a8aa 100644 --- a/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedService.ts +++ b/src/vs/workbench/contrib/welcomeGettingStarted/browser/gettingStartedService.ts @@ -364,28 +364,14 @@ export class WalkthroughsService extends Disposable implements IWalkthroughsServ }; } - // Legacy media config (only in use by remote-wsl at the moment) + // Throw error for unknown walkthrough format else { - const legacyMedia = step.media as unknown as { path: string; altText: string }; - if (typeof legacyMedia.path === 'string' && legacyMedia.path.endsWith('.md')) { - media = { - type: 'markdown', - path: convertExtensionPathToFileURI(legacyMedia.path), - base: convertExtensionPathToFileURI(dirname(legacyMedia.path)), - root: FileAccess.asFileUri(extension.extensionLocation), - }; - } - else { - const altText = legacyMedia.altText; - if (altText === undefined) { - console.error('Walkthrough item:', fullyQualifiedID, 'is missing altText for its media element.'); - } - media = { type: 'image', altText, path: convertExtensionRelativePathsToBrowserURIs(legacyMedia.path) }; - } + throw new Error('Unknown walkthrough format detected for ' + fullyQualifiedID); } return ({ - description, media, + description, + media, completionEvents: step.completionEvents?.filter(x => typeof x === 'string') ?? [], id: fullyQualifiedID, title: step.title, From cad9ba5f29fe387387427ed59af5da709d5a3c28 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Thu, 14 Jul 2022 09:24:12 +0200 Subject: [PATCH 044/121] add application to restricted settings (#155143) --- .../services/configuration/browser/configurationService.ts | 5 +++++ .../workbench/services/configuration/common/configuration.ts | 1 + 2 files changed, 6 insertions(+) diff --git a/src/vs/workbench/services/configuration/browser/configurationService.ts b/src/vs/workbench/services/configuration/browser/configurationService.ts index bba9911a15878..3dc4ea6419e7c 100644 --- a/src/vs/workbench/services/configuration/browser/configurationService.ts +++ b/src/vs/workbench/services/configuration/browser/configurationService.ts @@ -833,6 +833,10 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat const defaultDelta = delta(defaultRestrictedSettings, this._restrictedSettings.default, (a, b) => a.localeCompare(b)); changed.push(...defaultDelta.added, ...defaultDelta.removed); + const application = (this.applicationConfiguration?.getRestrictedSettings() || []).sort((a, b) => a.localeCompare(b)); + const applicationDelta = delta(application, this._restrictedSettings.application || [], (a, b) => a.localeCompare(b)); + changed.push(...applicationDelta.added, ...applicationDelta.removed); + const userLocal = this.localUserConfiguration.getRestrictedSettings().sort((a, b) => a.localeCompare(b)); const userLocalDelta = delta(userLocal, this._restrictedSettings.userLocal || [], (a, b) => a.localeCompare(b)); changed.push(...userLocalDelta.added, ...userLocalDelta.removed); @@ -861,6 +865,7 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat if (changed.length) { this._restrictedSettings = { default: defaultRestrictedSettings, + application: application.length ? application : undefined, userLocal: userLocal.length ? userLocal : undefined, userRemote: userRemote.length ? userRemote : undefined, workspace: workspace.length ? workspace : undefined, diff --git a/src/vs/workbench/services/configuration/common/configuration.ts b/src/vs/workbench/services/configuration/common/configuration.ts index 0b625da7565c5..26e00008c87e8 100644 --- a/src/vs/workbench/services/configuration/common/configuration.ts +++ b/src/vs/workbench/services/configuration/common/configuration.ts @@ -53,6 +53,7 @@ export interface IConfigurationCache { export type RestrictedSettings = { default: ReadonlyArray; + application?: ReadonlyArray; userLocal?: ReadonlyArray; userRemote?: ReadonlyArray; workspace?: ReadonlyArray; From 363ba649f5ac317fa628ee60ef4aef841ef0a930 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 14 Jul 2022 10:07:21 +0200 Subject: [PATCH 045/121] electron - drop support for `disable-color-correct-rendering` (#155150) --- src/main.js | 13 ++----------- .../electron-sandbox/desktop.contribution.ts | 4 ---- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/main.js b/src/main.js index 47f22e9909f7c..c53900217a453 100644 --- a/src/main.js +++ b/src/main.js @@ -153,9 +153,6 @@ function configureCommandlineSwitchesSync(cliArgs) { // alias from us for --disable-gpu 'disable-hardware-acceleration', - // provided by Electron - 'disable-color-correct-rendering', - // override for the color profile to use 'force-color-profile' ]; @@ -247,9 +244,7 @@ function readArgvConfigSync() { // Fallback to default if (!argvConfig) { - argvConfig = { - 'disable-color-correct-rendering': true // Force pre-Chrome-60 color profile handling (for https://github.com/microsoft/vscode/issues/51791) - }; + argvConfig = {}; } return argvConfig; @@ -279,11 +274,7 @@ function createDefaultArgvConfigSync(argvConfigPath) { '{', ' // Use software rendering instead of hardware accelerated rendering.', ' // This can help in cases where you see rendering issues in VS Code.', - ' // "disable-hardware-acceleration": true,', - '', - ' // Enabled by default by VS Code to resolve color issues in the renderer', - ' // See https://github.com/microsoft/vscode/issues/51791 for details', - ' "disable-color-correct-rendering": true', + ' // "disable-hardware-acceleration": true', '}' ]; diff --git a/src/vs/workbench/electron-sandbox/desktop.contribution.ts b/src/vs/workbench/electron-sandbox/desktop.contribution.ts index f105e0ce3082a..1dd0c84873b3b 100644 --- a/src/vs/workbench/electron-sandbox/desktop.contribution.ts +++ b/src/vs/workbench/electron-sandbox/desktop.contribution.ts @@ -310,10 +310,6 @@ import { ModifierKeyEmitter } from 'vs/base/browser/dom'; type: 'boolean', description: localize('argv.disableHardwareAcceleration', 'Disables hardware acceleration. ONLY change this option if you encounter graphic issues.') }, - 'disable-color-correct-rendering': { - type: 'boolean', - description: localize('argv.disableColorCorrectRendering', 'Resolves issues around color profile selection. ONLY change this option if you encounter graphic issues.') - }, 'force-color-profile': { type: 'string', markdownDescription: localize('argv.forceColorProfile', 'Allows to override the color profile to use. If you experience colors appear badly, try to set this to `srgb` and restart.') From 7dc714f9a7635eddaa572cd68ccb6b1c44fd429c Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Thu, 14 Jul 2022 10:46:57 +0200 Subject: [PATCH 046/121] Git - Add events to IPostCommitCommandsProviderRegistry (#155051) * Add events to IPostCommitCommandsProviderRegistry * Pull request feedback --- extensions/git/src/actionButton.ts | 2 ++ extensions/git/src/model.ts | 9 ++++++++- extensions/git/src/postCommitCommands.ts | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/extensions/git/src/actionButton.ts b/extensions/git/src/actionButton.ts index 311e9dc84d500..84c75067e3e57 100644 --- a/extensions/git/src/actionButton.ts +++ b/extensions/git/src/actionButton.ts @@ -50,6 +50,8 @@ export class ActionButtonCommand { repository.onDidRunGitStatus(this.onDidRunGitStatus, this, this.disposables); repository.onDidChangeOperations(this.onDidChangeOperations, this, this.disposables); + this.disposables.push(postCommitCommandsProviderRegistry.onDidChangePostCommitCommandsProviders(() => this._onDidChange.fire())); + const root = Uri.file(repository.root); this.disposables.push(workspace.onDidChangeConfiguration(e => { if (e.affectsConfiguration('git.enableSmartCommit', root) || diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index 505ceeb16c06a..5fc1b4d06acb2 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -108,6 +108,9 @@ export class Model implements IRemoteSourcePublisherRegistry, IPostCommitCommand private postCommitCommandsProviders = new Set(); + private _onDidChangePostCommitCommandsProviders = new EventEmitter(); + readonly onDidChangePostCommitCommandsProviders = this._onDidChangePostCommitCommandsProviders.event; + private showRepoOnHomeDriveRootWarning = true; private pushErrorHandlers = new Set(); @@ -591,8 +594,12 @@ export class Model implements IRemoteSourcePublisherRegistry, IPostCommitCommand registerPostCommitCommandsProvider(provider: PostCommitCommandsProvider): Disposable { this.postCommitCommandsProviders.add(provider); + this._onDidChangePostCommitCommandsProviders.fire(); - return toDisposable(() => this.postCommitCommandsProviders.delete(provider)); + return toDisposable(() => { + this.postCommitCommandsProviders.delete(provider); + this._onDidChangePostCommitCommandsProviders.fire(); + }); } getPostCommitCommandsProviders(): PostCommitCommandsProvider[] { diff --git a/extensions/git/src/postCommitCommands.ts b/extensions/git/src/postCommitCommands.ts index 2fd6dc5676b84..85d1689011a46 100644 --- a/extensions/git/src/postCommitCommands.ts +++ b/extensions/git/src/postCommitCommands.ts @@ -4,10 +4,12 @@ *--------------------------------------------------------------------------------------------*/ import * as nls from 'vscode-nls'; -import { Command, Disposable } from 'vscode'; +import { Command, Disposable, Event } from 'vscode'; import { PostCommitCommandsProvider } from './api/git'; export interface IPostCommitCommandsProviderRegistry { + readonly onDidChangePostCommitCommandsProviders: Event; + getPostCommitCommandsProviders(): PostCommitCommandsProvider[]; registerPostCommitCommandsProvider(provider: PostCommitCommandsProvider): Disposable; } From d2eeaf60f43b3844d46a8cfe9dbee1a9dbf9d5f9 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 14 Jul 2022 10:52:14 +0200 Subject: [PATCH 047/121] add 'Open File' command to merge editor title bar (#155159) fixes https://github.com/microsoft/vscode/issues/153690 --- .../mergeEditor/browser/commands/commands.ts | 31 +++++++++++++++++++ .../browser/mergeEditor.contribution.ts | 3 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/mergeEditor/browser/commands/commands.ts b/src/vs/workbench/contrib/mergeEditor/browser/commands/commands.ts index 892febf378ebb..2a0d776fb189b 100644 --- a/src/vs/workbench/contrib/mergeEditor/browser/commands/commands.ts +++ b/src/vs/workbench/contrib/mergeEditor/browser/commands/commands.ts @@ -167,6 +167,35 @@ const mergeEditorCategory: ILocalizedString = { original: 'Merge Editor', }; +export class OpenResultResource extends Action2 { + constructor() { + super({ + id: 'merge.openResult', + icon: Codicon.goToFile, + title: { + value: localize('openfile', 'Open File'), + original: 'Open File', + }, + category: mergeEditorCategory, + menu: [{ + id: MenuId.EditorTitle, + when: ctxIsMergeEditor, + group: 'navigation', + order: 1, + }], + precondition: ctxIsMergeEditor, + }); + } + + async run(accessor: ServicesAccessor): Promise { + const opener = accessor.get(IOpenerService); + const { activeEditor } = accessor.get(IEditorService); + if (activeEditor instanceof MergeEditorInput) { + await opener.open(activeEditor.result); + } + } +} + export class GoToNextConflict extends Action2 { constructor() { super({ @@ -182,6 +211,7 @@ export class GoToNextConflict extends Action2 { id: MenuId.EditorTitle, when: ctxIsMergeEditor, group: 'navigation', + order: 3 }, ], f1: true, @@ -215,6 +245,7 @@ export class GoToPreviousConflict extends Action2 { id: MenuId.EditorTitle, when: ctxIsMergeEditor, group: 'navigation', + order: 2 }, ], f1: true, diff --git a/src/vs/workbench/contrib/mergeEditor/browser/mergeEditor.contribution.ts b/src/vs/workbench/contrib/mergeEditor/browser/mergeEditor.contribution.ts index 09206f43520e0..cba7f643cecb0 100644 --- a/src/vs/workbench/contrib/mergeEditor/browser/mergeEditor.contribution.ts +++ b/src/vs/workbench/contrib/mergeEditor/browser/mergeEditor.contribution.ts @@ -10,7 +10,7 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { EditorPaneDescriptor, IEditorPaneRegistry } from 'vs/workbench/browser/editor'; import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; import { EditorExtensions, IEditorFactoryRegistry } from 'vs/workbench/common/editor'; -import { CompareInput1WithBaseCommand, CompareInput2WithBaseCommand, GoToNextConflict, GoToPreviousConflict, OpenBaseFile, OpenMergeEditor, SetColumnLayout, SetMixedLayout, ToggleActiveConflictInput1, ToggleActiveConflictInput2 } from 'vs/workbench/contrib/mergeEditor/browser/commands/commands'; +import { CompareInput1WithBaseCommand, CompareInput2WithBaseCommand, GoToNextConflict, GoToPreviousConflict, OpenBaseFile, OpenMergeEditor, OpenResultResource, SetColumnLayout, SetMixedLayout, ToggleActiveConflictInput1, ToggleActiveConflictInput2 } from 'vs/workbench/contrib/mergeEditor/browser/commands/commands'; import { MergeEditorCopyContentsToJSON, MergeEditorOpenContents } from 'vs/workbench/contrib/mergeEditor/browser/commands/devCommands'; import { MergeEditorInput } from 'vs/workbench/contrib/mergeEditor/browser/mergeEditorInput'; import { MergeEditor, MergeEditorOpenHandlerContribution } from 'vs/workbench/contrib/mergeEditor/browser/view/mergeEditor'; @@ -33,6 +33,7 @@ Registry.as(EditorExtensions.EditorFactory).registerEdit MergeEditorSerializer ); +registerAction2(OpenResultResource); registerAction2(SetMixedLayout); registerAction2(SetColumnLayout); registerAction2(OpenMergeEditor); From 8c6c17cf26d136e936e0ff1caa16dd67df505243 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Thu, 14 Jul 2022 08:55:29 +0200 Subject: [PATCH 048/121] Git - Use cloud icon for remote branches (#155140) Use cloud icon for remote branches --- extensions/git/src/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 4bbb17e5137b1..37c500f76054e 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -53,7 +53,7 @@ class CheckoutTagItem extends CheckoutItem { class CheckoutRemoteHeadItem extends CheckoutItem { - override get label(): string { return `$(git-branch) ${this.ref.name || this.shortCommit}`; } + override get label(): string { return `$(cloud) ${this.ref.name || this.shortCommit}`; } override get description(): string { return localize('remote branch at', "Remote branch at {0}", this.shortCommit); } From 7f000aceab7193dbf998edb10f45af24beb98ad6 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Thu, 14 Jul 2022 11:03:35 +0200 Subject: [PATCH 049/121] `MainThreadHostTreeView: [createInstance] First service dependency of CustomTreeView at position 4 conflicts with 2 static arguments` (#155160) Fixes #155155 --- src/vs/workbench/api/test/browser/mainThreadTreeViews.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/api/test/browser/mainThreadTreeViews.test.ts b/src/vs/workbench/api/test/browser/mainThreadTreeViews.test.ts index 1386a01b2348e..2c7906406f52e 100644 --- a/src/vs/workbench/api/test/browser/mainThreadTreeViews.test.ts +++ b/src/vs/workbench/api/test/browser/mainThreadTreeViews.test.ts @@ -57,7 +57,7 @@ suite('MainThreadHostTreeView', function () { id: testTreeViewId, ctorDescriptor: null!, name: 'Test View 1', - treeView: instantiationService.createInstance(CustomTreeView, 'testTree', 'Test Title'), + treeView: instantiationService.createInstance(CustomTreeView, 'testTree', 'Test Title', 'extension.id'), }; ViewsRegistry.registerViews([viewDescriptor], container); From 02c3d975d5777102d1ab08037cfd4285ed5ef5c4 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 14 Jul 2022 05:44:54 -0700 Subject: [PATCH 050/121] Fix link regex groups Fixes #155065 --- .../terminal/browser/links/terminalLocalLinkDetector.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/terminal/browser/links/terminalLocalLinkDetector.ts b/src/vs/workbench/contrib/terminal/browser/links/terminalLocalLinkDetector.ts index cec80cf90b197..a8452caf598ae 100644 --- a/src/vs/workbench/contrib/terminal/browser/links/terminalLocalLinkDetector.ts +++ b/src/vs/workbench/contrib/terminal/browser/links/terminalLocalLinkDetector.ts @@ -53,7 +53,8 @@ export const lineAndColumnClause = [ '((\\S*)[\'"], line ((\\d+)( column (\\d+))?))', // "(file path)", line 45 [see #40468] '((\\S*)[\'"],((\\d+)(:(\\d+))?))', // "(file path)",45 [see #78205] '((\\S*) on line ((\\d+)(, column (\\d+))?))', // (file path) on line 8, column 13 - '((\\S*):\\s?line ((\\d+)(, col(umn)? (\\d+))?))', // (file path):line 8, column 13, (file path): line 8, col 13 + '((\\S*):\\s?line ((\\d+)(, column (\\d+))?))', // (file path):line 8, column 13 + '((\\S*):\\s?line ((\\d+)(, col (\\d+))?))', // (file path): line 8, col 13 '(([^\\s\\(\\)]*)(\\s?[\\(\\[](\\d+)(,\\s?(\\d+))?)[\\)\\]])', // (file path)(45), (file path) (45), (file path)(45,18), (file path) (45,18), (file path)(45, 18), (file path) (45, 18), also with [] '(([^:\\s\\(\\)<>\'\"\\[\\]]*)(:(\\d+))?(:(\\d+))?)' // (file path):336, (file path):336:9 ].join('|').replace(/ /g, `[${'\u00A0'} ]`); From cda4ed9a6321c7d8c2e70d642765e378255182de Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 14 Jul 2022 14:29:42 +0200 Subject: [PATCH 051/121] tweak message when closing dirty and conflicting merge editor (#155176) fyi @bpasero this ensures the close handler is always called with `IEditorIdentifier[]` re https://github.com/microsoft/vscode/issues/152841 --- .../browser/parts/editor/editorGroupView.ts | 2 +- src/vs/workbench/common/editor/editorInput.ts | 6 +++--- .../mergeEditor/browser/mergeEditorInput.ts | 18 +++++++++++------- .../terminal/browser/terminalEditorInput.ts | 4 ++-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/editorGroupView.ts b/src/vs/workbench/browser/parts/editor/editorGroupView.ts index d2df00e4d5e39..29bfb9d670656 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupView.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupView.ts @@ -1555,7 +1555,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView { // Let editor handle confirmation if implemented if (typeof editor.closeHandler?.confirm === 'function') { - confirmation = await editor.closeHandler.confirm(); + confirmation = await editor.closeHandler.confirm([{ editor, groupId: this.id }]); } // Show a file specific confirmation diff --git a/src/vs/workbench/common/editor/editorInput.ts b/src/vs/workbench/common/editor/editorInput.ts index 86b53423c6062..33fb8d838249f 100644 --- a/src/vs/workbench/common/editor/editorInput.ts +++ b/src/vs/workbench/common/editor/editorInput.ts @@ -30,10 +30,10 @@ export interface IEditorCloseHandler { * should be used besides dirty state, this method should be * implemented to show a different dialog. * - * @param editors if more than one editor is closed, will pass in - * each editor of the same kind to be able to show a combined dialog. + * @param editors All editors of the same kind that are being closed. Should be used + * to show a combined dialog. */ - confirm(editors?: ReadonlyArray): Promise; + confirm(editors: ReadonlyArray): Promise; } /** diff --git a/src/vs/workbench/contrib/mergeEditor/browser/mergeEditorInput.ts b/src/vs/workbench/contrib/mergeEditor/browser/mergeEditorInput.ts index 4f29941dc13b6..864214ae21028 100644 --- a/src/vs/workbench/contrib/mergeEditor/browser/mergeEditorInput.ts +++ b/src/vs/workbench/contrib/mergeEditor/browser/mergeEditorInput.ts @@ -173,21 +173,25 @@ class MergeEditorCloseHandler implements IEditorCloseHandler { return !this._ignoreUnhandledConflicts && this._model.hasUnhandledConflicts.get(); } - async confirm(editors?: readonly IEditorIdentifier[] | undefined): Promise { + async confirm(editors: readonly IEditorIdentifier[]): Promise { - const handler: MergeEditorCloseHandler[] = [this]; - editors?.forEach(candidate => candidate.editor.closeHandler instanceof MergeEditorCloseHandler && handler.push(candidate.editor.closeHandler)); + const handler: MergeEditorCloseHandler[] = []; + let someAreDirty = false; - const inputsWithUnhandledConflicts = handler - .filter(input => input._model && input._model.hasUnhandledConflicts.get()); + for (const { editor } of editors) { + if (editor.closeHandler instanceof MergeEditorCloseHandler && editor.closeHandler._model.hasUnhandledConflicts.get()) { + handler.push(editor.closeHandler); + someAreDirty = someAreDirty || editor.isDirty(); + } + } - if (inputsWithUnhandledConflicts.length === 0) { + if (handler.length === 0) { // shouldn't happen return ConfirmResult.SAVE; } const actions: string[] = [ - localize('unhandledConflicts.ignore', "Continue with Conflicts"), + someAreDirty ? localize('unhandledConflicts.saveAndIgnore', "Save & Continue with Conflicts") : localize('unhandledConflicts.ignore', "Continue with Conflicts"), localize('unhandledConflicts.discard', "Discard Merge Changes"), localize('unhandledConflicts.cancel', "Cancel"), ]; diff --git a/src/vs/workbench/contrib/terminal/browser/terminalEditorInput.ts b/src/vs/workbench/contrib/terminal/browser/terminalEditorInput.ts index 55032336cd5a5..dd5684d1ad817 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalEditorInput.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalEditorInput.ts @@ -100,7 +100,7 @@ export class TerminalEditorInput extends EditorInput implements IEditorCloseHand return false; } - async confirm(terminals?: ReadonlyArray): Promise { + async confirm(terminals: ReadonlyArray): Promise { const { choice } = await this._dialogService.show( Severity.Warning, localize('confirmDirtyTerminal.message', "Do you want to terminate running processes?"), @@ -110,7 +110,7 @@ export class TerminalEditorInput extends EditorInput implements IEditorCloseHand ], { cancelId: 1, - detail: terminals && terminals.length > 1 ? + detail: terminals.length > 1 ? terminals.map(terminal => terminal.editor.getName()).join('\n') + '\n\n' + localize('confirmDirtyTerminals.detail', "Closing will terminate the running processes in the terminals.") : localize('confirmDirtyTerminal.detail', "Closing will terminate the running processes in this terminal.") } From 5e2848dcb5b0ac091b660d776f3d577f4641ebd5 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 14 Jul 2022 08:12:12 -0700 Subject: [PATCH 052/121] Use a non-capturing group to fix group indexes --- .../terminal/browser/links/terminalLocalLinkDetector.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/links/terminalLocalLinkDetector.ts b/src/vs/workbench/contrib/terminal/browser/links/terminalLocalLinkDetector.ts index a8452caf598ae..dd4e98400043d 100644 --- a/src/vs/workbench/contrib/terminal/browser/links/terminalLocalLinkDetector.ts +++ b/src/vs/workbench/contrib/terminal/browser/links/terminalLocalLinkDetector.ts @@ -53,8 +53,7 @@ export const lineAndColumnClause = [ '((\\S*)[\'"], line ((\\d+)( column (\\d+))?))', // "(file path)", line 45 [see #40468] '((\\S*)[\'"],((\\d+)(:(\\d+))?))', // "(file path)",45 [see #78205] '((\\S*) on line ((\\d+)(, column (\\d+))?))', // (file path) on line 8, column 13 - '((\\S*):\\s?line ((\\d+)(, column (\\d+))?))', // (file path):line 8, column 13 - '((\\S*):\\s?line ((\\d+)(, col (\\d+))?))', // (file path): line 8, col 13 + '((\\S*):\\s?line ((\\d+)(, col(?:umn)? (\\d+))?))', // (file path):line 8, column 13, (file path): line 8, col 13 '(([^\\s\\(\\)]*)(\\s?[\\(\\[](\\d+)(,\\s?(\\d+))?)[\\)\\]])', // (file path)(45), (file path) (45), (file path)(45,18), (file path) (45,18), (file path)(45, 18), (file path) (45, 18), also with [] '(([^:\\s\\(\\)<>\'\"\\[\\]]*)(:(\\d+))?(:(\\d+))?)' // (file path):336, (file path):336:9 ].join('|').replace(/ /g, `[${'\u00A0'} ]`); From fbe5941993438fe4f45af8db4cb94297ed3dc4d2 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Thu, 14 Jul 2022 09:08:33 -0400 Subject: [PATCH 053/121] Polish New File... based on feedback (#155115) --- src/vs/workbench/contrib/files/browser/fileCommands.ts | 2 +- .../contrib/welcomeViews/common/newFile.contribution.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/files/browser/fileCommands.ts b/src/vs/workbench/contrib/files/browser/fileCommands.ts index 0cea70cc9102a..d3ae1ad9f6ba5 100644 --- a/src/vs/workbench/contrib/files/browser/fileCommands.ts +++ b/src/vs/workbench/contrib/files/browser/fileCommands.ts @@ -651,7 +651,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ const editorService = accessor.get(IEditorService); await editorService.openEditor({ - resource: args?.path ? URI.from({ scheme: Schemas.untitled, path: `Untitled-${args.path}` }) : undefined, + resource: args?.path ? URI.from({ scheme: Schemas.untitled, path: args.path }) : undefined, options: { override: args?.viewType, pinned: true diff --git a/src/vs/workbench/contrib/welcomeViews/common/newFile.contribution.ts b/src/vs/workbench/contrib/welcomeViews/common/newFile.contribution.ts index 02106a3341c46..9bbe2ed1d272a 100644 --- a/src/vs/workbench/contrib/welcomeViews/common/newFile.contribution.ts +++ b/src/vs/workbench/contrib/welcomeViews/common/newFile.contribution.ts @@ -164,6 +164,7 @@ class NewFileTemplatesManager extends Disposable { disposables.add(qp.onDidChangeValue((val: string) => { if (val === '') { + refreshQp(entries); return; } const currentTextEntry: NewFileItem = { From 5bf385f3df45cd7ee84eb8c9a34570b2ab011173 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Thu, 14 Jul 2022 15:51:47 +0200 Subject: [PATCH 054/121] Sync Changes button - only show when local branch is ahead/behind the remote branch (#155192) Only show Sync Changes button when local branch is ahead/behind the remote branch --- extensions/git/package.nls.json | 8 ++++---- extensions/git/src/actionButton.ts | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 2477a55fa76e5..cc9f4a8c1d311 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -221,10 +221,10 @@ "config.timeline.date.committed": "Use the committed date", "config.timeline.date.authored": "Use the authored date", "config.useCommitInputAsStashMessage": "Controls whether to use the message from the commit input box as the default stash message.", - "config.showActionButton": "Controls whether an action button can be shown in the Source Control view.", - "config.showActionButton.commit": "Show an action button to commit changes.", - "config.showActionButton.publish": "Show an action button to publish a local branch.", - "config.showActionButton.sync": "Show an action button to sync changes.", + "config.showActionButton": "Controls whether an action button is shown in the Source Control view.", + "config.showActionButton.commit": "Show an action button to commit changes when the local branch has modified files ready to be committed.", + "config.showActionButton.publish": "Show an action button to publish the local branch when it does not have a tracking remote branch.", + "config.showActionButton.sync": "Show an action button to synchronize changes when the local branch is either ahead or behind the remote branch.", "config.statusLimit": "Controls how to limit the number of changes that can be parsed from Git status command. Can be set to 0 for no limit.", "config.experimental.installGuide": "Experimental improvements for the git setup flow.", "config.repositoryScanIgnoredFolders": "List of folders that are ignored while scanning for Git repositories when `#git.autoRepositoryDetection#` is set to `true` or `subFolders`.", diff --git a/extensions/git/src/actionButton.ts b/extensions/git/src/actionButton.ts index 84c75067e3e57..0695869be35e0 100644 --- a/extensions/git/src/actionButton.ts +++ b/extensions/git/src/actionButton.ts @@ -204,9 +204,10 @@ export class ActionButtonCommand { private getSyncChangesActionButton(): SourceControlActionButton | undefined { const config = workspace.getConfiguration('git', Uri.file(this.repository.root)); const showActionButton = config.get<{ sync: boolean }>('showActionButton', { sync: true }); + const branchIsAheadOrBehind = (this.state.HEAD?.behind ?? 0) > 0 || (this.state.HEAD?.ahead ?? 0) > 0; - // Branch does not have an upstream, commit/merge is in progress, or the button is disabled - if (!this.state.HEAD?.upstream || this.state.isCommitInProgress || this.state.isMergeInProgress || !showActionButton.sync) { return undefined; } + // Branch does not have an upstream, branch is not ahead/behind the remote branch, commit/merge is in progress, or the button is disabled + if (!this.state.HEAD?.upstream || !branchIsAheadOrBehind || this.state.isCommitInProgress || this.state.isMergeInProgress || !showActionButton.sync) { return undefined; } const ahead = this.state.HEAD.ahead ? ` ${this.state.HEAD.ahead}$(arrow-up)` : ''; const behind = this.state.HEAD.behind ? ` ${this.state.HEAD.behind}$(arrow-down)` : ''; From a801dde2459003fd3ef3f6125867b678112f8105 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Thu, 14 Jul 2022 16:04:00 +0200 Subject: [PATCH 055/121] add clear display language action (#155194) --- .../extensions/browser/extensionEditor.ts | 5 +- .../browser/extensions.contribution.ts | 20 +++++++- .../extensions/browser/extensionsActions.ts | 50 +++++++++++++++++-- .../browser/media/extensionActions.css | 1 + 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/contrib/extensions/browser/extensionEditor.ts b/src/vs/workbench/contrib/extensions/browser/extensionEditor.ts index c8632a19ecbec..d155971ec3aca 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionEditor.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionEditor.ts @@ -29,7 +29,7 @@ import { UpdateAction, ReloadAction, EnableDropDownAction, DisableDropDownAction, ExtensionStatusLabelAction, SetFileIconThemeAction, SetColorThemeAction, RemoteInstallAction, ExtensionStatusAction, LocalInstallAction, ToggleSyncExtensionAction, SetProductIconThemeAction, ActionWithDropDownAction, InstallDropdownAction, InstallingLabelAction, UninstallAction, ExtensionActionWithDropdownActionViewItem, ExtensionDropDownAction, - InstallAnotherVersionAction, ExtensionEditorManageExtensionAction, WebInstallAction, SwitchToPreReleaseVersionAction, SwitchToReleasedVersionAction, MigrateDeprecatedExtensionAction, SetLanguageAction + InstallAnotherVersionAction, ExtensionEditorManageExtensionAction, WebInstallAction, SwitchToPreReleaseVersionAction, SwitchToReleasedVersionAction, MigrateDeprecatedExtensionAction, SetLanguageAction, ClearLanguageAction } from 'vs/workbench/contrib/extensions/browser/extensionsActions'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement'; @@ -326,10 +326,11 @@ export class ExtensionEditor extends EditorPane { this.instantiationService.createInstance(SetColorThemeAction), this.instantiationService.createInstance(SetFileIconThemeAction), this.instantiationService.createInstance(SetProductIconThemeAction), + this.instantiationService.createInstance(SetLanguageAction), + this.instantiationService.createInstance(ClearLanguageAction), this.instantiationService.createInstance(EnableDropDownAction), this.instantiationService.createInstance(DisableDropDownAction), - this.instantiationService.createInstance(SetLanguageAction), this.instantiationService.createInstance(RemoteInstallAction, false), this.instantiationService.createInstance(LocalInstallAction), this.instantiationService.createInstance(WebInstallAction), diff --git a/src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts b/src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts index f53f6a7de8a31..13edddae38d1c 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts @@ -15,7 +15,7 @@ import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWo import { IOutputChannelRegistry, Extensions as OutputExtensions } from 'vs/workbench/services/output/common/output'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { VIEWLET_ID, IExtensionsWorkbenchService, IExtensionsViewPaneContainer, TOGGLE_IGNORE_EXTENSION_ACTION_ID, INSTALL_EXTENSION_FROM_VSIX_COMMAND_ID, DefaultViewsContext, ExtensionsSortByContext, WORKSPACE_RECOMMENDATIONS_VIEW_ID, IWorkspaceRecommendedExtensionsView, AutoUpdateConfigurationKey, HasOutdatedExtensionsContext, SELECT_INSTALL_VSIX_EXTENSION_COMMAND_ID, LIST_WORKSPACE_UNSUPPORTED_EXTENSIONS_COMMAND_ID, ExtensionEditorTab, THEME_ACTIONS_GROUP, INSTALL_ACTIONS_GROUP } from 'vs/workbench/contrib/extensions/common/extensions'; -import { ReinstallAction, InstallSpecificVersionOfExtensionAction, ConfigureWorkspaceRecommendedExtensionsAction, ConfigureWorkspaceFolderRecommendedExtensionsAction, PromptExtensionInstallFailureAction, SearchExtensionsAction, SwitchToPreReleaseVersionAction, SwitchToReleasedVersionAction, SetColorThemeAction, SetFileIconThemeAction, SetProductIconThemeAction } from 'vs/workbench/contrib/extensions/browser/extensionsActions'; +import { ReinstallAction, InstallSpecificVersionOfExtensionAction, ConfigureWorkspaceRecommendedExtensionsAction, ConfigureWorkspaceFolderRecommendedExtensionsAction, PromptExtensionInstallFailureAction, SearchExtensionsAction, SwitchToPreReleaseVersionAction, SwitchToReleasedVersionAction, SetColorThemeAction, SetFileIconThemeAction, SetProductIconThemeAction, ClearLanguageAction } from 'vs/workbench/contrib/extensions/browser/extensionsActions'; import { ExtensionsInput } from 'vs/workbench/contrib/extensions/common/extensionsInput'; import { ExtensionEditor } from 'vs/workbench/contrib/extensions/browser/extensionEditor'; import { StatusUpdater, MaliciousExtensionChecker, ExtensionsViewletViewsContribution, ExtensionsViewPaneContainer } from 'vs/workbench/contrib/extensions/browser/extensionsViewlet'; @@ -1339,6 +1339,24 @@ class ExtensionsContributions extends Disposable implements IWorkbenchContributi } } }); + this.registerExtensionAction({ + id: ClearLanguageAction.ID, + title: ClearLanguageAction.TITLE, + menu: { + id: MenuId.ExtensionContext, + group: INSTALL_ACTIONS_GROUP, + order: 0, + when: ContextKeyExpr.and(ContextKeyExpr.not('inExtensionEditor'), ContextKeyExpr.has('canSetLanguage'), ContextKeyExpr.has('isActiveLanguagePackExtension')) + }, + run: async (accessor: ServicesAccessor, extensionId: string) => { + const instantiationService = accessor.get(IInstantiationService); + const extensionsWorkbenchService = accessor.get(IExtensionsWorkbenchService); + const extension = (await extensionsWorkbenchService.getExtensions([{ id: extensionId }], CancellationToken.None))[0]; + const action = instantiationService.createInstance(ClearLanguageAction); + action.extension = extension; + return action.run(); + } + }); this.registerExtensionAction({ id: 'workbench.extensions.action.copyExtension', diff --git a/src/vs/workbench/contrib/extensions/browser/extensionsActions.ts b/src/vs/workbench/contrib/extensions/browser/extensionsActions.ts index 23ddb1a771cab..d2247bf251978 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionsActions.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionsActions.ts @@ -67,6 +67,7 @@ import { flatten } from 'vs/base/common/arrays'; import { fromNow } from 'vs/base/common/date'; import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences'; import { ILanguagePackService } from 'vs/platform/languagePacks/common/languagePacks'; +import { ILocaleService } from 'vs/workbench/contrib/localization/common/locale'; export class PromptExtensionInstallFailureAction extends Action { @@ -981,6 +982,8 @@ export class DropDownMenuActionViewItem extends ActionViewItem { async function getContextMenuActionsGroups(extension: IExtension | undefined | null, contextKeyService: IContextKeyService, instantiationService: IInstantiationService): Promise<[string, Array][]> { return instantiationService.invokeFunction(async accessor => { + const extensionsWorkbenchService = accessor.get(IExtensionsWorkbenchService); + const languagePackService = accessor.get(ILanguagePackService); const menuService = accessor.get(IMenuService); const extensionRecommendationsService = accessor.get(IExtensionRecommendationsService); const extensionIgnoredRecommendationsService = accessor.get(IExtensionIgnoredRecommendationsService); @@ -1006,6 +1009,9 @@ async function getContextMenuActionsGroups(extension: IExtension | undefined | n cksOverlay.push(['extensionHasColorThemes', colorThemes.some(theme => isThemeFromExtension(theme, extension))]); cksOverlay.push(['extensionHasFileIconThemes', fileIconThemes.some(theme => isThemeFromExtension(theme, extension))]); cksOverlay.push(['extensionHasProductIconThemes', productIconThemes.some(theme => isThemeFromExtension(theme, extension))]); + + cksOverlay.push(['canSetLanguage', extensionsWorkbenchService.canSetLanguage(extension)]); + cksOverlay.push(['isActiveLanguagePackExtension', extension.gallery && language === languagePackService.getLocale(extension.gallery)]); } const menu = menuService.createMenu(MenuId.ExtensionContext, contextKeyService.createOverlay(cksOverlay)); @@ -1791,10 +1797,10 @@ export class SetProductIconThemeAction extends ExtensionAction { export class SetLanguageAction extends ExtensionAction { - static readonly ID = 'workbench.extensions.action.setLanguageTheme'; - static readonly TITLE = { value: localize('workbench.extensions.action.setLanguageTheme', "Set Display Language"), original: 'Set Display Language' }; + static readonly ID = 'workbench.extensions.action.setDisplayLanguage'; + static readonly TITLE = { value: localize('workbench.extensions.action.setDisplayLanguage', "Set Display Language"), original: 'Set Display Language' }; - private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} theme`; + private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} language`; private static readonly DisabledClass = `${SetLanguageAction.EnabledClass} disabled`; constructor( @@ -1826,6 +1832,44 @@ export class SetLanguageAction extends ExtensionAction { } } +export class ClearLanguageAction extends ExtensionAction { + + static readonly ID = 'workbench.extensions.action.clearLanguage'; + static readonly TITLE = { value: localize('workbench.extensions.action.clearLanguage', "Clear Display Language"), original: 'Clear Display Language' }; + + private static readonly EnabledClass = `${ExtensionAction.LABEL_ACTION_CLASS} language`; + private static readonly DisabledClass = `${ClearLanguageAction.EnabledClass} disabled`; + + constructor( + @IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService, + @ILanguagePackService private readonly languagePackService: ILanguagePackService, + @ILocaleService private readonly localeService: ILocaleService, + ) { + super(ClearLanguageAction.ID, ClearLanguageAction.TITLE.value, ClearLanguageAction.DisabledClass, false); + this.update(); + } + + update(): void { + this.enabled = false; + this.class = ClearLanguageAction.DisabledClass; + if (!this.extension) { + return; + } + if (!this.extensionsWorkbenchService.canSetLanguage(this.extension)) { + return; + } + if (this.extension.gallery && language !== this.languagePackService.getLocale(this.extension.gallery)) { + return; + } + this.enabled = true; + this.class = ClearLanguageAction.EnabledClass; + } + + override async run(): Promise { + return this.extension && this.localeService.clearLocalePreference(); + } +} + export class ShowRecommendedExtensionAction extends Action { static readonly ID = 'workbench.extensions.action.showRecommendedExtension'; diff --git a/src/vs/workbench/contrib/extensions/browser/media/extensionActions.css b/src/vs/workbench/contrib/extensions/browser/media/extensionActions.css index 13d0d87abca06..b50af123be2b1 100644 --- a/src/vs/workbench/contrib/extensions/browser/media/extensionActions.css +++ b/src/vs/workbench/contrib/extensions/browser/media/extensionActions.css @@ -54,6 +54,7 @@ .monaco-action-bar .action-item.disabled .action-label.extension-action.update, .monaco-action-bar .action-item.disabled .action-label.extension-action.migrate, .monaco-action-bar .action-item.disabled .action-label.extension-action.theme, +.monaco-action-bar .action-item.disabled .action-label.extension-action.language, .monaco-action-bar .action-item.disabled .action-label.extension-action.extension-sync, .monaco-action-bar .action-item.action-dropdown-item.disabled, .monaco-action-bar .action-item.action-dropdown-item .action-label.extension-action.hide, From a97ef216014864c45621bf4f6ed00236c3986daa Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Thu, 14 Jul 2022 16:07:06 +0200 Subject: [PATCH 056/121] Settings editor - Boolean setting description should take up the full width instead of just 60% (#155195) Boolean setting description should take up the full width instead of just 60% --- .../contrib/preferences/browser/media/settingsWidgets.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/preferences/browser/media/settingsWidgets.css b/src/vs/workbench/contrib/preferences/browser/media/settingsWidgets.css index f92d003cc0d83..ac9b41bff4c7b 100644 --- a/src/vs/workbench/contrib/preferences/browser/media/settingsWidgets.css +++ b/src/vs/workbench/contrib/preferences/browser/media/settingsWidgets.css @@ -30,7 +30,8 @@ .settings-editor > .settings-body .settings-tree-container .setting-item-bool .setting-list-object-input-key-checkbox .setting-value-checkbox { margin-top: 3px; } -.settings-editor > .settings-body .settings-tree-container .setting-item-bool .setting-list-object-value { +.settings-editor > .settings-body .settings-tree-container .setting-item.setting-item-list .setting-list-object-widget .setting-item-bool .setting-list-object-value { + width: 100%; cursor: pointer; } From 9e92355251ab7ce3151a7d45d3865cdfe14e15e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Thu, 14 Jul 2022 16:19:25 +0200 Subject: [PATCH 057/121] Move Web job into its own stage (#155193) * split web from linux fixes #155191 * reorder --- build/azure-pipelines/product-build.yml | 320 ++++++++++++------------ 1 file changed, 164 insertions(+), 156 deletions(-) diff --git a/build/azure-pipelines/product-build.yml b/build/azure-pipelines/product-build.yml index 46402a8b7f0ef..958203ec56d46 100644 --- a/build/azure-pipelines/product-build.yml +++ b/build/azure-pipelines/product-build.yml @@ -108,9 +108,11 @@ variables: - name: VSCODE_BUILD_STAGE_WINDOWS value: ${{ or(eq(parameters.VSCODE_BUILD_WIN32, true), eq(parameters.VSCODE_BUILD_WIN32_32BIT, true), eq(parameters.VSCODE_BUILD_WIN32_ARM64, true)) }} - name: VSCODE_BUILD_STAGE_LINUX - value: ${{ or(eq(parameters.VSCODE_BUILD_LINUX, true), eq(parameters.VSCODE_BUILD_LINUX_ARMHF, true), eq(parameters.VSCODE_BUILD_LINUX_ARM64, true), eq(parameters.VSCODE_BUILD_LINUX_ALPINE, true), eq(parameters.VSCODE_BUILD_LINUX_ALPINE_ARM64, true), eq(parameters.VSCODE_BUILD_WEB, true)) }} + value: ${{ or(eq(parameters.VSCODE_BUILD_LINUX, true), eq(parameters.VSCODE_BUILD_LINUX_ARMHF, true), eq(parameters.VSCODE_BUILD_LINUX_ARM64, true), eq(parameters.VSCODE_BUILD_LINUX_ALPINE, true), eq(parameters.VSCODE_BUILD_LINUX_ALPINE_ARM64, true)) }} - name: VSCODE_BUILD_STAGE_MACOS value: ${{ or(eq(parameters.VSCODE_BUILD_MACOS, true), eq(parameters.VSCODE_BUILD_MACOS_ARM64, true)) }} + - name: VSCODE_BUILD_STAGE_WEB + value: ${{ eq(parameters.VSCODE_BUILD_WEB, true) }} - name: VSCODE_CIBUILD value: ${{ in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI') }} - name: VSCODE_PUBLISH @@ -176,45 +178,45 @@ stages: pool: vscode-1es-windows jobs: - ${{ if eq(variables['VSCODE_CIBUILD'], true) }}: - - job: WindowsUnitTests - displayName: Unit Tests - timeoutInMinutes: 60 - variables: - VSCODE_ARCH: x64 - steps: - - template: win32/product-build-win32.yml - parameters: - VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} - VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} - VSCODE_RUN_UNIT_TESTS: true - VSCODE_RUN_INTEGRATION_TESTS: false - VSCODE_RUN_SMOKE_TESTS: false - - job: WindowsIntegrationTests - displayName: Integration Tests - timeoutInMinutes: 60 - variables: - VSCODE_ARCH: x64 - steps: - - template: win32/product-build-win32.yml - parameters: - VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} - VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} - VSCODE_RUN_UNIT_TESTS: false - VSCODE_RUN_INTEGRATION_TESTS: true - VSCODE_RUN_SMOKE_TESTS: false - - job: WindowsSmokeTests - displayName: Smoke Tests - timeoutInMinutes: 60 - variables: - VSCODE_ARCH: x64 - steps: - - template: win32/product-build-win32.yml - parameters: - VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} - VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} - VSCODE_RUN_UNIT_TESTS: false - VSCODE_RUN_INTEGRATION_TESTS: false - VSCODE_RUN_SMOKE_TESTS: true + - job: WindowsUnitTests + displayName: Unit Tests + timeoutInMinutes: 60 + variables: + VSCODE_ARCH: x64 + steps: + - template: win32/product-build-win32.yml + parameters: + VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} + VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} + VSCODE_RUN_UNIT_TESTS: true + VSCODE_RUN_INTEGRATION_TESTS: false + VSCODE_RUN_SMOKE_TESTS: false + - job: WindowsIntegrationTests + displayName: Integration Tests + timeoutInMinutes: 60 + variables: + VSCODE_ARCH: x64 + steps: + - template: win32/product-build-win32.yml + parameters: + VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} + VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} + VSCODE_RUN_UNIT_TESTS: false + VSCODE_RUN_INTEGRATION_TESTS: true + VSCODE_RUN_SMOKE_TESTS: false + - job: WindowsSmokeTests + displayName: Smoke Tests + timeoutInMinutes: 60 + variables: + VSCODE_ARCH: x64 + steps: + - template: win32/product-build-win32.yml + parameters: + VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} + VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} + VSCODE_RUN_UNIT_TESTS: false + VSCODE_RUN_INTEGRATION_TESTS: false + VSCODE_RUN_SMOKE_TESTS: true - ${{ if and(eq(variables['VSCODE_CIBUILD'], false), eq(parameters.VSCODE_BUILD_WIN32, true)) }}: - job: Windows @@ -291,51 +293,51 @@ stages: pool: vscode-1es-linux jobs: - ${{ if eq(variables['VSCODE_CIBUILD'], true) }}: - - job: Linuxx64UnitTest - displayName: Unit Tests - container: vscode-bionic-x64 - variables: - VSCODE_ARCH: x64 - NPM_ARCH: x64 - DISPLAY: ":10" - steps: - - template: linux/product-build-linux-client.yml - parameters: - VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} - VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} - VSCODE_RUN_UNIT_TESTS: true - VSCODE_RUN_INTEGRATION_TESTS: false - VSCODE_RUN_SMOKE_TESTS: false - - job: Linuxx64IntegrationTest - displayName: Integration Tests - container: vscode-bionic-x64 - variables: - VSCODE_ARCH: x64 - NPM_ARCH: x64 - DISPLAY: ":10" - steps: - - template: linux/product-build-linux-client.yml - parameters: - VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} - VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} - VSCODE_RUN_UNIT_TESTS: false - VSCODE_RUN_INTEGRATION_TESTS: true - VSCODE_RUN_SMOKE_TESTS: false - - job: Linuxx64SmokeTest - displayName: Smoke Tests - container: vscode-bionic-x64 - variables: - VSCODE_ARCH: x64 - NPM_ARCH: x64 - DISPLAY: ":10" - steps: - - template: linux/product-build-linux-client.yml - parameters: - VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} - VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} - VSCODE_RUN_UNIT_TESTS: false - VSCODE_RUN_INTEGRATION_TESTS: false - VSCODE_RUN_SMOKE_TESTS: true + - job: Linuxx64UnitTest + displayName: Unit Tests + container: vscode-bionic-x64 + variables: + VSCODE_ARCH: x64 + NPM_ARCH: x64 + DISPLAY: ":10" + steps: + - template: linux/product-build-linux-client.yml + parameters: + VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} + VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} + VSCODE_RUN_UNIT_TESTS: true + VSCODE_RUN_INTEGRATION_TESTS: false + VSCODE_RUN_SMOKE_TESTS: false + - job: Linuxx64IntegrationTest + displayName: Integration Tests + container: vscode-bionic-x64 + variables: + VSCODE_ARCH: x64 + NPM_ARCH: x64 + DISPLAY: ":10" + steps: + - template: linux/product-build-linux-client.yml + parameters: + VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} + VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} + VSCODE_RUN_UNIT_TESTS: false + VSCODE_RUN_INTEGRATION_TESTS: true + VSCODE_RUN_SMOKE_TESTS: false + - job: Linuxx64SmokeTest + displayName: Smoke Tests + container: vscode-bionic-x64 + variables: + VSCODE_ARCH: x64 + NPM_ARCH: x64 + DISPLAY: ":10" + steps: + - template: linux/product-build-linux-client.yml + parameters: + VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} + VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} + VSCODE_RUN_UNIT_TESTS: false + VSCODE_RUN_INTEGRATION_TESTS: false + VSCODE_RUN_SMOKE_TESTS: true - ${{ if and(eq(variables['VSCODE_CIBUILD'], false), eq(parameters.VSCODE_BUILD_LINUX, true)) }}: - job: Linuxx64 @@ -430,13 +432,6 @@ stages: steps: - template: linux/product-build-alpine.yml - - ${{ if and(eq(variables['VSCODE_CIBUILD'], false), eq(parameters.VSCODE_BUILD_WEB, true)) }}: - - job: LinuxWeb - variables: - VSCODE_ARCH: x64 - steps: - - template: web/product-build-web.yml - - ${{ if and(eq(parameters.VSCODE_COMPILE_ONLY, false), eq(variables['VSCODE_BUILD_STAGE_MACOS'], true)) }}: - stage: macOS dependsOn: @@ -447,62 +442,8 @@ stages: BUILDSECMON_OPT_IN: true jobs: - ${{ if eq(variables['VSCODE_CIBUILD'], true) }}: - - job: macOSUnitTest - displayName: Unit Tests - timeoutInMinutes: 90 - variables: - VSCODE_ARCH: x64 - steps: - - template: darwin/product-build-darwin.yml - parameters: - VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} - VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} - VSCODE_RUN_UNIT_TESTS: true - VSCODE_RUN_INTEGRATION_TESTS: false - VSCODE_RUN_SMOKE_TESTS: false - - job: macOSIntegrationTest - displayName: Integration Tests - timeoutInMinutes: 90 - variables: - VSCODE_ARCH: x64 - steps: - - template: darwin/product-build-darwin.yml - parameters: - VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} - VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} - VSCODE_RUN_UNIT_TESTS: false - VSCODE_RUN_INTEGRATION_TESTS: true - VSCODE_RUN_SMOKE_TESTS: false - - job: macOSSmokeTest - displayName: Smoke Tests - timeoutInMinutes: 90 - variables: - VSCODE_ARCH: x64 - steps: - - template: darwin/product-build-darwin.yml - parameters: - VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} - VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} - VSCODE_RUN_UNIT_TESTS: false - VSCODE_RUN_INTEGRATION_TESTS: false - VSCODE_RUN_SMOKE_TESTS: true - - - ${{ if and(eq(variables['VSCODE_CIBUILD'], false), eq(parameters.VSCODE_BUILD_MACOS, true)) }}: - - job: macOS - timeoutInMinutes: 90 - variables: - VSCODE_ARCH: x64 - steps: - - template: darwin/product-build-darwin.yml - parameters: - VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} - VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} - VSCODE_RUN_UNIT_TESTS: false - VSCODE_RUN_INTEGRATION_TESTS: false - VSCODE_RUN_SMOKE_TESTS: false - - - ${{ if eq(parameters.VSCODE_STEP_ON_IT, false) }}: - - job: macOSTest + - job: macOSUnitTest + displayName: Unit Tests timeoutInMinutes: 90 variables: VSCODE_ARCH: x64 @@ -511,19 +452,73 @@ stages: parameters: VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} - VSCODE_RUN_UNIT_TESTS: ${{ eq(parameters.VSCODE_STEP_ON_IT, false) }} - VSCODE_RUN_INTEGRATION_TESTS: ${{ eq(parameters.VSCODE_STEP_ON_IT, false) }} - VSCODE_RUN_SMOKE_TESTS: ${{ eq(parameters.VSCODE_STEP_ON_IT, false) }} + VSCODE_RUN_UNIT_TESTS: true + VSCODE_RUN_INTEGRATION_TESTS: false + VSCODE_RUN_SMOKE_TESTS: false + - job: macOSIntegrationTest + displayName: Integration Tests + timeoutInMinutes: 90 + variables: + VSCODE_ARCH: x64 + steps: + - template: darwin/product-build-darwin.yml + parameters: + VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} + VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} + VSCODE_RUN_UNIT_TESTS: false + VSCODE_RUN_INTEGRATION_TESTS: true + VSCODE_RUN_SMOKE_TESTS: false + - job: macOSSmokeTest + displayName: Smoke Tests + timeoutInMinutes: 90 + variables: + VSCODE_ARCH: x64 + steps: + - template: darwin/product-build-darwin.yml + parameters: + VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} + VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} + VSCODE_RUN_UNIT_TESTS: false + VSCODE_RUN_INTEGRATION_TESTS: false + VSCODE_RUN_SMOKE_TESTS: true - - ${{ if eq(variables['VSCODE_PUBLISH'], true) }}: - - job: macOSSign - dependsOn: - - macOS + - ${{ if and(eq(variables['VSCODE_CIBUILD'], false), eq(parameters.VSCODE_BUILD_MACOS, true)) }}: + - job: macOS timeoutInMinutes: 90 variables: VSCODE_ARCH: x64 steps: - - template: darwin/product-build-darwin-sign.yml + - template: darwin/product-build-darwin.yml + parameters: + VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} + VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} + VSCODE_RUN_UNIT_TESTS: false + VSCODE_RUN_INTEGRATION_TESTS: false + VSCODE_RUN_SMOKE_TESTS: false + + - ${{ if eq(parameters.VSCODE_STEP_ON_IT, false) }}: + - job: macOSTest + timeoutInMinutes: 90 + variables: + VSCODE_ARCH: x64 + steps: + - template: darwin/product-build-darwin.yml + parameters: + VSCODE_PUBLISH: ${{ variables.VSCODE_PUBLISH }} + VSCODE_QUALITY: ${{ variables.VSCODE_QUALITY }} + VSCODE_RUN_UNIT_TESTS: ${{ eq(parameters.VSCODE_STEP_ON_IT, false) }} + VSCODE_RUN_INTEGRATION_TESTS: ${{ eq(parameters.VSCODE_STEP_ON_IT, false) }} + VSCODE_RUN_SMOKE_TESTS: ${{ eq(parameters.VSCODE_STEP_ON_IT, false) }} + + - ${{ if eq(variables['VSCODE_PUBLISH'], true) }}: + - job: macOSSign + dependsOn: + - macOS + timeoutInMinutes: 90 + variables: + VSCODE_ARCH: x64 + steps: + - template: darwin/product-build-darwin-sign.yml - ${{ if and(eq(variables['VSCODE_CIBUILD'], false), eq(parameters.VSCODE_BUILD_MACOS_ARM64, true)) }}: - job: macOSARM64 @@ -570,6 +565,19 @@ stages: steps: - template: darwin/product-build-darwin-sign.yml + - ${{ if and(eq(variables['VSCODE_CIBUILD'], false), eq(parameters.VSCODE_COMPILE_ONLY, false), eq(variables['VSCODE_BUILD_STAGE_WEB'], true)) }}: + - stage: Web + dependsOn: + - Compile + pool: vscode-1es-linux + jobs: + - ${{ if eq(parameters.VSCODE_BUILD_WEB, true) }}: + - job: Web + variables: + VSCODE_ARCH: x64 + steps: + - template: web/product-build-web.yml + - ${{ if and(eq(parameters.VSCODE_COMPILE_ONLY, false), ne(variables['VSCODE_PUBLISH'], 'false')) }}: - stage: Publish dependsOn: From 23e447e4824d0a66541eb9498919dba87b817a33 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Thu, 14 Jul 2022 17:28:25 +0200 Subject: [PATCH 058/121] switch default - use browser request by default (#155205) --- .../electron-browser/sharedProcessRequestService.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/vs/platform/request/electron-browser/sharedProcessRequestService.ts b/src/vs/platform/request/electron-browser/sharedProcessRequestService.ts index e8dcf7532656c..700d6d1ea6564 100644 --- a/src/vs/platform/request/electron-browser/sharedProcessRequestService.ts +++ b/src/vs/platform/request/electron-browser/sharedProcessRequestService.ts @@ -37,11 +37,11 @@ export class SharedProcessRequestService implements IRequestService { } private getRequestService(): IRequestService { - if (this.configurationService.getValue('developer.sharedProcess.useBrowserRequestService') === true) { - this.logService.trace('Using browser request service'); - return this.browserRequestService; + if (this.configurationService.getValue('developer.sharedProcess.redirectRequestsToMain') === true) { + this.logService.trace('Using main request service'); + return this.mainRequestService; } - this.logService.trace('Using main request service'); - return this.mainRequestService; + this.logService.trace('Using browser request service'); + return this.browserRequestService; } } From 4154553cb8167f183a41255820421adb8bd6938a Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 14 Jul 2022 18:23:44 +0200 Subject: [PATCH 059/121] read `REBASE_HEAD` when rebasing, swap yours/theirs (label, sides) as well (#155208) https://github.com/microsoft/vscode/issues/153737 --- extensions/git/src/commands.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 37c500f76054e..0e3e19792ccf9 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -418,6 +418,7 @@ export class CommandCenter { return; } + const isRebasing = Boolean(repo.rebaseCommit); type InputData = { uri: Uri; title?: string; detail?: string; description?: string }; const mergeUris = toMergeUris(uri); @@ -425,14 +426,17 @@ export class CommandCenter { const theirs: InputData = { uri: mergeUris.theirs, title: localize('Theirs', 'Theirs') }; try { - const [head, mergeHead] = await Promise.all([repo.getCommit('HEAD'), repo.getCommit('MERGE_HEAD')]); + const [head, rebaseOrMergeHead] = await Promise.all([ + repo.getCommit('HEAD'), + isRebasing ? repo.getCommit('REBASE_HEAD') : repo.getCommit('MERGE_HEAD') + ]); // ours (current branch and commit) ours.detail = head.refNames.map(s => s.replace(/^HEAD ->/, '')).join(', '); ours.description = head.hash.substring(0, 7); // theirs - theirs.detail = mergeHead.refNames.join(', '); - theirs.description = mergeHead.hash.substring(0, 7); + theirs.detail = rebaseOrMergeHead.refNames.join(', '); + theirs.description = rebaseOrMergeHead.hash.substring(0, 7); } catch (error) { // not so bad, can continue with just uris @@ -442,8 +446,8 @@ export class CommandCenter { const options = { base: mergeUris.base, - input1: theirs, - input2: ours, + input1: isRebasing ? ours : theirs, + input2: isRebasing ? theirs : ours, output: uri }; From 1acc07db959dff0b8681414ceec047e09830737f Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Thu, 14 Jul 2022 10:21:57 -0700 Subject: [PATCH 060/121] Re #154948. No MenuItemAction in notebook (#155096) --- src/vs/platform/actions/common/actions.ts | 2 + .../interactive/browser/interactiveEditor.ts | 1 + .../browser/controller/editActions.ts | 37 ++++++--------- .../notebook/browser/notebookBrowser.ts | 1 + .../notebook/browser/notebookEditorWidget.ts | 1 + .../browser/view/cellParts/cellToolbars.ts | 45 ++++++++++--------- .../browser/view/renderers/cellRenderer.ts | 2 + 7 files changed, 44 insertions(+), 45 deletions(-) diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index 79fbc7424c325..cbf2991ee7c8f 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -127,10 +127,12 @@ export class MenuId { static readonly CommentActions = new MenuId('CommentActions'); static readonly InteractiveToolbar = new MenuId('InteractiveToolbar'); static readonly InteractiveCellTitle = new MenuId('InteractiveCellTitle'); + static readonly InteractiveCellDelete = new MenuId('InteractiveCellDelete'); static readonly InteractiveCellExecute = new MenuId('InteractiveCellExecute'); static readonly InteractiveInputExecute = new MenuId('InteractiveInputExecute'); static readonly NotebookToolbar = new MenuId('NotebookToolbar'); static readonly NotebookCellTitle = new MenuId('NotebookCellTitle'); + static readonly NotebookCellDelete = new MenuId('NotebookCellDelete'); static readonly NotebookCellInsert = new MenuId('NotebookCellInsert'); static readonly NotebookCellBetween = new MenuId('NotebookCellBetween'); static readonly NotebookCellListTop = new MenuId('NotebookCellTop'); diff --git a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts index 3462892ee8ab7..549ca51417f58 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts @@ -336,6 +336,7 @@ export class InteractiveEditor extends EditorPane { menuIds: { notebookToolbar: MenuId.InteractiveToolbar, cellTitleToolbar: MenuId.InteractiveCellTitle, + cellDeleteToolbar: MenuId.InteractiveCellDelete, cellInsertToolbar: MenuId.NotebookCellBetween, cellTopInsertToolbar: MenuId.NotebookCellListTop, cellExecuteToolbar: MenuId.InteractiveCellExecute, diff --git a/src/vs/workbench/contrib/notebook/browser/controller/editActions.ts b/src/vs/workbench/contrib/notebook/browser/controller/editActions.ts index 1f64bddb5e36d..06e089a7c6b21 100644 --- a/src/vs/workbench/contrib/notebook/browser/controller/editActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/controller/editActions.ts @@ -11,9 +11,8 @@ import { getIconClasses } from 'vs/editor/common/services/getIconClasses'; import { IModelService } from 'vs/editor/common/services/model'; import { ILanguageService } from 'vs/editor/common/languages/language'; import { localize } from 'vs/nls'; -import { MenuId, MenuItemAction, registerAction2 } from 'vs/platform/actions/common/actions'; -import { ICommandService } from 'vs/platform/commands/common/commands'; -import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { MenuId, registerAction2 } from 'vs/platform/actions/common/actions'; +import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { InputFocusedContext, InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; @@ -35,26 +34,6 @@ const EDIT_CELL_COMMAND_ID = 'notebook.cell.edit'; const DELETE_CELL_COMMAND_ID = 'notebook.cell.delete'; const CLEAR_CELL_OUTPUTS_COMMAND_ID = 'notebook.cell.clearOutputs'; -export class DeleteCellAction extends MenuItemAction { - constructor( - @IContextKeyService contextKeyService: IContextKeyService, - @ICommandService commandService: ICommandService - ) { - super( - { - id: DELETE_CELL_COMMAND_ID, - title: localize('notebookActions.deleteCell', "Delete Cell"), - icon: icons.deleteCellIcon, - precondition: NOTEBOOK_EDITOR_EDITABLE.isEqualTo(true) - }, - undefined, - { shouldForwardArgs: true }, - undefined, - contextKeyService, - commandService); - } -} - registerAction2(class EditCellAction extends NotebookCellAction { constructor() { super( @@ -158,6 +137,18 @@ registerAction2(class DeleteCellAction extends NotebookCellAction { when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_EDITABLE, ContextKeyExpr.not(InputFocusedContextKey)), weight: KeybindingWeight.WorkbenchContrib }, + menu: [ + { + id: MenuId.NotebookCellDelete, + when: NOTEBOOK_EDITOR_EDITABLE, + group: CELL_TITLE_CELL_GROUP_ID + }, + { + id: MenuId.InteractiveCellDelete, + when: NOTEBOOK_EDITOR_EDITABLE, + group: CELL_TITLE_CELL_GROUP_ID + } + ], icon: icons.deleteCellIcon }); } diff --git a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts index 84614d859fe5d..9b245482c3d54 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts @@ -325,6 +325,7 @@ export interface INotebookEditorCreationOptions { readonly menuIds: { notebookToolbar: MenuId; cellTitleToolbar: MenuId; + cellDeleteToolbar: MenuId; cellInsertToolbar: MenuId; cellTopInsertToolbar: MenuId; cellExecuteToolbar: MenuId; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 3debc2599a6ad..6402451333d9c 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -190,6 +190,7 @@ export function getDefaultNotebookCreationOptions(): INotebookEditorCreationOpti menuIds: { notebookToolbar: MenuId.NotebookToolbar, cellTitleToolbar: MenuId.NotebookCellTitle, + cellDeleteToolbar: MenuId.NotebookCellDelete, cellInsertToolbar: MenuId.NotebookCellBetween, cellTopInsertToolbar: MenuId.NotebookCellListTop, cellExecuteToolbar: MenuId.NotebookCellExecute, diff --git a/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellToolbars.ts b/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellToolbars.ts index 35502e4e1a99b..9b3a6397be2e1 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellToolbars.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellToolbars.ts @@ -18,7 +18,6 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { INotebookCellActionContext } from 'vs/workbench/contrib/notebook/browser/controller/coreActions'; -import { DeleteCellAction } from 'vs/workbench/contrib/notebook/browser/controller/editActions'; import { ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; import { CodiconActionViewItem } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellActionView'; import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellPart'; @@ -93,22 +92,23 @@ export interface ICssClassDelegate { export class CellTitleToolbarPart extends CellPart { private _toolbar: ToolBar; - private _deleteToolbar: ToolBar; private _titleMenu: IMenu; - private _actionsDisposables = this._register(new DisposableStore()); - - private _hasActions = false; + private _deleteToolbar: ToolBar; + private _deleteMenu: IMenu; + private _toolbarActionsDisposables = this._register(new DisposableStore()); + private _deleteActionsDisposables = this._register(new DisposableStore()); private readonly _onDidUpdateActions: Emitter = this._register(new Emitter()); readonly onDidUpdateActions: Event = this._onDidUpdateActions.event; get hasActions(): boolean { - return this._hasActions; + return this._toolbar.getItemsLength() + this._deleteToolbar.getItemsLength() > 0; } constructor( private readonly toolbarContainer: HTMLElement, private readonly _rootClassDelegate: ICssClassDelegate, toolbarId: MenuId, + deleteToolbarId: MenuId, private readonly _notebookEditor: INotebookEditorDelegate, @IContextKeyService contextKeyService: IContextKeyService, @IMenuService menuService: IMenuService, @@ -120,11 +120,14 @@ export class CellTitleToolbarPart extends CellPart { this._titleMenu = this._register(menuService.createMenu(toolbarId, contextKeyService)); this._deleteToolbar = this._register(instantiationService.invokeFunction(accessor => createToolbar(accessor, toolbarContainer, 'cell-delete-toolbar'))); + this._deleteMenu = this._register(menuService.createMenu(deleteToolbarId, contextKeyService)); if (!this._notebookEditor.creationOptions.isReadOnly) { - this._deleteToolbar.setActions([instantiationService.createInstance(DeleteCellAction)]); + const deleteActions = getCellToolbarActions(this._deleteMenu); + this._deleteToolbar.setActions(deleteActions.primary, deleteActions.secondary); } - this.setupChangeListeners(); + this.setupChangeListeners(this._toolbar, this._titleMenu, this._toolbarActionsDisposables); + this.setupChangeListeners(this._deleteToolbar, this._deleteMenu, this._deleteActionsDisposables); } override didRenderCell(element: ICellViewModel): void { @@ -143,22 +146,22 @@ export class CellTitleToolbarPart extends CellPart { this._deleteToolbar.context = toolbarContext; } - private setupChangeListeners(): void { + private setupChangeListeners(toolbar: ToolBar, menu: IMenu, actionDisposables: DisposableStore): void { // #103926 let dropdownIsVisible = false; let deferredUpdate: (() => void) | undefined; - this.updateActions(); - this._register(this._titleMenu.onDidChange(() => { + this.updateActions(toolbar, menu, actionDisposables); + this._register(menu.onDidChange(() => { if (dropdownIsVisible) { - deferredUpdate = () => this.updateActions(); + deferredUpdate = () => this.updateActions(toolbar, menu, actionDisposables); return; } - this.updateActions(); + this.updateActions(toolbar, menu, actionDisposables); })); this._rootClassDelegate.toggle('cell-toolbar-dropdown-active', false); - this._register(this._toolbar.onDidChangeDropdownVisibility(visible => { + this._register(toolbar.onDidChangeDropdownVisibility(visible => { dropdownIsVisible = visible; this._rootClassDelegate.toggle('cell-toolbar-dropdown-active', visible); @@ -172,24 +175,22 @@ export class CellTitleToolbarPart extends CellPart { })); } - private updateActions() { - this._actionsDisposables.clear(); - const actions = getCellToolbarActions(this._titleMenu); - this._actionsDisposables.add(actions.disposable); + private updateActions(toolbar: ToolBar, menu: IMenu, actionDisposables: DisposableStore) { + actionDisposables.clear(); + const actions = getCellToolbarActions(menu); + actionDisposables.add(actions.disposable); - const hadFocus = DOM.isAncestor(document.activeElement, this._toolbar.getElement()); - this._toolbar.setActions(actions.primary, actions.secondary); + const hadFocus = DOM.isAncestor(document.activeElement, toolbar.getElement()); + toolbar.setActions(actions.primary, actions.secondary); if (hadFocus) { this._notebookEditor.focus(); } if (actions.primary.length || actions.secondary.length) { this._rootClassDelegate.toggle('cell-has-toolbar-actions', true); - this._hasActions = true; this._onDidUpdateActions.fire(); } else { this._rootClassDelegate.toggle('cell-has-toolbar-actions', false); - this._hasActions = false; this._onDidUpdateActions.fire(); } } diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts index 2bcf55c85318c..77ed53a9ce354 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts @@ -160,6 +160,7 @@ export class MarkupCellRenderer extends AbstractCellRenderer implements IListRen titleToolbarContainer, rootClassDelegate, this.notebookEditor.creationOptions.menuIds.cellTitleToolbar, + this.notebookEditor.creationOptions.menuIds.cellDeleteToolbar, this.notebookEditor)); const focusIndicatorBottom = new FastDomNode(DOM.append(container, $('.cell-focus-indicator.cell-focus-indicator-bottom'))); @@ -299,6 +300,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende titleToolbarContainer, rootClassDelegate, this.notebookEditor.creationOptions.menuIds.cellTitleToolbar, + this.notebookEditor.creationOptions.menuIds.cellDeleteToolbar, this.notebookEditor)); const focusIndicatorPart = templateDisposables.add(new CellFocusIndicator(this.notebookEditor, titleToolbar, focusIndicatorTop, focusIndicatorLeft, focusIndicatorRight, focusIndicatorBottom)); From 64ff727bf289c29d70e5826366da454766c22b92 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Thu, 14 Jul 2022 11:40:06 -0700 Subject: [PATCH 061/121] Don't ask debug adapter for initial configs when opening launch.json to add a dynamic config (#155215) Fixes #153388 --- .../contrib/debug/browser/debugCommands.ts | 2 +- .../debug/browser/debugConfigurationManager.ts | 18 ++++++++++-------- .../contrib/debug/browser/debugQuickAccess.ts | 2 +- .../contrib/debug/browser/debugService.ts | 6 +++--- .../contrib/debug/browser/debugViewlet.ts | 2 +- src/vs/workbench/contrib/debug/common/debug.ts | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/vs/workbench/contrib/debug/browser/debugCommands.ts b/src/vs/workbench/contrib/debug/browser/debugCommands.ts index 596bbd9c32d8b..20390fcd0f366 100644 --- a/src/vs/workbench/contrib/debug/browser/debugCommands.ts +++ b/src/vs/workbench/contrib/debug/browser/debugCommands.ts @@ -917,7 +917,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ const launch = manager.getLaunches().find(l => l.uri.toString() === launchUri) || manager.selectedConfiguration.launch; if (launch) { - const { editor, created } = await launch.openConfigFile(false); + const { editor, created } = await launch.openConfigFile({ preserveFocus: false }); if (editor && !created) { const codeEditor = editor.getControl(); if (codeEditor) { diff --git a/src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts b/src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts index 0245dbd5a2d05..a00d75ef26a07 100644 --- a/src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts +++ b/src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts @@ -215,7 +215,7 @@ export class ConfigurationManager implements IConfigurationManager { disposables.add(input.onDidTriggerItemButton(async (context) => { resolve(undefined); const { launch, config } = context.item; - await launch.openConfigFile(false, config.type); + await launch.openConfigFile({ preserveFocus: false, type: config.type }); // Only Launch have a pin trigger button await (launch as Launch).writeConfiguration(config); await this.selectConfiguration(launch, config.name); @@ -521,11 +521,13 @@ abstract class AbstractLaunch { return configuration; } - async getInitialConfigurationContent(folderUri?: uri, type?: string, token?: CancellationToken): Promise { + async getInitialConfigurationContent(folderUri?: uri, type?: string, useInitialConfigs?: boolean, token?: CancellationToken): Promise { let content = ''; const adapter = type ? this.adapterManager.getEnabledDebugger(type) : await this.adapterManager.guessDebugger(true); if (adapter) { - const initialConfigs = await this.configurationManager.provideDebugConfigurations(folderUri, adapter.type, token || CancellationToken.None); + const initialConfigs = useInitialConfigs ? + await this.configurationManager.provideDebugConfigurations(folderUri, adapter.type, token || CancellationToken.None) : + []; content = await adapter.getInitialConfigurationContent(initialConfigs); } return content; @@ -562,7 +564,7 @@ class Launch extends AbstractLaunch implements ILaunch { return this.configurationService.inspect('launch', { resource: this.workspace.uri }).workspaceFolderValue; } - async openConfigFile(preserveFocus: boolean, type?: string, token?: CancellationToken): Promise<{ editor: IEditorPane | null; created: boolean }> { + async openConfigFile({ preserveFocus, type, useInitialConfigs }: { preserveFocus: boolean; type?: string; useInitialConfigs?: boolean }, token?: CancellationToken): Promise<{ editor: IEditorPane | null; created: boolean }> { const resource = this.uri; let created = false; let content = ''; @@ -571,7 +573,7 @@ class Launch extends AbstractLaunch implements ILaunch { content = fileContent.value.toString(); } catch { // launch.json not found: create one by collecting launch configs from debugConfigProviders - content = await this.getInitialConfigurationContent(this.workspace.uri, type, token); + content = await this.getInitialConfigurationContent(this.workspace.uri, type, useInitialConfigs, token); if (!content) { // Cancelled return { editor: null, created: false }; @@ -647,11 +649,11 @@ class WorkspaceLaunch extends AbstractLaunch implements ILaunch { return this.configurationService.inspect('launch').workspaceValue; } - async openConfigFile(preserveFocus: boolean, type?: string, token?: CancellationToken): Promise<{ editor: IEditorPane | null; created: boolean }> { + async openConfigFile({ preserveFocus, type, useInitialConfigs }: { preserveFocus: boolean; type?: string; useInitialConfigs?: boolean }, token?: CancellationToken): Promise<{ editor: IEditorPane | null; created: boolean }> { const launchExistInFile = !!this.getConfig(); if (!launchExistInFile) { // Launch property in workspace config not found: create one by collecting launch configs from debugConfigProviders - const content = await this.getInitialConfigurationContent(undefined, type, token); + const content = await this.getInitialConfigurationContent(undefined, type, useInitialConfigs, token); if (content) { await this.configurationService.updateValue('launch', json.parse(content), ConfigurationTarget.WORKSPACE); } else { @@ -702,7 +704,7 @@ class UserLaunch extends AbstractLaunch implements ILaunch { return this.configurationService.inspect('launch').userValue; } - async openConfigFile(preserveFocus: boolean): Promise<{ editor: IEditorPane | null; created: boolean }> { + async openConfigFile({ preserveFocus, type, useInitialContent }: { preserveFocus: boolean; type?: string; useInitialContent?: boolean }): Promise<{ editor: IEditorPane | null; created: boolean }> { const editor = await this.preferencesService.openUserSettings({ jsonEditor: true, preserveFocus, revealSetting: { key: 'launch' } }); return ({ editor: withUndefinedAsNull(editor), diff --git a/src/vs/workbench/contrib/debug/browser/debugQuickAccess.ts b/src/vs/workbench/contrib/debug/browser/debugQuickAccess.ts index df5f79031eafc..6cd33d34f5ca9 100644 --- a/src/vs/workbench/contrib/debug/browser/debugQuickAccess.ts +++ b/src/vs/workbench/contrib/debug/browser/debugQuickAccess.ts @@ -63,7 +63,7 @@ export class StartDebugQuickAccessProvider extends PickerQuickAccessProvider { - config.launch.openConfigFile(false); + config.launch.openConfigFile({ preserveFocus: false, useInitialConfigs: false }); return TriggerAction.CLOSE_PICKER; }, diff --git a/src/vs/workbench/contrib/debug/browser/debugService.ts b/src/vs/workbench/contrib/debug/browser/debugService.ts index 2474922a5add0..f6db1acdb8023 100644 --- a/src/vs/workbench/contrib/debug/browser/debugService.ts +++ b/src/vs/workbench/contrib/debug/browser/debugService.ts @@ -474,7 +474,7 @@ export class DebugService implements IDebugService { const cfg = await this.configurationManager.resolveDebugConfigurationWithSubstitutedVariables(launch && launch.workspace ? launch.workspace.uri : undefined, type, resolvedConfig, initCancellationToken.token); if (!cfg) { if (launch && type && cfg === null && !initCancellationToken.token.isCancellationRequested) { // show launch.json only for "config" being "null". - await launch.openConfigFile(true, type, initCancellationToken.token); + await launch.openConfigFile({ preserveFocus: true, type }, initCancellationToken.token); } return false; } @@ -526,7 +526,7 @@ export class DebugService implements IDebugService { await this.showError(nls.localize('noFolderWorkspaceDebugError', "The active file can not be debugged. Make sure it is saved and that you have a debug extension installed for that file type.")); } if (launch && !initCancellationToken.token.isCancellationRequested) { - await launch.openConfigFile(true, undefined, initCancellationToken.token); + await launch.openConfigFile({ preserveFocus: true }, initCancellationToken.token); } return false; @@ -534,7 +534,7 @@ export class DebugService implements IDebugService { } if (launch && type && configByProviders === null && !initCancellationToken.token.isCancellationRequested) { // show launch.json only for "config" being "null". - await launch.openConfigFile(true, type, initCancellationToken.token); + await launch.openConfigFile({ preserveFocus: true, type }, initCancellationToken.token); } return false; diff --git a/src/vs/workbench/contrib/debug/browser/debugViewlet.ts b/src/vs/workbench/contrib/debug/browser/debugViewlet.ts index ae38d059d8855..ca8b89ac152fa 100644 --- a/src/vs/workbench/contrib/debug/browser/debugViewlet.ts +++ b/src/vs/workbench/contrib/debug/browser/debugViewlet.ts @@ -231,7 +231,7 @@ registerAction2(class extends Action2 { } if (launch) { - await launch.openConfigFile(false); + await launch.openConfigFile({ preserveFocus: false }); } } }); diff --git a/src/vs/workbench/contrib/debug/common/debug.ts b/src/vs/workbench/contrib/debug/common/debug.ts index 21dc92d475c86..ca1c5e318d289 100644 --- a/src/vs/workbench/contrib/debug/common/debug.ts +++ b/src/vs/workbench/contrib/debug/common/debug.ts @@ -927,7 +927,7 @@ export interface ILaunch { /** * Opens the launch.json file. Creates if it does not exist. */ - openConfigFile(preserveFocus: boolean, type?: string, token?: CancellationToken): Promise<{ editor: IEditorPane | null; created: boolean }>; + openConfigFile(options: { preserveFocus: boolean; type?: string; useInitialConfigs?: boolean }, token?: CancellationToken): Promise<{ editor: IEditorPane | null; created: boolean }>; } // Debug service interfaces From 263fbe268c1b5b02bc35d2661e4ea4ec7c631047 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Thu, 14 Jul 2022 11:42:04 -0700 Subject: [PATCH 062/121] Fix: do not delete partially applied edit sessions (#155218) --- .../contrib/editSessions/browser/editSessions.contribution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts b/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts index e292a79c0849f..34d89d716a288 100644 --- a/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts +++ b/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts @@ -270,7 +270,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo const folderRoot = this.contextService.getWorkspace().folders.find((f) => f.name === folder.name); if (!folderRoot) { this.logService.info(`Skipping applying ${folder.workingChanges.length} changes from edit session with ref ${ref} as no corresponding workspace folder named ${folder.name} is currently open.`); - continue; + return; } for (const repository of this.scmService.repositories) { From b7093a3fb5796a46ad31b5a4234bcf43e03d6cbe Mon Sep 17 00:00:00 2001 From: Alexandru Dima Date: Thu, 14 Jul 2022 20:44:05 +0200 Subject: [PATCH 063/121] Add try-catch around call that throws in ctor (#155224) Add try-catch around call that throws in ctor (#151147) --- src/vs/workbench/api/browser/mainThreadTesting.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/api/browser/mainThreadTesting.ts b/src/vs/workbench/api/browser/mainThreadTesting.ts index 01fd391e965a9..280741c14a93d 100644 --- a/src/vs/workbench/api/browser/mainThreadTesting.ts +++ b/src/vs/workbench/api/browser/mainThreadTesting.ts @@ -19,6 +19,7 @@ import { ITestResultService } from 'vs/workbench/contrib/testing/common/testResu import { IMainThreadTestController, ITestRootProvider, ITestService } from 'vs/workbench/contrib/testing/common/testService'; import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers'; import { ExtHostContext, ExtHostTestingShape, ILocationDto, ITestControllerPatch, MainContext, MainThreadTestingShape } from '../common/extHost.protocol'; +import { onUnexpectedError } from 'vs/base/common/errors'; @extHostNamedCustomer(MainContext.MainThreadTesting) export class MainThreadTesting extends Disposable implements MainThreadTestingShape, ITestRootProvider { @@ -42,7 +43,13 @@ export class MainThreadTesting extends Disposable implements MainThreadTestingSh const prevResults = resultService.results.map(r => r.toJSON()).filter(isDefined); if (prevResults.length) { - this.proxy.$publishTestResults(prevResults); + try { + this.proxy.$publishTestResults(prevResults); + } catch (err) { + // See https://github.com/microsoft/vscode/issues/151147 + // Trying to send more than 1GB of data can cause the method to throw. + onUnexpectedError(err); + } } this._register(this.testService.onDidCancelTestRun(({ runId }) => { From 01171d0407f380148ca32fedfae6d2056a852b75 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Thu, 14 Jul 2022 11:55:38 -0700 Subject: [PATCH 064/121] Disable chunking to prevent `importScripts` calls in web (#155226) --- extensions/shared.webpack.config.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extensions/shared.webpack.config.js b/extensions/shared.webpack.config.js index a33fa89ce30c8..37eed9c9b853d 100644 --- a/extensions/shared.webpack.config.js +++ b/extensions/shared.webpack.config.js @@ -13,7 +13,7 @@ const fs = require('fs'); const merge = require('merge-options'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const { NLSBundlePlugin } = require('vscode-nls-dev/lib/webpack-bundler'); -const { DefinePlugin } = require('webpack'); +const { DefinePlugin, optimize } = require('webpack'); function withNodeDefaults(/**@type WebpackConfig*/extConfig) { /** @type WebpackConfig */ @@ -145,6 +145,9 @@ function withBrowserDefaults(/**@type WebpackConfig*/extConfig, /** @type Additi } const browserPlugins = [ + new optimize.LimitChunkCountPlugin({ + maxChunks: 1 + }), new CopyWebpackPlugin({ patterns: [ { from: 'src', to: '.', globOptions: { ignore: ['**/test/**', '**/*.ts'] }, noErrorOnMissing: true } From 8b03d68a33432c1d86e34e36b63db46d8f645209 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Thu, 14 Jul 2022 12:30:49 -0700 Subject: [PATCH 065/121] Fix unhandled promise rejections for debug commands (#155220) Fixes #154763 --- .../contrib/debug/browser/debugCommands.ts | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/vs/workbench/contrib/debug/browser/debugCommands.ts b/src/vs/workbench/contrib/debug/browser/debugCommands.ts index 20390fcd0f366..92b3b970f078b 100644 --- a/src/vs/workbench/contrib/debug/browser/debugCommands.ts +++ b/src/vs/workbench/contrib/debug/browser/debugCommands.ts @@ -304,27 +304,27 @@ CommandsRegistry.registerCommand({ CommandsRegistry.registerCommand({ id: REVERSE_CONTINUE_ID, - handler: (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { - getThreadAndRun(accessor, context, thread => thread.reverseContinue()); + handler: async (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { + await getThreadAndRun(accessor, context, thread => thread.reverseContinue()); } }); CommandsRegistry.registerCommand({ id: STEP_BACK_ID, - handler: (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { + handler: async (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { const contextKeyService = accessor.get(IContextKeyService); if (CONTEXT_DISASSEMBLY_VIEW_FOCUS.getValue(contextKeyService)) { - getThreadAndRun(accessor, context, (thread: IThread) => thread.stepBack('instruction')); + await getThreadAndRun(accessor, context, (thread: IThread) => thread.stepBack('instruction')); } else { - getThreadAndRun(accessor, context, (thread: IThread) => thread.stepBack()); + await getThreadAndRun(accessor, context, (thread: IThread) => thread.stepBack()); } } }); CommandsRegistry.registerCommand({ id: TERMINATE_THREAD_ID, - handler: (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { - getThreadAndRun(accessor, context, thread => thread.terminate()); + handler: async (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { + await getThreadAndRun(accessor, context, thread => thread.terminate()); } }); @@ -467,12 +467,12 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ weight: KeybindingWeight.WorkbenchContrib, primary: isWeb ? (KeyMod.Alt | KeyCode.F10) : KeyCode.F10, // Browsers do not allow F10 to be binded so we have to bind an alternative when: CONTEXT_DEBUG_STATE.isEqualTo('stopped'), - handler: (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { + handler: async (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { const contextKeyService = accessor.get(IContextKeyService); if (CONTEXT_DISASSEMBLY_VIEW_FOCUS.getValue(contextKeyService)) { - getThreadAndRun(accessor, context, (thread: IThread) => thread.next('instruction')); + await getThreadAndRun(accessor, context, (thread: IThread) => thread.next('instruction')); } else { - getThreadAndRun(accessor, context, (thread: IThread) => thread.next()); + await getThreadAndRun(accessor, context, (thread: IThread) => thread.next()); } } }); @@ -486,12 +486,12 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ primary: STEP_INTO_KEYBINDING, // Use a more flexible when clause to not allow full screen command to take over when F11 pressed a lot of times when: CONTEXT_DEBUG_STATE.notEqualsTo('inactive'), - handler: (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { + handler: async (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { const contextKeyService = accessor.get(IContextKeyService); if (CONTEXT_DISASSEMBLY_VIEW_FOCUS.getValue(contextKeyService)) { - getThreadAndRun(accessor, context, (thread: IThread) => thread.stepIn('instruction')); + await getThreadAndRun(accessor, context, (thread: IThread) => thread.stepIn('instruction')); } else { - getThreadAndRun(accessor, context, (thread: IThread) => thread.stepIn()); + await getThreadAndRun(accessor, context, (thread: IThread) => thread.stepIn()); } } }); @@ -501,12 +501,12 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ weight: KeybindingWeight.WorkbenchContrib, primary: KeyMod.Shift | KeyCode.F11, when: CONTEXT_DEBUG_STATE.isEqualTo('stopped'), - handler: (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { + handler: async (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { const contextKeyService = accessor.get(IContextKeyService); if (CONTEXT_DISASSEMBLY_VIEW_FOCUS.getValue(contextKeyService)) { - getThreadAndRun(accessor, context, (thread: IThread) => thread.stepOut('instruction')); + await getThreadAndRun(accessor, context, (thread: IThread) => thread.stepOut('instruction')); } else { - getThreadAndRun(accessor, context, (thread: IThread) => thread.stepOut()); + await getThreadAndRun(accessor, context, (thread: IThread) => thread.stepOut()); } } }); @@ -516,8 +516,8 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ weight: KeybindingWeight.WorkbenchContrib + 2, // take priority over focus next part while we are debugging primary: KeyCode.F6, when: CONTEXT_DEBUG_STATE.isEqualTo('running'), - handler: (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { - getThreadAndRun(accessor, context, thread => thread.pause()); + handler: async (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { + await getThreadAndRun(accessor, context, thread => thread.pause()); } }); @@ -649,17 +649,15 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ weight: KeybindingWeight.WorkbenchContrib + 10, // Use a stronger weight to get priority over start debugging F5 shortcut primary: KeyCode.F5, when: CONTEXT_DEBUG_STATE.isEqualTo('stopped'), - handler: (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { - getThreadAndRun(accessor, context, thread => thread.continue()); + handler: async (accessor: ServicesAccessor, _: string, context: CallStackContext | unknown) => { + await getThreadAndRun(accessor, context, thread => thread.continue()); } }); CommandsRegistry.registerCommand({ id: SHOW_LOADED_SCRIPTS_ID, handler: async (accessor) => { - await showLoadedScriptMenu(accessor); - } }); From 5b3742b65a057d97ddae684177b37664b1bb9311 Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Thu, 14 Jul 2022 12:57:48 -0700 Subject: [PATCH 066/121] concat arrays instead of replace because we want all items in the array (#155228) --- build/azure-pipelines/upload-nlsmetadata.js | 1 + build/azure-pipelines/upload-nlsmetadata.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/build/azure-pipelines/upload-nlsmetadata.js b/build/azure-pipelines/upload-nlsmetadata.js index fd69b9a8c3658..c92cd277d859e 100644 --- a/build/azure-pipelines/upload-nlsmetadata.js +++ b/build/azure-pipelines/upload-nlsmetadata.js @@ -20,6 +20,7 @@ function main() { .pipe(merge({ fileName: 'combined.nls.metadata.json', jsonSpace: '', + concatArrays: true, edit: (parsedJson, file) => { if (file.base === 'out-vscode-web-min') { return { vscode: parsedJson }; diff --git a/build/azure-pipelines/upload-nlsmetadata.ts b/build/azure-pipelines/upload-nlsmetadata.ts index 100f5d9cfd51d..4749e1f9605fe 100644 --- a/build/azure-pipelines/upload-nlsmetadata.ts +++ b/build/azure-pipelines/upload-nlsmetadata.ts @@ -33,6 +33,7 @@ function main(): Promise { .pipe(merge({ fileName: 'combined.nls.metadata.json', jsonSpace: '', + concatArrays: true, edit: (parsedJson, file) => { if (file.base === 'out-vscode-web-min') { return { vscode: parsedJson }; From c1374a75c90c5b074d5d392b6291a174c52f600d Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Thu, 14 Jul 2022 13:46:30 -0700 Subject: [PATCH 067/121] remove terminal data when terminal is disposed of for reconnected terminals (#155233) --- src/vs/platform/terminal/common/terminal.ts | 6 +- .../terminal/common/terminalProcess.ts | 2 +- .../tasks/browser/abstractTaskService.ts | 12 ++- .../tasks/browser/terminalTaskSystem.ts | 88 +++++++++++-------- 4 files changed, 64 insertions(+), 44 deletions(-) diff --git a/src/vs/platform/terminal/common/terminal.ts b/src/vs/platform/terminal/common/terminal.ts index c9c7fcde470f4..4c3c72a1f309f 100644 --- a/src/vs/platform/terminal/common/terminal.ts +++ b/src/vs/platform/terminal/common/terminal.ts @@ -168,7 +168,7 @@ export interface IPtyHostAttachTarget { fixedDimensions: IFixedTerminalDimensions | undefined; environmentVariableCollections: ISerializableEnvironmentVariableCollections | undefined; reconnectionOwner?: string; - task?: { label: string; id: string; lastTask?: string; group?: string }; + task?: { label: string; id: string; lastTask: string; group?: string }; } export enum TitleEventSource { @@ -469,7 +469,7 @@ export interface IShellLaunchConfig { /** * This is a terminal that attaches to an already running terminal. */ - attachPersistentProcess?: { id: number; findRevivedId?: boolean; pid: number; title: string; titleSource: TitleEventSource; cwd: string; icon?: TerminalIcon; color?: string; hasChildProcesses?: boolean; fixedDimensions?: IFixedTerminalDimensions; environmentVariableCollections?: ISerializableEnvironmentVariableCollections; reconnectionOwner?: string; task?: { label: string; id: string; lastTask?: string; group?: string } }; + attachPersistentProcess?: { id: number; findRevivedId?: boolean; pid: number; title: string; titleSource: TitleEventSource; cwd: string; icon?: TerminalIcon; color?: string; hasChildProcesses?: boolean; fixedDimensions?: IFixedTerminalDimensions; environmentVariableCollections?: ISerializableEnvironmentVariableCollections; reconnectionOwner?: string; task?: { label: string; id: string; lastTask: string; group?: string } }; /** * Whether the terminal process environment should be exactly as provided in @@ -544,7 +544,7 @@ export interface IShellLaunchConfig { /** * The task associated with this terminal */ - task?: { lastTask?: string; group?: string; label: string; id: string }; + task?: { lastTask: string; group?: string; label: string; id: string }; } export interface ICreateContributedTerminalProfileOptions { diff --git a/src/vs/platform/terminal/common/terminalProcess.ts b/src/vs/platform/terminal/common/terminalProcess.ts index dbbd128282928..4329c9e063523 100644 --- a/src/vs/platform/terminal/common/terminalProcess.ts +++ b/src/vs/platform/terminal/common/terminalProcess.ts @@ -61,7 +61,7 @@ export interface IProcessDetails { fixedDimensions: IFixedTerminalDimensions | undefined; environmentVariableCollections: ISerializableEnvironmentVariableCollections | undefined; reconnectionOwner?: string; - task?: { label: string; id: string; lastTask?: string; group?: string }; + task?: { label: string; id: string; lastTask: string; group?: string }; } export type ITerminalTabLayoutInfoDto = IRawTerminalTabLayoutInfo; diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index 33f885dfe72ef..b1369374838b1 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -200,6 +200,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer private static _nextHandle: number = 0; + private _tasksReconnected: boolean = false; private _schemaVersion: JsonSchemaVersion | undefined; private _executionEngine: ExecutionEngine | undefined; private _workspaceFolders: IWorkspaceFolder[] | undefined; @@ -337,11 +338,14 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer processContext.set(process && !isVirtual); } this._onDidRegisterSupportedExecutions.fire(); + if (this._jsonTasksSupported && !this._tasksReconnected) { + this._reconnectTasks(); + } } - private async _restartTasks(): Promise { + private async _reconnectTasks(): Promise { const recentlyUsedTasks = await this.readRecentTasks(); - if (!recentlyUsedTasks) { + if (!recentlyUsedTasks.length) { return; } for (const task of recentlyUsedTasks) { @@ -354,6 +358,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer this.run(task, undefined, TaskRunSource.Reconnect); } } + this._tasksReconnected = true; } public get onDidStateChange(): Event { @@ -618,7 +623,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer return infosCount > 0; } - public async registerTaskSystem(key: string, info: ITaskSystemInfo): Promise { + public registerTaskSystem(key: string, info: ITaskSystemInfo): void { // Ideally the Web caller of registerRegisterTaskSystem would use the correct key. // However, the caller doesn't know about the workspace folders at the time of the call, even though we know about them here. if (info.platform === Platform.Platform.Web) { @@ -638,7 +643,6 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer if (this.hasTaskSystemInfo) { this._onDidChangeTaskSystemInfo.fire(); - await this._restartTasks(); } } diff --git a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts index b46a625ed1009..23bc33a957e29 100644 --- a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts @@ -63,6 +63,8 @@ interface IActiveTerminalData { state?: TaskEventKind; } +const ReconnectionType = 'Task'; + class InstanceManager { private _currentInstances: number = 0; private _counter: number = 0; @@ -255,6 +257,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { this._logService.trace(`Could not reconnect to terminal ${terminal.instanceId} with process details ${terminal.shellLaunchConfig.attachPersistentProcess}`); } } + this._hasReconnected = true; } public get onDidStateChange(): Event { @@ -270,10 +273,13 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { } public reconnect(task: Task, resolver: ITaskResolver, trigger: string = Triggers.command): ITaskExecuteResult | undefined { - const terminals = this._terminalService.getReconnectedTerminals('Task'); + const terminals = this._terminalService.getReconnectedTerminals(ReconnectionType); + if (!terminals || terminals?.length === 0) { + return; + } if (!this._hasReconnected && terminals && terminals.length > 0) { + this._reviveTerminals(); this._reconnectToTerminals(terminals); - this._hasReconnected = true; } if (this._tasksToReconnect.includes(task._id)) { this._lastTask = new VerifiedTask(task, resolver, trigger); @@ -449,12 +455,14 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { } } - private _removeFromActiveTasks(task: Task): void { - if (!this._activeTasks[task.getMapKey()]) { + private _removeFromActiveTasks(task: Task | string): void { + const key = typeof task === 'string' ? task : task.getMapKey(); + if (!this._activeTasks[key]) { return; } - delete this._activeTasks[task.getMapKey()]; - this._removeInstances(task); + const taskToRemove = this._activeTasks[key]; + delete this._activeTasks[key]; + this._removeInstances(taskToRemove.task); } private _fireTaskEvent(event: ITaskEvent) { @@ -1059,7 +1067,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { const isShellCommand = task.command.runtime === RuntimeType.Shell; const needsFolderQualification = this._contextService.getWorkbenchState() === WorkbenchState.WORKSPACE; const terminalName = this._createTerminalName(task); - const type = 'Task'; + const type = ReconnectionType; const originalCommand = task.command.name; if (isShellCommand) { let os: Platform.OperatingSystem; @@ -1289,17 +1297,40 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { } private _reviveTerminals(): void { - if (Object.entries(this._terminals).length === 0) { - for (const terminal of this._terminalService.instances) { - if (terminal.shellLaunchConfig.attachPersistentProcess?.task?.lastTask) { - this._terminals[terminal.instanceId] = { lastTask: terminal.shellLaunchConfig.attachPersistentProcess.task.lastTask, group: terminal.shellLaunchConfig.attachPersistentProcess.task.group, terminal }; - } + if (Object.entries(this._terminals).length > 0) { + return; + } + const terminals = this._terminalService.getReconnectedTerminals(ReconnectionType)?.filter(t => !t.isDisposed); + if (!terminals?.length) { + return; + } + for (const terminal of terminals) { + const task = terminal.shellLaunchConfig.attachPersistentProcess?.task; + if (!task) { + continue; } + const terminalData = { lastTask: task.lastTask, group: task.group, terminal }; + this._terminals[terminal.instanceId] = terminalData; + terminal.onDisposed(() => this._deleteTaskAndTerminal(terminal, terminalData)); + } + } + + private _deleteTaskAndTerminal(terminal: ITerminalInstance, terminalData: ITerminalData): void { + delete this._terminals[terminal.instanceId]; + delete this._sameTaskTerminals[terminalData.lastTask]; + this._idleTaskTerminals.delete(terminalData.lastTask); + // Delete the task now as a work around for cases when the onExit isn't fired. + // This can happen if the terminal wasn't shutdown with an "immediate" flag and is expected. + // For correct terminal re-use, the task needs to be deleted immediately. + // Note that this shouldn't be a problem anymore since user initiated terminal kills are now immediate. + const mapKey = terminalData.lastTask; + this._removeFromActiveTasks(mapKey); + if (this._busyTasks[mapKey]) { + delete this._busyTasks[mapKey]; } } private async _createTerminal(task: CustomTask | ContributedTask, resolver: VariableResolver, workspaceFolder: IWorkspaceFolder | undefined): Promise<[ITerminalInstance | undefined, TaskError | undefined]> { - this._reviveTerminals(); const platform = resolver.taskSystemInfo ? resolver.taskSystemInfo.platform : Platform.platform; const options = await this._resolveOptions(resolver, task.command.options); const presentationOptions = task.command.presentation; @@ -1398,29 +1429,14 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { } this._terminalCreationQueue = this._terminalCreationQueue.then(() => this._doCreateTerminal(group, launchConfigs!)); - const result: ITerminalInstance = (await this._terminalCreationQueue)!; - result.shellLaunchConfig.task = { lastTask: taskKey, group, label: task._label, id: task._id }; - result.shellLaunchConfig.reconnectionOwner = 'Task'; - const terminalKey = result.instanceId.toString(); - result.onDisposed(() => { - const terminalData = this._terminals[terminalKey]; - if (terminalData) { - delete this._terminals[terminalKey]; - delete this._sameTaskTerminals[terminalData.lastTask]; - this._idleTaskTerminals.delete(terminalData.lastTask); - // Delete the task now as a work around for cases when the onExit isn't fired. - // This can happen if the terminal wasn't shutdown with an "immediate" flag and is expected. - // For correct terminal re-use, the task needs to be deleted immediately. - // Note that this shouldn't be a problem anymore since user initiated terminal kills are now immediate. - const mapKey = task.getMapKey(); - this._removeFromActiveTasks(task); - if (this._busyTasks[mapKey]) { - delete this._busyTasks[mapKey]; - } - } - }); - this._terminals[terminalKey] = { terminal: result, lastTask: taskKey, group }; - return [result, undefined]; + const terminal: ITerminalInstance = (await this._terminalCreationQueue)!; + terminal.shellLaunchConfig.task = { lastTask: taskKey, group, label: task._label, id: task._id }; + terminal.shellLaunchConfig.reconnectionOwner = ReconnectionType; + const terminalKey = terminal.instanceId.toString(); + const terminalData = { terminal: terminal, lastTask: taskKey, group }; + terminal.onDisposed(() => this._deleteTaskAndTerminal(terminal, terminalData)); + this._terminals[terminalKey] = terminalData; + return [terminal, undefined]; } private _buildShellCommandLine(platform: Platform.Platform, shellExecutable: string, shellOptions: IShellConfiguration | undefined, command: CommandString, originalCommand: CommandString | undefined, args: CommandString[]): string { From a69dc7ca05fee0dcdf47078bb0f5851133c3c5c8 Mon Sep 17 00:00:00 2001 From: SteVen Batten <6561887+sbatten@users.noreply.github.com> Date: Thu, 14 Jul 2022 14:40:53 -0700 Subject: [PATCH 068/121] Allow menubar to convert into hamburger below threshold (#155223) fixes #152906 --- src/vs/base/browser/ui/menu/menu.ts | 3 +-- src/vs/base/browser/ui/menu/menubar.css | 5 +++++ src/vs/base/browser/ui/menu/menubar.ts | 22 +++++++++++++++++-- .../parts/titlebar/media/titlebarpart.css | 1 + .../browser/parts/titlebar/menubarControl.ts | 16 -------------- .../browser/parts/titlebar/titlebarPart.ts | 8 ------- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/vs/base/browser/ui/menu/menu.ts b/src/vs/base/browser/ui/menu/menu.ts index dce1f797febb1..7a22cb3503899 100644 --- a/src/vs/base/browser/ui/menu/menu.ts +++ b/src/vs/base/browser/ui/menu/menu.ts @@ -33,8 +33,7 @@ export const MENU_ESCAPED_MNEMONIC_REGEX = /(&)?(&)([^\s&])/g; export enum Direction { Right, - Left, - Down + Left } export interface IMenuOptions { diff --git a/src/vs/base/browser/ui/menu/menubar.css b/src/vs/base/browser/ui/menu/menubar.css index 64e309bf5dc54..3a65f9a882985 100644 --- a/src/vs/base/browser/ui/menu/menubar.css +++ b/src/vs/base/browser/ui/menu/menubar.css @@ -13,6 +13,10 @@ overflow: hidden; } +.menubar.overflow-menu-only { + width: 38px; +} + .fullscreen .menubar:not(.compact) { margin: 0px; padding: 4px 5px; @@ -93,6 +97,7 @@ justify-content: center; } +.menubar:not(.compact) .menubar-menu-button:first-child .toolbar-toggle-more::before, .menubar.compact .toolbar-toggle-more::before { content: "\eb94" !important; } diff --git a/src/vs/base/browser/ui/menu/menubar.ts b/src/vs/base/browser/ui/menu/menubar.ts index 10dd697e7a4bc..572b33983ccba 100644 --- a/src/vs/base/browser/ui/menu/menubar.ts +++ b/src/vs/base/browser/ui/menu/menubar.ts @@ -334,8 +334,6 @@ export class MenuBar extends Disposable { triggerKeys.push(KeyCode.RightArrow); } else if (this.options.compactMode === Direction.Left) { triggerKeys.push(KeyCode.LeftArrow); - } else if (this.options.compactMode === Direction.Down) { - triggerKeys.push(KeyCode.DownArrow); } } @@ -475,6 +473,11 @@ export class MenuBar extends Disposable { return; } + const overflowMenuOnlyClass = 'overflow-menu-only'; + + // Remove overflow only restriction to allow the most space + this.container.classList.toggle(overflowMenuOnlyClass, false); + const sizeAvailable = this.container.offsetWidth; let currentSize = 0; let full = this.isCompact; @@ -501,6 +504,18 @@ export class MenuBar extends Disposable { } } + + // If below minimium menu threshold, show the overflow menu only as hamburger menu + if (this.numMenusShown - 1 <= showableMenus.length / 2) { + for (const menuBarMenu of showableMenus) { + menuBarMenu.buttonElement.style.visibility = 'hidden'; + } + + full = true; + this.numMenusShown = 0; + currentSize = 0; + } + // Overflow if (this.isCompact) { this.overflowMenu.actions = []; @@ -540,6 +555,9 @@ export class MenuBar extends Disposable { this.container.appendChild(this.overflowMenu.buttonElement); this.overflowMenu.buttonElement.style.visibility = 'hidden'; } + + // If we are only showing the overflow, add this class to avoid taking up space + this.container.classList.toggle(overflowMenuOnlyClass, this.numMenusShown === 0); } private updateLabels(titleElement: HTMLElement, buttonElement: HTMLElement, label: string): void { diff --git a/src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css b/src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css index 29f1142364e59..9b4d5aada91bc 100644 --- a/src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css +++ b/src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css @@ -133,6 +133,7 @@ /* width */ width: 16px; + flex-shrink: 0; } .monaco-workbench .part.titlebar>.titlebar-container>.window-title>.command-center .action-item.quickopen>.action-label { diff --git a/src/vs/workbench/browser/parts/titlebar/menubarControl.ts b/src/vs/workbench/browser/parts/titlebar/menubarControl.ts index 6c0a24014c852..b431d4df48ebe 100644 --- a/src/vs/workbench/browser/parts/titlebar/menubarControl.ts +++ b/src/vs/workbench/browser/parts/titlebar/menubarControl.ts @@ -581,17 +581,6 @@ export class CustomMenubarControl extends MenubarControl { return getMenuBarVisibility(this.configurationService); } - private get currentCommandCenterEnabled(): boolean { - const settingValue = this.configurationService.getValue('window.commandCenter'); - - let enableCommandCenter = false; - if (typeof settingValue === 'boolean') { - enableCommandCenter = !!settingValue; - } - - return enableCommandCenter; - } - private get currentDisableMenuBarAltFocus(): boolean { const settingValue = this.configurationService.getValue('window.customMenuBarAltFocus'); @@ -637,11 +626,6 @@ export class CustomMenubarControl extends MenubarControl { private get currentCompactMenuMode(): Direction | undefined { if (this.currentMenubarVisibility !== 'compact') { - // With the command center enabled, use compact menu in title bar and flow to the right - if (this.currentCommandCenterEnabled) { - return Direction.Down; - } - return undefined; } diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index 2c7855bd9cc22..17b5eb918bb95 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -157,14 +157,6 @@ export class TitlebarPart extends Part implements ITitleService { this.installMenubar(); } } - - // Trigger a re-install of the menubar with command center change - if (event.affectsConfiguration('window.commandCenter')) { - if (this.currentMenubarVisibility !== 'compact') { - this.uninstallMenubar(); - this.installMenubar(); - } - } } if (this.titleBarStyle !== 'native' && this.layoutControls && event.affectsConfiguration('workbench.layoutControl.enabled')) { From ee1a93f57d36546bb35de4dcb6c238b8373de58e Mon Sep 17 00:00:00 2001 From: Miguel Solorio Date: Thu, 14 Jul 2022 15:04:46 -0700 Subject: [PATCH 069/121] Increase contrast for diff inserted bg (#154969) --- src/vs/platform/theme/common/colorRegistry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/platform/theme/common/colorRegistry.ts b/src/vs/platform/theme/common/colorRegistry.ts index 3b7889d5caca5..0be76bfc597a7 100644 --- a/src/vs/platform/theme/common/colorRegistry.ts +++ b/src/vs/platform/theme/common/colorRegistry.ts @@ -401,7 +401,7 @@ export const editorLightBulbAutoFixForeground = registerColor('editorLightBulbAu /** * Diff Editor Colors */ -export const defaultInsertColor = new Color(new RGBA(155, 185, 85, 0.2)); +export const defaultInsertColor = new Color(new RGBA(53, 175, 34, 0.24)); export const defaultRemoveColor = new Color(new RGBA(255, 0, 0, 0.2)); export const diffInserted = registerColor('diffEditor.insertedTextBackground', { dark: defaultInsertColor, light: defaultInsertColor, hcDark: null, hcLight: null }, nls.localize('diffEditorInserted', 'Background color for text that got inserted. The color must not be opaque so as not to hide underlying decorations.'), true); From fba254e6293110acfc491535efd1c13e46b4a140 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Thu, 14 Jul 2022 18:14:35 -0700 Subject: [PATCH 070/121] fix command not found warning (#155250) fix command not found part of #155163 --- src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts | 3 ++- src/vs/workbench/contrib/tasks/browser/task.contribution.ts | 4 ++-- src/vs/workbench/contrib/tasks/common/taskService.ts | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index b1369374838b1..4bfc497f05a59 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -57,7 +57,7 @@ import { TaskSettingId, TasksSchemaProperties } from 'vs/workbench/contrib/tasks/common/tasks'; -import { ITaskService, ITaskProvider, IProblemMatcherRunOptions, ICustomizationProperties, ITaskFilter, IWorkspaceFolderTaskResult, CustomExecutionSupportedContext, ShellExecutionSupportedContext, ProcessExecutionSupportedContext } from 'vs/workbench/contrib/tasks/common/taskService'; +import { ITaskService, ITaskProvider, IProblemMatcherRunOptions, ICustomizationProperties, ITaskFilter, IWorkspaceFolderTaskResult, CustomExecutionSupportedContext, ShellExecutionSupportedContext, ProcessExecutionSupportedContext, TaskCommandsRegistered } from 'vs/workbench/contrib/tasks/common/taskService'; import { getTemplates as getTaskTemplates } from 'vs/workbench/contrib/tasks/common/taskTemplates'; import * as TaskConfig from '../common/taskConfiguration'; @@ -491,6 +491,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer this._openTaskFile(resource, TaskSourceKind.WorkspaceFile); } }); + TaskCommandsRegistered.bindTo(this._contextKeyService).set(true); } private get workspaceFolders(): IWorkspaceFolder[] { diff --git a/src/vs/workbench/contrib/tasks/browser/task.contribution.ts b/src/vs/workbench/contrib/tasks/browser/task.contribution.ts index 00c85294b7bd6..3b7aa6162afba 100644 --- a/src/vs/workbench/contrib/tasks/browser/task.contribution.ts +++ b/src/vs/workbench/contrib/tasks/browser/task.contribution.ts @@ -21,7 +21,7 @@ import { StatusbarAlignment, IStatusbarService, IStatusbarEntryAccessor, IStatus import { IOutputChannelRegistry, Extensions as OutputExt } from 'vs/workbench/services/output/common/output'; import { ITaskEvent, TaskEventKind, TaskGroup, TaskSettingId, TASKS_CATEGORY, TASK_RUNNING_STATE } from 'vs/workbench/contrib/tasks/common/tasks'; -import { ITaskService, ProcessExecutionSupportedContext, ShellExecutionSupportedContext } from 'vs/workbench/contrib/tasks/common/taskService'; +import { ITaskService, ProcessExecutionSupportedContext, ShellExecutionSupportedContext, TaskCommandsRegistered } from 'vs/workbench/contrib/tasks/common/taskService'; import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry, IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { RunAutomaticTasks, ManageAutomaticTaskRunning } from 'vs/workbench/contrib/tasks/browser/runAutomaticTasks'; @@ -359,7 +359,7 @@ MenuRegistry.appendMenuItem(MenuId.CommandPalette, { KeybindingsRegistry.registerKeybindingRule({ id: 'workbench.action.tasks.build', weight: KeybindingWeight.WorkbenchContrib, - when: undefined, + when: TaskCommandsRegistered, primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyB }); diff --git a/src/vs/workbench/contrib/tasks/common/taskService.ts b/src/vs/workbench/contrib/tasks/common/taskService.ts index 86acc2a6a03a7..afc0ed385fa27 100644 --- a/src/vs/workbench/contrib/tasks/common/taskService.ts +++ b/src/vs/workbench/contrib/tasks/common/taskService.ts @@ -19,6 +19,7 @@ export { ITaskSummary, Task, ITaskTerminateResponse as TaskTerminateResponse }; export const CustomExecutionSupportedContext = new RawContextKey('customExecutionSupported', true, nls.localize('tasks.customExecutionSupported', "Whether CustomExecution tasks are supported. Consider using in the when clause of a \'taskDefinition\' contribution.")); export const ShellExecutionSupportedContext = new RawContextKey('shellExecutionSupported', false, nls.localize('tasks.shellExecutionSupported', "Whether ShellExecution tasks are supported. Consider using in the when clause of a \'taskDefinition\' contribution.")); +export const TaskCommandsRegistered = new RawContextKey('taskCommandsRegistered', false, nls.localize('tasks.taskCommandsRegistered', "Whether the task commands have been registered yet")); export const ProcessExecutionSupportedContext = new RawContextKey('processExecutionSupported', false, nls.localize('tasks.processExecutionSupported', "Whether ProcessExecution tasks are supported. Consider using in the when clause of a \'taskDefinition\' contribution.")); export const ITaskService = createDecorator('taskService'); From 486b3018b49def3312c9d69578d41219b895be09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Fri, 15 Jul 2022 11:10:39 +0200 Subject: [PATCH 071/121] Publish stage should wait for web stage (#155284) publish stage should wait for web stage --- build/azure-pipelines/product-publish.ps1 | 1 + build/azure-pipelines/product-publish.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/build/azure-pipelines/product-publish.ps1 b/build/azure-pipelines/product-publish.ps1 index 5abfed48dca9c..5006ec61a3027 100644 --- a/build/azure-pipelines/product-publish.ps1 +++ b/build/azure-pipelines/product-publish.ps1 @@ -46,6 +46,7 @@ $stages = @( if ($env:VSCODE_BUILD_STAGE_WINDOWS -eq 'True') { 'Windows' } if ($env:VSCODE_BUILD_STAGE_LINUX -eq 'True') { 'Linux' } if ($env:VSCODE_BUILD_STAGE_MACOS -eq 'True') { 'macOS' } + if ($env:VSCODE_BUILD_STAGE_WEB -eq 'True') { 'Web' } ) do { diff --git a/build/azure-pipelines/product-publish.yml b/build/azure-pipelines/product-publish.yml index 4d711aba1203e..80076fd666da2 100644 --- a/build/azure-pipelines/product-publish.yml +++ b/build/azure-pipelines/product-publish.yml @@ -109,6 +109,7 @@ steps: if ($env:VSCODE_BUILD_STAGE_WINDOWS -eq 'True') { 'Windows' } if ($env:VSCODE_BUILD_STAGE_LINUX -eq 'True') { 'Linux' } if ($env:VSCODE_BUILD_STAGE_MACOS -eq 'True') { 'macOS' } + if ($env:VSCODE_BUILD_STAGE_WEB -eq 'True') { 'Web' } ) Write-Host "Stages to check: $stages" From eb6eb04540f6f5b2d702d5e47d607e4a57a13b19 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 15 Jul 2022 11:11:19 +0200 Subject: [PATCH 072/121] move custom hover logic into `BaseActionViewItem` (#155278) fixes https://github.com/microsoft/vscode/issues/153429 --- .../browser/ui/actionbar/actionViewItems.ts | 47 ++++++++++--------- .../browser/menuEntryActionViewItem.ts | 4 +- .../parts/titlebar/commandCenterControl.ts | 10 ++-- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/vs/base/browser/ui/actionbar/actionViewItems.ts b/src/vs/base/browser/ui/actionbar/actionViewItems.ts index a41daab42afaa..7d0833e27bee5 100644 --- a/src/vs/base/browser/ui/actionbar/actionViewItems.ts +++ b/src/vs/base/browser/ui/actionbar/actionViewItems.ts @@ -23,6 +23,7 @@ export interface IBaseActionViewItemOptions { draggable?: boolean; isMenu?: boolean; useEventAsContext?: boolean; + hoverDelegate?: IHoverDelegate; } export class BaseActionViewItem extends Disposable implements IActionViewItem { @@ -32,6 +33,8 @@ export class BaseActionViewItem extends Disposable implements IActionViewItem { _context: unknown; readonly _action: IAction; + private customHover?: ICustomHover; + get action() { return this._action; } @@ -210,8 +213,27 @@ export class BaseActionViewItem extends Disposable implements IActionViewItem { // implement in subclass } + protected getTooltip(): string | undefined { + return this.getAction().tooltip; + } + protected updateTooltip(): void { - // implement in subclass + if (!this.element) { + return; + } + const title = this.getTooltip() ?? ''; + this.element.setAttribute('aria-label', title); + if (!this.options.hoverDelegate) { + this.element.title = title; + } else { + this.element.title = ''; + if (!this.customHover) { + this.customHover = setupCustomHover(this.options.hoverDelegate, this.element, title); + this._store.add(this.customHover); + } else { + this.customHover.update(title); + } + } } protected updateClass(): void { @@ -236,7 +258,6 @@ export interface IActionViewItemOptions extends IBaseActionViewItemOptions { icon?: boolean; label?: boolean; keybinding?: string | null; - hoverDelegate?: IHoverDelegate; } export class ActionViewItem extends BaseActionViewItem { @@ -245,7 +266,6 @@ export class ActionViewItem extends BaseActionViewItem { protected override options: IActionViewItemOptions; private cssClass?: string; - private customHover?: ICustomHover; constructor(context: unknown, action: IAction, options: IActionViewItemOptions = {}) { super(context, action, options); @@ -317,7 +337,7 @@ export class ActionViewItem extends BaseActionViewItem { } } - override updateTooltip(): void { + override getTooltip() { let title: string | null = null; if (this.getAction().tooltip) { @@ -330,24 +350,7 @@ export class ActionViewItem extends BaseActionViewItem { title = nls.localize({ key: 'titleLabel', comment: ['action title', 'action keybinding'] }, "{0} ({1})", title, this.options.keybinding); } } - this._applyUpdateTooltip(title); - } - - protected _applyUpdateTooltip(title: string | undefined | null): void { - if (title && this.label) { - this.label.setAttribute('aria-label', title); - if (!this.options.hoverDelegate) { - this.label.title = title; - } else { - this.label.title = ''; - if (!this.customHover) { - this.customHover = setupCustomHover(this.options.hoverDelegate, this.label, title); - this._store.add(this.customHover); - } else { - this.customHover.update(title); - } - } - } + return title ?? undefined; } override updateClass(): void { diff --git a/src/vs/platform/actions/browser/menuEntryActionViewItem.ts b/src/vs/platform/actions/browser/menuEntryActionViewItem.ts index e9353c86faab8..4c98b03d76a10 100644 --- a/src/vs/platform/actions/browser/menuEntryActionViewItem.ts +++ b/src/vs/platform/actions/browser/menuEntryActionViewItem.ts @@ -231,7 +231,7 @@ export class MenuEntryActionViewItem extends ActionViewItem { } } - override updateTooltip(): void { + override getTooltip() { const keybinding = this._keybindingService.lookupKeybinding(this._commandAction.id, this._contextKeyService); const keybindingLabel = keybinding && keybinding.getLabel(); @@ -249,7 +249,7 @@ export class MenuEntryActionViewItem extends ActionViewItem { title = localize('titleAndKbAndAlt', "{0}\n[{1}] {2}", title, UILabelProvider.modifierLabels[OS].altKey, altTitleSection); } - this._applyUpdateTooltip(title); + return title; } override updateClass(): void { diff --git a/src/vs/workbench/browser/parts/titlebar/commandCenterControl.ts b/src/vs/workbench/browser/parts/titlebar/commandCenterControl.ts index 2b383111c09bd..8ccb1dcc33a67 100644 --- a/src/vs/workbench/browser/parts/titlebar/commandCenterControl.ts +++ b/src/vs/workbench/browser/parts/titlebar/commandCenterControl.ts @@ -65,15 +65,14 @@ export class CommandCenterControl { searchIcon.classList.add('search-icon'); this.workspaceTitle.classList.add('search-label'); - this._updateFromWindowTitle(); + this.updateTooltip(); reset(this.label, searchIcon, this.workspaceTitle); // this._renderAllQuickPickItem(container); - this._store.add(windowTitle.onDidChange(this._updateFromWindowTitle, this)); + this._store.add(windowTitle.onDidChange(this.updateTooltip, this)); } - private _updateFromWindowTitle() { - + override getTooltip() { // label: just workspace name and optional decorations const { prefix, suffix } = windowTitle.getTitleDecorations(); let label = windowTitle.workspaceName; @@ -93,7 +92,8 @@ export class CommandCenterControl { const title = kb ? localize('title', "Search {0} ({1}) \u2014 {2}", windowTitle.workspaceName, kb, windowTitle.value) : localize('title2', "Search {0} \u2014 {1}", windowTitle.workspaceName, windowTitle.value); - this._applyUpdateTooltip(title); + + return title; } } return instantiationService.createInstance(InputLikeViewItem, action, { hoverDelegate }); From 2db5990c8242f9b04648e6bb130515a6ad0296a0 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 14 Jul 2022 18:15:13 -0700 Subject: [PATCH 073/121] Fix md document links for untitled files (#155248) --- .../markdown-language-features/server/src/workspace.ts | 5 ++++- .../markdown-language-features/src/test/documentLink.test.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/extensions/markdown-language-features/server/src/workspace.ts b/extensions/markdown-language-features/server/src/workspace.ts index 7838c20f32895..5847d0c55053b 100644 --- a/extensions/markdown-language-features/server/src/workspace.ts +++ b/extensions/markdown-language-features/server/src/workspace.ts @@ -162,7 +162,10 @@ export class VsCodeClientWorkspace implements md.IWorkspace { } } - stat(resource: URI): Promise { + async stat(resource: URI): Promise { + if (this._documentCache.has(resource) || this.documents.get(resource.toString())) { + return { isDirectory: false }; + } return this.connection.sendRequest(protocol.statFileRequestType, { uri: resource.toString() }); } diff --git a/extensions/markdown-language-features/src/test/documentLink.test.ts b/extensions/markdown-language-features/src/test/documentLink.test.ts index 6902d68976230..37fe52e3dfb64 100644 --- a/extensions/markdown-language-features/src/test/documentLink.test.ts +++ b/extensions/markdown-language-features/src/test/documentLink.test.ts @@ -134,7 +134,7 @@ async function getLinksForFile(file: vscode.Uri): Promise } }); - test.skip('Should navigate to fragment within current untitled file', async () => { // TODO: skip for now for ls migration + test('Should navigate to fragment within current untitled file', async () => { // TODO: skip for now for ls migration const testFile = workspaceFile('x.md').with({ scheme: 'untitled' }); await withFileContents(testFile, joinLines( '[](#second)', From a014cffc3393aa242bb897093c07046c2c805ecf Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Fri, 15 Jul 2022 11:12:33 +0200 Subject: [PATCH 074/121] Fix #155158 (#155288) --- .../extensions/test/browser/extensionService.test.ts | 5 ++--- src/vs/workbench/test/browser/workbenchTestServices.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/services/extensions/test/browser/extensionService.test.ts b/src/vs/workbench/services/extensions/test/browser/extensionService.test.ts index eaa0069f098b9..88c83a94c72c3 100644 --- a/src/vs/workbench/services/extensions/test/browser/extensionService.test.ts +++ b/src/vs/workbench/services/extensions/test/browser/extensionService.test.ts @@ -29,12 +29,11 @@ import { ExtensionManifestPropertiesService, IExtensionManifestPropertiesService import { ExtensionHostKind, ExtensionRunningLocation, IExtensionHost, IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle'; import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; -import { TestEnvironmentService, TestFileService, TestLifecycleService, TestRemoteAgentService, TestWebExtensionsScannerService, TestWorkbenchExtensionEnablementService, TestWorkbenchExtensionManagementService } from 'vs/workbench/test/browser/workbenchTestServices'; +import { TestEnvironmentService, TestFileService, TestLifecycleService, TestRemoteAgentService, TestUserDataProfileService, TestWebExtensionsScannerService, TestWorkbenchExtensionEnablementService, TestWorkbenchExtensionManagementService } from 'vs/workbench/test/browser/workbenchTestServices'; import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices'; import { mock } from 'vs/base/test/common/mock'; import { IExtensionHostManager } from 'vs/workbench/services/extensions/common/extensionHostManager'; import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile'; -import { UserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfileService'; import { IUserDataProfilesService, UserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile'; import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'; import { UriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentityService'; @@ -182,7 +181,7 @@ suite('ExtensionService', () => { [IEnvironmentService, TestEnvironmentService], [IWorkspaceTrustEnablementService, WorkspaceTrustEnablementService], [IUserDataProfilesService, UserDataProfilesService], - [IUserDataProfileService, UserDataProfileService], + [IUserDataProfileService, TestUserDataProfileService], [IUriIdentityService, UriIdentityService], ]); extService = instantiationService.get(IExtensionService); diff --git a/src/vs/workbench/test/browser/workbenchTestServices.ts b/src/vs/workbench/test/browser/workbenchTestServices.ts index b910e0408c459..ff291f79a9fde 100644 --- a/src/vs/workbench/test/browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/browser/workbenchTestServices.ts @@ -160,7 +160,7 @@ import { ExtensionIdentifier, ExtensionType, IExtension, IExtensionDescription, import { ISocketFactory } from 'vs/platform/remote/common/remoteAgentConnection'; import { IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment'; import { ILayoutOffsetInfo } from 'vs/platform/layout/browser/layoutService'; -import { IUserDataProfilesService, UserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile'; +import { IUserDataProfilesService, toUserDataProfile, UserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile'; import { UserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfileService'; import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile'; import { EnablementState, IExtensionManagementServer, IScannedExtension, IWebExtensionsScannerService, IWorkbenchExtensionEnablementService, IWorkbenchExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; @@ -2006,6 +2006,14 @@ export class TestWorkbenchExtensionManagementService implements IWorkbenchExtens async getTargetPlatform(): Promise { return TargetPlatform.UNDEFINED; } } +export class TestUserDataProfileService implements IUserDataProfileService { + + readonly _serviceBrand: undefined; + readonly onDidChangeCurrentProfile = Event.None; + readonly currentProfile = toUserDataProfile('test', URI.file('tests').with({ scheme: 'vscode-tests' })); + async updateCurrentProfile(): Promise { } +} + export class TestWebExtensionsScannerService implements IWebExtensionsScannerService { _serviceBrand: undefined; onDidChangeProfileExtensions = Event.None; From 09db93eb049b9a552e9b83392152b788e584ebbd Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Thu, 14 Jul 2022 18:43:10 -0700 Subject: [PATCH 075/121] make sure execute in terminal is reached (#155254) --- .../contrib/tasks/browser/terminalTaskSystem.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts index 23bc33a957e29..0499c4cd0b599 100644 --- a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts @@ -192,6 +192,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { private _terminals: IStringDictionary; private _idleTaskTerminals: LinkedMap; private _sameTaskTerminals: IStringDictionary; + private _terminalForTask: ITerminalInstance | undefined; private _taskSystemInfoResolver: ITaskSystemInfoResolver; private _lastTask: VerifiedTask | undefined; // Should always be set in run @@ -282,8 +283,8 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { this._reconnectToTerminals(terminals); } if (this._tasksToReconnect.includes(task._id)) { - this._lastTask = new VerifiedTask(task, resolver, trigger); - this.rerun(); + this._terminalForTask = terminals.find(t => t.shellLaunchConfig.attachPersistentProcess?.task?.id === task._id); + this.run(task, resolver, trigger); } return undefined; } @@ -305,7 +306,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { } try { - const executeResult = { kind: TaskExecuteKind.Started, task, started: {}, promise: this._executeTask(task, resolver, trigger, new Set()) }; + const executeResult = { kind: TaskExecuteKind.Started, task, started: {}, promise: this._executeTask(task, resolver, trigger, new Set(), undefined) }; executeResult.promise.then(summary => { this._lastTask = this._currentTask; }); @@ -880,7 +881,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { })); watchingProblemMatcher.aboutToStart(); let delayer: Async.Delayer | undefined = undefined; - [terminal, error] = await this._createTerminal(task, resolver, workspaceFolder); + [terminal, error] = this._terminalForTask ? [this._terminalForTask, undefined] : await this._createTerminal(task, resolver, workspaceFolder); if (error) { return Promise.reject(new Error((error).message)); @@ -962,7 +963,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { }); }); } else { - [terminal, error] = await this._createTerminal(task, resolver, workspaceFolder); + [terminal, error] = this._terminalForTask ? [this._terminalForTask, undefined] : await this._createTerminal(task, resolver, workspaceFolder); if (error) { return Promise.reject(new Error((error).message)); From 9e12edf320c8336f039f39ce151d8147549eaeea Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Fri, 15 Jul 2022 11:44:46 +0200 Subject: [PATCH 076/121] Fix #155157 (#155290) --- .../experimentService.test.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/vs/workbench/contrib/experiments/test/electron-browser/experimentService.test.ts b/src/vs/workbench/contrib/experiments/test/electron-browser/experimentService.test.ts index 2dbfdafd6947b..7c111e51eda3e 100644 --- a/src/vs/workbench/contrib/experiments/test/electron-browser/experimentService.test.ts +++ b/src/vs/workbench/contrib/experiments/test/electron-browser/experimentService.test.ts @@ -6,14 +6,13 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; import { timeout } from 'vs/base/common/async'; -import { Emitter } from 'vs/base/common/event'; +import { Emitter, Event } from 'vs/base/common/event'; import { OS } from 'vs/base/common/platform'; import { URI } from 'vs/base/common/uri'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; -import { DidUninstallExtensionEvent, IExtensionIdentifier, IExtensionManagementService, ILocalExtension, InstallExtensionEvent, InstallExtensionResult } from 'vs/platform/extensionManagement/common/extensionManagement'; +import { DidUninstallExtensionEvent, IExtensionIdentifier, ILocalExtension, InstallExtensionEvent, InstallExtensionResult } from 'vs/platform/extensionManagement/common/extensionManagement'; import { getGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil'; -import { ExtensionManagementService } from 'vs/platform/extensionManagement/node/extensionManagementService'; import { ExtensionType } from 'vs/platform/extensions/common/extensions'; import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock'; import { IProductService } from 'vs/platform/product/common/productService'; @@ -26,7 +25,8 @@ import { IURLService } from 'vs/platform/url/common/url'; import { NativeURLService } from 'vs/platform/url/common/urlService'; import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust'; import { currentSchemaVersion, ExperimentActionType, ExperimentService, ExperimentState, getCurrentActivationRecord, IExperiment } from 'vs/workbench/contrib/experiments/common/experimentService'; -import { IWorkbenchExtensionEnablementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; +import { IWorkbenchExtensionEnablementService, IWorkbenchExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; +import { ExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagementService'; import { TestExtensionEnablementService } from 'vs/workbench/services/extensionManagement/test/browser/extensionEnablementService.test'; import { IExtensionService, IWillActivateEvent } from 'vs/workbench/services/extensions/common/extensions'; import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle'; @@ -84,15 +84,16 @@ suite('Experiment Service', () => { instantiationService.stub(IExtensionService, TestExtensionService); instantiationService.stub(IExtensionService, 'onWillActivateByEvent', activationEvent.event); instantiationService.stub(IUriIdentityService, UriIdentityService); - instantiationService.stub(IExtensionManagementService, ExtensionManagementService); - instantiationService.stub(IExtensionManagementService, 'onInstallExtension', installEvent.event); - instantiationService.stub(IExtensionManagementService, 'onDidInstallExtensions', didInstallEvent.event); - instantiationService.stub(IExtensionManagementService, 'onUninstallExtension', uninstallEvent.event); - instantiationService.stub(IExtensionManagementService, 'onDidUninstallExtension', didUninstallEvent.event); + instantiationService.stub(IWorkbenchExtensionManagementService, ExtensionManagementService); + instantiationService.stub(IWorkbenchExtensionManagementService, 'onInstallExtension', installEvent.event); + instantiationService.stub(IWorkbenchExtensionManagementService, 'onDidInstallExtensions', didInstallEvent.event); + instantiationService.stub(IWorkbenchExtensionManagementService, 'onUninstallExtension', uninstallEvent.event); + instantiationService.stub(IWorkbenchExtensionManagementService, 'onDidUninstallExtension', didUninstallEvent.event); + instantiationService.stub(IWorkbenchExtensionManagementService, 'onDidChangeProfileExtensions', Event.None); instantiationService.stub(IWorkbenchExtensionEnablementService, new TestExtensionEnablementService(instantiationService)); instantiationService.stub(ITelemetryService, NullTelemetryService); instantiationService.stub(IURLService, NativeURLService); - instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]); + instantiationService.stubPromise(IWorkbenchExtensionManagementService, 'getInstalled', [local]); testConfigurationService = new TestConfigurationService(); instantiationService.stub(IConfigurationService, testConfigurationService); instantiationService.stub(ILifecycleService, new TestLifecycleService()); From b27c9157d282be43ce112999097d2bf118c50698 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 15 Jul 2022 12:36:33 +0200 Subject: [PATCH 077/121] Revert "remove es5ClassCompat" This reverts commit 05d2534e663a327f37c812c51884aa543dea104b. --- src/vs/workbench/api/common/extHostTypes.ts | 82 +++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index e50faecd5959d..74d65b863365d 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -19,6 +19,16 @@ import { IRelativePatternDto } from 'vs/workbench/api/common/extHost.protocol'; import { CellEditType, ICellPartialMetadataEdit, IDocumentMetadataEdit } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import type * as vscode from 'vscode'; +function es5ClassCompat(target: Function): any { + ///@ts-expect-error + function _() { return Reflect.construct(target, arguments, this.constructor); } + Object.defineProperty(_, 'name', Object.getOwnPropertyDescriptor(target, 'name')!); + Object.setPrototypeOf(_, target); + Object.setPrototypeOf(_.prototype, target.prototype); + return _; +} + +@es5ClassCompat export class Disposable { static from(...inDisposables: { dispose(): any }[]): Disposable { @@ -49,6 +59,7 @@ export class Disposable { } } +@es5ClassCompat export class Position { static Min(...positions: Position[]): Position { @@ -229,6 +240,7 @@ export class Position { } } +@es5ClassCompat export class Range { static isRange(thing: any): thing is vscode.Range { @@ -374,6 +386,7 @@ export class Range { } } +@es5ClassCompat export class Selection extends Range { static isSelection(thing: any): thing is Selection { @@ -502,6 +515,7 @@ export enum EnvironmentVariableMutatorType { Prepend = 3 } +@es5ClassCompat export class TextEdit { static isTextEdit(thing: any): thing is TextEdit { @@ -584,6 +598,7 @@ export class TextEdit { } } +@es5ClassCompat export class NotebookEdit implements vscode.NotebookEdit { static isNotebookCellEdit(thing: any): thing is NotebookEdit { @@ -690,6 +705,7 @@ export interface ICellEdit { type WorkspaceEditEntry = IFileOperation | IFileTextEdit | IFileSnippetTextEdit | IFileCellEdit | ICellEdit; +@es5ClassCompat export class WorkspaceEdit implements vscode.WorkspaceEdit { private readonly _edits: WorkspaceEditEntry[] = []; @@ -840,6 +856,7 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit { } } +@es5ClassCompat export class SnippetString { static isSnippetString(thing: any): thing is SnippetString { @@ -946,6 +963,7 @@ export enum DiagnosticSeverity { Error = 0 } +@es5ClassCompat export class Location { static isLocation(thing: any): thing is vscode.Location { @@ -984,6 +1002,7 @@ export class Location { } } +@es5ClassCompat export class DiagnosticRelatedInformation { static is(thing: any): thing is DiagnosticRelatedInformation { @@ -1017,6 +1036,7 @@ export class DiagnosticRelatedInformation { } } +@es5ClassCompat export class Diagnostic { range: Range; @@ -1067,6 +1087,7 @@ export class Diagnostic { } } +@es5ClassCompat export class Hover { public contents: (vscode.MarkdownString | vscode.MarkedString)[]; @@ -1094,6 +1115,7 @@ export enum DocumentHighlightKind { Write = 2 } +@es5ClassCompat export class DocumentHighlight { range: Range; @@ -1145,6 +1167,7 @@ export enum SymbolTag { Deprecated = 1, } +@es5ClassCompat export class SymbolInformation { static validate(candidate: SymbolInformation): void { @@ -1189,6 +1212,7 @@ export class SymbolInformation { } } +@es5ClassCompat export class DocumentSymbol { static validate(candidate: DocumentSymbol): void { @@ -1227,6 +1251,7 @@ export enum CodeActionTriggerKind { Automatic = 2, } +@es5ClassCompat export class CodeAction { title: string; @@ -1247,6 +1272,7 @@ export class CodeAction { } +@es5ClassCompat export class CodeActionKind { private static readonly sep = '.'; @@ -1286,6 +1312,7 @@ CodeActionKind.Source = CodeActionKind.Empty.append('source'); CodeActionKind.SourceOrganizeImports = CodeActionKind.Source.append('organizeImports'); CodeActionKind.SourceFixAll = CodeActionKind.Source.append('fixAll'); +@es5ClassCompat export class SelectionRange { range: Range; @@ -1352,6 +1379,7 @@ export enum LanguageStatusSeverity { } +@es5ClassCompat export class CodeLens { range: Range; @@ -1368,6 +1396,7 @@ export class CodeLens { } } +@es5ClassCompat export class MarkdownString implements vscode.MarkdownString { readonly #delegate: BaseMarkdownString; @@ -1438,6 +1467,7 @@ export class MarkdownString implements vscode.MarkdownString { } } +@es5ClassCompat export class ParameterInformation { label: string | [number, number]; @@ -1449,6 +1479,7 @@ export class ParameterInformation { } } +@es5ClassCompat export class SignatureInformation { label: string; @@ -1463,6 +1494,7 @@ export class SignatureInformation { } } +@es5ClassCompat export class SignatureHelp { signatures: SignatureInformation[]; @@ -1486,6 +1518,7 @@ export enum InlayHintKind { Parameter = 2, } +@es5ClassCompat export class InlayHintLabelPart { value: string; @@ -1498,6 +1531,7 @@ export class InlayHintLabelPart { } } +@es5ClassCompat export class InlayHint implements vscode.InlayHint { label: string | InlayHintLabelPart[]; @@ -1566,6 +1600,7 @@ export interface CompletionItemLabel { description?: string; } +@es5ClassCompat export class CompletionItem implements vscode.CompletionItem { label: string | CompletionItemLabel; @@ -1604,6 +1639,7 @@ export class CompletionItem implements vscode.CompletionItem { } } +@es5ClassCompat export class CompletionList { isIncomplete?: boolean; @@ -1615,6 +1651,7 @@ export class CompletionList { } } +@es5ClassCompat export class InlineSuggestion implements vscode.InlineCompletionItem { filterText?: string; @@ -1629,6 +1666,7 @@ export class InlineSuggestion implements vscode.InlineCompletionItem { } } +@es5ClassCompat export class InlineSuggestionList implements vscode.InlineCompletionList { items: vscode.InlineCompletionItemNew[]; @@ -1639,6 +1677,7 @@ export class InlineSuggestionList implements vscode.InlineCompletionList { } } +@es5ClassCompat export class InlineSuggestionNew implements vscode.InlineCompletionItemNew { insertText: string; range?: Range; @@ -1651,6 +1690,7 @@ export class InlineSuggestionNew implements vscode.InlineCompletionItemNew { } } +@es5ClassCompat export class InlineSuggestionsNew implements vscode.InlineCompletionListNew { items: vscode.InlineCompletionItemNew[]; @@ -1744,6 +1784,7 @@ export namespace TextEditorSelectionChangeKind { } } +@es5ClassCompat export class DocumentLink { range: Range; @@ -1764,6 +1805,7 @@ export class DocumentLink { } } +@es5ClassCompat export class Color { readonly red: number; readonly green: number; @@ -1780,6 +1822,7 @@ export class Color { export type IColorFormat = string | { opaque: string; transparent: string }; +@es5ClassCompat export class ColorInformation { range: Range; @@ -1797,6 +1840,7 @@ export class ColorInformation { } } +@es5ClassCompat export class ColorPresentation { label: string; textEdit?: TextEdit; @@ -1879,6 +1923,7 @@ export enum TaskPanelKind { New = 3 } +@es5ClassCompat export class TaskGroup implements vscode.TaskGroup { isDefault: boolean | undefined; @@ -1930,6 +1975,7 @@ function computeTaskExecutionId(values: string[]): string { return id; } +@es5ClassCompat export class ProcessExecution implements vscode.ProcessExecution { private _process: string; @@ -2000,6 +2046,7 @@ export class ProcessExecution implements vscode.ProcessExecution { } } +@es5ClassCompat export class ShellExecution implements vscode.ShellExecution { private _commandLine: string | undefined; @@ -2114,6 +2161,7 @@ export class CustomExecution implements vscode.CustomExecution { } } +@es5ClassCompat export class Task implements vscode.Task { private static ExtensionCallbackType: string = 'customExecution'; @@ -2370,6 +2418,7 @@ export enum ProgressLocation { Notification = 15 } +@es5ClassCompat export class TreeItem { label?: string | vscode.TreeItemLabel; @@ -2446,6 +2495,7 @@ export enum TreeItemCollapsibleState { Expanded = 2 } +@es5ClassCompat export class DataTransferItem { async asString(): Promise { @@ -2459,6 +2509,7 @@ export class DataTransferItem { constructor(public readonly value: any) { } } +@es5ClassCompat export class DataTransfer implements vscode.DataTransfer { #items = new Map(); @@ -2500,6 +2551,7 @@ export class DataTransfer implements vscode.DataTransfer { } } +@es5ClassCompat export class DocumentDropEdit { insertText: string | SnippetString; @@ -2510,6 +2562,7 @@ export class DocumentDropEdit { } } +@es5ClassCompat export class DocumentPasteEdit { insertText: string | SnippetString; @@ -2520,6 +2573,7 @@ export class DocumentPasteEdit { } } +@es5ClassCompat export class ThemeIcon { static File: ThemeIcon; @@ -2537,6 +2591,7 @@ ThemeIcon.File = new ThemeIcon('file'); ThemeIcon.Folder = new ThemeIcon('folder'); +@es5ClassCompat export class ThemeColor { id: string; constructor(id: string) { @@ -2552,6 +2607,7 @@ export enum ConfigurationTarget { WorkspaceFolder = 3 } +@es5ClassCompat export class RelativePattern implements IRelativePattern { pattern: string; @@ -2605,6 +2661,7 @@ export class RelativePattern implements IRelativePattern { } } +@es5ClassCompat export class Breakpoint { private _id: string | undefined; @@ -2635,6 +2692,7 @@ export class Breakpoint { } } +@es5ClassCompat export class SourceBreakpoint extends Breakpoint { readonly location: Location; @@ -2647,6 +2705,7 @@ export class SourceBreakpoint extends Breakpoint { } } +@es5ClassCompat export class FunctionBreakpoint extends Breakpoint { readonly functionName: string; @@ -2656,6 +2715,7 @@ export class FunctionBreakpoint extends Breakpoint { } } +@es5ClassCompat export class DataBreakpoint extends Breakpoint { readonly label: string; readonly dataId: string; @@ -2673,6 +2733,7 @@ export class DataBreakpoint extends Breakpoint { } +@es5ClassCompat export class DebugAdapterExecutable implements vscode.DebugAdapterExecutable { readonly command: string; readonly args: string[]; @@ -2685,6 +2746,7 @@ export class DebugAdapterExecutable implements vscode.DebugAdapterExecutable { } } +@es5ClassCompat export class DebugAdapterServer implements vscode.DebugAdapterServer { readonly port: number; readonly host?: string; @@ -2695,11 +2757,13 @@ export class DebugAdapterServer implements vscode.DebugAdapterServer { } } +@es5ClassCompat export class DebugAdapterNamedPipeServer implements vscode.DebugAdapterNamedPipeServer { constructor(public readonly path: string) { } } +@es5ClassCompat export class DebugAdapterInlineImplementation implements vscode.DebugAdapterInlineImplementation { readonly implementation: vscode.DebugAdapter; @@ -2708,6 +2772,7 @@ export class DebugAdapterInlineImplementation implements vscode.DebugAdapterInli } } +@es5ClassCompat export class EvaluatableExpression implements vscode.EvaluatableExpression { readonly range: vscode.Range; readonly expression?: string; @@ -2728,6 +2793,7 @@ export enum InlineCompletionTriggerKindNew { Automatic = 1, } +@es5ClassCompat export class InlineValueText implements vscode.InlineValueText { readonly range: Range; readonly text: string; @@ -2738,6 +2804,7 @@ export class InlineValueText implements vscode.InlineValueText { } } +@es5ClassCompat export class InlineValueVariableLookup implements vscode.InlineValueVariableLookup { readonly range: Range; readonly variableName?: string; @@ -2750,6 +2817,7 @@ export class InlineValueVariableLookup implements vscode.InlineValueVariableLook } } +@es5ClassCompat export class InlineValueEvaluatableExpression implements vscode.InlineValueEvaluatableExpression { readonly range: Range; readonly expression?: string; @@ -2760,6 +2828,7 @@ export class InlineValueEvaluatableExpression implements vscode.InlineValueEvalu } } +@es5ClassCompat export class InlineValueContext implements vscode.InlineValueContext { readonly frameId: number; @@ -2779,6 +2848,7 @@ export enum FileChangeType { Deleted = 3, } +@es5ClassCompat export class FileSystemError extends Error { static FileExists(messageOrUri?: string | URI): FileSystemError { @@ -2828,6 +2898,7 @@ export class FileSystemError extends Error { //#region folding api +@es5ClassCompat export class FoldingRange { start: number; @@ -3117,6 +3188,7 @@ export enum DebugConsoleMode { //#endregion +@es5ClassCompat export class QuickInputButtons { static readonly Back: vscode.QuickInputButton = { iconPath: new ThemeIcon('arrow-left') }; @@ -3172,6 +3244,7 @@ export class FileDecoration { //#region Theming +@es5ClassCompat export class ColorTheme implements vscode.ColorTheme { constructor(public readonly kind: ColorThemeKind) { } @@ -3466,6 +3539,7 @@ export class NotebookRendererScript { //#region Timeline +@es5ClassCompat export class TimelineItem implements vscode.TimelineItem { constructor(public label: string, public timestamp: number) { } } @@ -3555,6 +3629,7 @@ export enum TestRunProfileKind { Coverage = 3, } +@es5ClassCompat export class TestRunRequest implements vscode.TestRunRequest { constructor( public readonly include: vscode.TestItem[] | undefined = undefined, @@ -3563,6 +3638,7 @@ export class TestRunRequest implements vscode.TestRunRequest { ) { } } +@es5ClassCompat export class TestMessage implements vscode.TestMessage { public expectedOutput?: string; public actualOutput?: string; @@ -3578,6 +3654,7 @@ export class TestMessage implements vscode.TestMessage { constructor(public message: string | vscode.MarkdownString) { } } +@es5ClassCompat export class TestTag implements vscode.TestTag { constructor(public readonly id: string) { } } @@ -3585,10 +3662,12 @@ export class TestTag implements vscode.TestTag { //#endregion //#region Test Coverage +@es5ClassCompat export class CoveredCount implements vscode.CoveredCount { constructor(public covered: number, public total: number) { } } +@es5ClassCompat export class FileCoverage implements vscode.FileCoverage { public static fromDetails(uri: vscode.Uri, details: vscode.DetailedCoverage[]): vscode.FileCoverage { const statements = new CoveredCount(0, 0); @@ -3632,6 +3711,7 @@ export class FileCoverage implements vscode.FileCoverage { ) { } } +@es5ClassCompat export class StatementCoverage implements vscode.StatementCoverage { constructor( public executionCount: number, @@ -3640,6 +3720,7 @@ export class StatementCoverage implements vscode.StatementCoverage { ) { } } +@es5ClassCompat export class BranchCoverage implements vscode.BranchCoverage { constructor( public executionCount: number, @@ -3647,6 +3728,7 @@ export class BranchCoverage implements vscode.BranchCoverage { ) { } } +@es5ClassCompat export class FunctionCoverage implements vscode.FunctionCoverage { constructor( public executionCount: number, From 8754d3cca261e79818492de1b9f8e50384d7d2ca Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 15 Jul 2022 12:23:03 +0200 Subject: [PATCH 078/121] fix assumptions about action-bar title structure (#155292) --- test/automation/src/extensions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/automation/src/extensions.ts b/test/automation/src/extensions.ts index b98b03eb4b1a4..7168258d308e7 100644 --- a/test/automation/src/extensions.ts +++ b/test/automation/src/extensions.ts @@ -61,7 +61,7 @@ export class Extensions extends Viewlet { await this.code.waitAndClick(`div.extensions-viewlet[id="workbench.view.extensions"] .monaco-list-row[data-extension-id="${id}"] .extension-list-item .monaco-action-bar .action-item:not(.disabled) .extension-action.install`); await this.code.waitForElement(`.extension-editor .monaco-action-bar .action-item:not(.disabled) .extension-action.uninstall`); if (waitUntilEnabled) { - await this.code.waitForElement(`.extension-editor .monaco-action-bar .action-item:not(.disabled) .extension-action[title="Disable this extension"]`); + await this.code.waitForElement(`.extension-editor .monaco-action-bar .action-item:not(.disabled)[title="Disable this extension"]`); } } } From cc7d90741013437eb12470df7ca43997935a5421 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 15 Jul 2022 12:40:45 +0200 Subject: [PATCH 079/121] deprecate es5ClassCompat and explain why --- src/vs/workbench/api/common/extHostTypes.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index 74d65b863365d..2f5af73ddf2ca 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -19,6 +19,12 @@ import { IRelativePatternDto } from 'vs/workbench/api/common/extHost.protocol'; import { CellEditType, ICellPartialMetadataEdit, IDocumentMetadataEdit } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import type * as vscode from 'vscode'; +/** + * @deprecated + * + * This utility ensures that old JS code that uses functions for classes still works. Existing usages cannot be removed + * but new ones must not be added + * */ function es5ClassCompat(target: Function): any { ///@ts-expect-error function _() { return Reflect.construct(target, arguments, this.constructor); } From f23404fd71f213fe83ccdaf1a215654ef7c6e18a Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 15 Jul 2022 13:11:09 +0200 Subject: [PATCH 080/121] track usage of snippets to support snippet LRU (#155289) enforce that all snippets have an identifier, mark a snippet as used after completing with it or after inserting one, store the last 100 snippet usages per (user, profile) --- .../contrib/snippets/browser/insertSnippet.ts | 2 + .../browser/snippetCompletionProvider.ts | 18 ++- .../contrib/snippets/browser/snippetPicker.ts | 2 +- .../snippets/browser/snippets.contribution.ts | 3 + .../contrib/snippets/browser/snippetsFile.ts | 24 +--- .../snippets/browser/snippetsService.ts | 87 +++++++++++++-- .../snippets/browser/surroundWithSnippet.ts | 1 + .../snippets/test/browser/snippetFile.test.ts | 21 ++-- .../test/browser/snippetsRewrite.test.ts | 5 +- .../test/browser/snippetsService.test.ts | 103 +++++++++++------- 10 files changed, 183 insertions(+), 83 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts b/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts index 3a0088a1f4867..2d84a9a71a5da 100644 --- a/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts @@ -102,6 +102,7 @@ class InsertSnippetAction extends EditorAction { snippet, '', SnippetSource.User, + `random/${Math.random()}` )); } @@ -143,6 +144,7 @@ class InsertSnippetAction extends EditorAction { clipboardText = await clipboardService.readText(); } SnippetController2.get(editor)?.insert(snippet.codeSnippet, { clipboardText }); + snippetService.updateUsageTimestamp(snippet); } } diff --git a/src/vs/workbench/contrib/snippets/browser/snippetCompletionProvider.ts b/src/vs/workbench/contrib/snippets/browser/snippetCompletionProvider.ts index 3e8ea30e666af..7e8c6555e5c72 100644 --- a/src/vs/workbench/contrib/snippets/browser/snippetCompletionProvider.ts +++ b/src/vs/workbench/contrib/snippets/browser/snippetCompletionProvider.ts @@ -8,7 +8,7 @@ import { compare, compareSubstring } from 'vs/base/common/strings'; import { Position } from 'vs/editor/common/core/position'; import { IRange, Range } from 'vs/editor/common/core/range'; import { ITextModel } from 'vs/editor/common/model'; -import { CompletionItem, CompletionItemKind, CompletionItemProvider, CompletionList, CompletionItemInsertTextRule, CompletionContext, CompletionTriggerKind, CompletionItemLabel } from 'vs/editor/common/languages'; +import { CompletionItem, CompletionItemKind, CompletionItemProvider, CompletionList, CompletionItemInsertTextRule, CompletionContext, CompletionTriggerKind, CompletionItemLabel, Command } from 'vs/editor/common/languages'; import { ILanguageService } from 'vs/editor/common/languages/language'; import { SnippetParser } from 'vs/editor/contrib/snippet/browser/snippetParser'; import { localize } from 'vs/nls'; @@ -19,6 +19,18 @@ import { StopWatch } from 'vs/base/common/stopwatch'; import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry'; import { getWordAtText } from 'vs/editor/common/core/wordHelper'; import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions'; +import { CommandsRegistry } from 'vs/platform/commands/common/commands'; + + +const markSnippetAsUsed = '_snippet.markAsUsed'; + +CommandsRegistry.registerCommand(markSnippetAsUsed, (accessor, ...args) => { + const snippetsService = accessor.get(ISnippetsService); + const [first] = args; + if (first instanceof Snippet) { + snippetsService.updateUsageTimestamp(first); + } +}); export class SnippetCompletion implements CompletionItem { @@ -31,10 +43,11 @@ export class SnippetCompletion implements CompletionItem { kind: CompletionItemKind; insertTextRules: CompletionItemInsertTextRule; extensionId?: ExtensionIdentifier; + command?: Command; constructor( readonly snippet: Snippet, - range: IRange | { insert: IRange; replace: IRange } + range: IRange | { insert: IRange; replace: IRange }, ) { this.label = { label: snippet.prefix, description: snippet.name }; this.detail = localize('detail.snippet', "{0} ({1})", snippet.description || snippet.name, snippet.source); @@ -44,6 +57,7 @@ export class SnippetCompletion implements CompletionItem { this.sortText = `${snippet.snippetSource === SnippetSource.Extension ? 'z' : 'a'}-${snippet.prefix}`; this.kind = CompletionItemKind.Snippet; this.insertTextRules = CompletionItemInsertTextRule.InsertAsSnippet; + this.command = { id: markSnippetAsUsed, title: '', arguments: [snippet] }; } resolve(): this { diff --git a/src/vs/workbench/contrib/snippets/browser/snippetPicker.ts b/src/vs/workbench/contrib/snippets/browser/snippetPicker.ts index 9cb08b37047c2..0814ea32312c0 100644 --- a/src/vs/workbench/contrib/snippets/browser/snippetPicker.ts +++ b/src/vs/workbench/contrib/snippets/browser/snippetPicker.ts @@ -27,7 +27,7 @@ export async function pickSnippet(accessor: ServicesAccessor, languageIdOrSnippe snippets = (await snippetService.getSnippets(languageIdOrSnippets, { includeDisabledSnippets: true, includeNoPrefixSnippets: true })); } - snippets.sort(Snippet.compare); + snippets.sort((a, b) => a.snippetSource - b.snippetSource); const makeSnippetPicks = () => { const result: QuickPickInput[] = []; diff --git a/src/vs/workbench/contrib/snippets/browser/snippets.contribution.ts b/src/vs/workbench/contrib/snippets/browser/snippets.contribution.ts index 1e1bdd82c69c0..02b6c4b4238df 100644 --- a/src/vs/workbench/contrib/snippets/browser/snippets.contribution.ts +++ b/src/vs/workbench/contrib/snippets/browser/snippets.contribution.ts @@ -15,6 +15,7 @@ export const ISnippetsService = createDecorator('snippetServic export interface ISnippetGetOptions { includeDisabledSnippets?: boolean; includeNoPrefixSnippets?: boolean; + noRecencySort?: boolean; } export interface ISnippetsService { @@ -27,6 +28,8 @@ export interface ISnippetsService { updateEnablement(snippet: Snippet, enabled: boolean): void; + updateUsageTimestamp(snippet: Snippet): void; + getSnippets(languageId: string, opt?: ISnippetGetOptions): Promise; getSnippetsSync(languageId: string, opt?: ISnippetGetOptions): Snippet[]; diff --git a/src/vs/workbench/contrib/snippets/browser/snippetsFile.ts b/src/vs/workbench/contrib/snippets/browser/snippetsFile.ts index 784296b70de01..72a3e74f64cfb 100644 --- a/src/vs/workbench/contrib/snippets/browser/snippetsFile.ts +++ b/src/vs/workbench/contrib/snippets/browser/snippetsFile.ts @@ -113,7 +113,7 @@ export class Snippet { readonly body: string, readonly source: string, readonly snippetSource: SnippetSource, - readonly snippetIdentifier?: string, + readonly snippetIdentifier: string, readonly extensionId?: ExtensionIdentifier, ) { this.prefixLow = prefix.toLowerCase(); @@ -139,24 +139,6 @@ export class Snippet { get usesSelection(): boolean { return this._bodyInsights.value.usesSelectionVariable; } - - static compare(a: Snippet, b: Snippet): number { - if (a.snippetSource < b.snippetSource) { - return -1; - } else if (a.snippetSource > b.snippetSource) { - return 1; - } else if (a.source < b.source) { - return -1; - } else if (a.source > b.source) { - return 1; - } else if (a.name > b.name) { - return 1; - } else if (a.name < b.name) { - return -1; - } else { - return 0; - } - } } @@ -195,7 +177,7 @@ export class SnippetFile { public defaultScopes: string[] | undefined, private readonly _extension: IExtensionDescription | undefined, private readonly _fileService: IFileService, - private readonly _extensionResourceLoaderService: IExtensionResourceLoaderService + private readonly _extensionResourceLoaderService: IExtensionResourceLoaderService, ) { this.isGlobalSnippets = extname(location.path) === '.code-snippets'; this.isUserSnippets = !this._extension; @@ -330,7 +312,7 @@ export class SnippetFile { body, source, this.source, - this._extension && `${relativePath(this._extension.extensionLocation, this.location)}/${name}`, + this._extension ? `${relativePath(this._extension.extensionLocation, this.location)}/${name}` : `${basename(this.location.path)}/${name}`, this._extension?.identifier, )); } diff --git a/src/vs/workbench/contrib/snippets/browser/snippetsService.ts b/src/vs/workbench/contrib/snippets/browser/snippetsService.ts index abc007e863d4e..da0e5e26960b2 100644 --- a/src/vs/workbench/contrib/snippets/browser/snippetsService.ts +++ b/src/vs/workbench/contrib/snippets/browser/snippetsService.ts @@ -167,6 +167,42 @@ class SnippetEnablement { } } +class SnippetUsageTimestamps { + + private static _key = 'snippets.usageTimestamps'; + + private readonly _usages: Map; + + constructor( + @IStorageService private readonly _storageService: IStorageService, + ) { + + const raw = _storageService.get(SnippetUsageTimestamps._key, StorageScope.PROFILE, ''); + let data: [string, number][] | undefined; + try { + data = JSON.parse(raw); + } catch { + data = []; + } + + this._usages = Array.isArray(data) ? new Map(data) : new Map(); + } + + getUsageTimestamp(id: string): number | undefined { + return this._usages.get(id); + } + + updateUsageTimestamp(id: string): void { + // map uses insertion order, we want most recent at the end + this._usages.delete(id); + this._usages.set(id, Date.now()); + + // persist last 100 item + const all = [...this._usages].slice(-100); + this._storageService.store(SnippetUsageTimestamps._key, JSON.stringify(all), StorageScope.PROFILE, StorageTarget.USER); + } +} + class SnippetsService implements ISnippetsService { declare readonly _serviceBrand: undefined; @@ -175,6 +211,7 @@ class SnippetsService implements ISnippetsService { private readonly _pendingWork: Promise[] = []; private readonly _files = new ResourceMap(); private readonly _enablement: SnippetEnablement; + private readonly _usageTimestamps: SnippetUsageTimestamps; constructor( @IEnvironmentService private readonly _environmentService: IEnvironmentService, @@ -198,6 +235,7 @@ class SnippetsService implements ISnippetsService { setSnippetSuggestSupport(new SnippetCompletionProvider(this._languageService, this, languageConfigurationService)); this._enablement = instantiationService.createInstance(SnippetEnablement); + this._usageTimestamps = instantiationService.createInstance(SnippetUsageTimestamps); } dispose(): void { @@ -205,13 +243,15 @@ class SnippetsService implements ISnippetsService { } isEnabled(snippet: Snippet): boolean { - return !snippet.snippetIdentifier || !this._enablement.isIgnored(snippet.snippetIdentifier); + return !this._enablement.isIgnored(snippet.snippetIdentifier); } updateEnablement(snippet: Snippet, enabled: boolean): void { - if (snippet.snippetIdentifier) { - this._enablement.updateIgnored(snippet.snippetIdentifier, !enabled); - } + this._enablement.updateIgnored(snippet.snippetIdentifier, !enabled); + } + + updateUsageTimestamp(snippet: Snippet): void { + this._usageTimestamps.updateUsageTimestamp(snippet.snippetIdentifier); } private _joinSnippets(): Promise { @@ -240,7 +280,7 @@ class SnippetsService implements ISnippetsService { } } await Promise.all(promises); - return this._filterSnippets(result, opts); + return this._filterAndSortSnippets(result, opts); } getSnippetsSync(languageId: string, opts?: ISnippetGetOptions): Snippet[] { @@ -253,14 +293,45 @@ class SnippetsService implements ISnippetsService { file.select(languageId, result); } } - return this._filterSnippets(result, opts); + return this._filterAndSortSnippets(result, opts); } - private _filterSnippets(snippets: Snippet[], opts?: ISnippetGetOptions): Snippet[] { - return snippets.filter(snippet => { + private _filterAndSortSnippets(snippets: Snippet[], opts?: ISnippetGetOptions): Snippet[] { + const result = snippets.filter(snippet => { return (snippet.prefix || opts?.includeNoPrefixSnippets) // prefix or no-prefix wanted && (this.isEnabled(snippet) || opts?.includeDisabledSnippets); // enabled or disabled wanted }); + + return result.sort((a, b) => { + let result = 0; + if (!opts?.noRecencySort) { + const val1 = this._usageTimestamps.getUsageTimestamp(a.snippetIdentifier) ?? -1; + const val2 = this._usageTimestamps.getUsageTimestamp(b.snippetIdentifier) ?? -1; + result = val2 - val1; + } + if (result === 0) { + result = this._compareSnippet(a, b); + } + return result; + }); + } + + private _compareSnippet(a: Snippet, b: Snippet): number { + if (a.snippetSource < b.snippetSource) { + return -1; + } else if (a.snippetSource > b.snippetSource) { + return 1; + } else if (a.source < b.source) { + return -1; + } else if (a.source > b.source) { + return 1; + } else if (a.name > b.name) { + return 1; + } else if (a.name < b.name) { + return -1; + } else { + return 0; + } } // --- loading, watching diff --git a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts index 2d7a798594dea..02805db79eb33 100644 --- a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts @@ -83,6 +83,7 @@ class SurroundWithSnippetEditorAction extends EditorAction2 { } SnippetController2.get(editor)?.insert(snippet.codeSnippet, { clipboardText }); + snippetService.updateUsageTimestamp(snippet); } } diff --git a/src/vs/workbench/contrib/snippets/test/browser/snippetFile.test.ts b/src/vs/workbench/contrib/snippets/test/browser/snippetFile.test.ts index dffa5ea30ef91..b2f87092ad1ba 100644 --- a/src/vs/workbench/contrib/snippets/test/browser/snippetFile.test.ts +++ b/src/vs/workbench/contrib/snippets/test/browser/snippetFile.test.ts @@ -7,6 +7,7 @@ import * as assert from 'assert'; import { SnippetFile, Snippet, SnippetSource } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; import { URI } from 'vs/base/common/uri'; import { SnippetParser } from 'vs/editor/contrib/snippet/browser/snippetParser'; +import { generateUuid } from 'vs/base/common/uuid'; suite('Snippets', function () { @@ -24,12 +25,12 @@ suite('Snippets', function () { assert.strictEqual(bucket.length, 0); file = new TestSnippetFile(URI.file('somepath/foo.code-snippets'), [ - new Snippet(['foo'], 'FooSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User), - new Snippet(['foo'], 'FooSnippet2', 'foo', '', 'snippet', 'test', SnippetSource.User), - new Snippet(['bar'], 'BarSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User), - new Snippet(['bar.comment'], 'BarSnippet2', 'foo', '', 'snippet', 'test', SnippetSource.User), - new Snippet(['bar.strings'], 'BarSnippet2', 'foo', '', 'snippet', 'test', SnippetSource.User), - new Snippet(['bazz', 'bazz'], 'BazzSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User), + new Snippet(['foo'], 'FooSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(['foo'], 'FooSnippet2', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(['bar'], 'BarSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(['bar.comment'], 'BarSnippet2', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(['bar.strings'], 'BarSnippet2', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(['bazz', 'bazz'], 'BazzSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), ]); bucket = []; @@ -56,8 +57,8 @@ suite('Snippets', function () { test('SnippetFile#select - any scope', function () { const file = new TestSnippetFile(URI.file('somepath/foo.code-snippets'), [ - new Snippet([], 'AnySnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User), - new Snippet(['foo'], 'FooSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User), + new Snippet([], 'AnySnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(['foo'], 'FooSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), ]); const bucket: Snippet[] = []; @@ -69,7 +70,7 @@ suite('Snippets', function () { test('Snippet#needsClipboard', function () { function assertNeedsClipboard(body: string, expected: boolean): void { - const snippet = new Snippet(['foo'], 'FooSnippet1', 'foo', '', body, 'test', SnippetSource.User); + const snippet = new Snippet(['foo'], 'FooSnippet1', 'foo', '', body, 'test', SnippetSource.User, generateUuid()); assert.strictEqual(snippet.needsClipboard, expected); assert.strictEqual(SnippetParser.guessNeedsClipboard(body), expected); @@ -86,7 +87,7 @@ suite('Snippets', function () { test('Snippet#isTrivial', function () { function assertIsTrivial(body: string, expected: boolean): void { - const snippet = new Snippet(['foo'], 'FooSnippet1', 'foo', '', body, 'test', SnippetSource.User); + const snippet = new Snippet(['foo'], 'FooSnippet1', 'foo', '', body, 'test', SnippetSource.User, generateUuid()); assert.strictEqual(snippet.isTrivial, expected); } diff --git a/src/vs/workbench/contrib/snippets/test/browser/snippetsRewrite.test.ts b/src/vs/workbench/contrib/snippets/test/browser/snippetsRewrite.test.ts index 50c826d58683d..ac5a579fcfdc2 100644 --- a/src/vs/workbench/contrib/snippets/test/browser/snippetsRewrite.test.ts +++ b/src/vs/workbench/contrib/snippets/test/browser/snippetsRewrite.test.ts @@ -4,12 +4,13 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; +import { generateUuid } from 'vs/base/common/uuid'; import { Snippet, SnippetSource } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; suite('SnippetRewrite', function () { function assertRewrite(input: string, expected: string | boolean): void { - const actual = new Snippet(['foo'], 'foo', 'foo', 'foo', input, 'foo', SnippetSource.User); + const actual = new Snippet(['foo'], 'foo', 'foo', 'foo', input, 'foo', SnippetSource.User, generateUuid()); if (typeof expected === 'boolean') { assert.strictEqual(actual.codeSnippet, input); } else { @@ -47,7 +48,7 @@ suite('SnippetRewrite', function () { }); test('lazy bogous variable rewrite', function () { - const snippet = new Snippet(['fooLang'], 'foo', 'prefix', 'desc', 'This is ${bogous} because it is a ${var}', 'source', SnippetSource.Extension); + const snippet = new Snippet(['fooLang'], 'foo', 'prefix', 'desc', 'This is ${bogous} because it is a ${var}', 'source', SnippetSource.Extension, generateUuid()); assert.strictEqual(snippet.body, 'This is ${bogous} because it is a ${var}'); assert.strictEqual(snippet.codeSnippet, 'This is ${1:bogous} because it is a ${2:var}'); assert.strictEqual(snippet.isBogous, true); diff --git a/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts b/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts index 6c442beb9f209..81156296016f3 100644 --- a/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts +++ b/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts @@ -15,6 +15,7 @@ import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/te import { EditOperation } from 'vs/editor/common/core/editOperation'; import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock'; import { ILanguageService } from 'vs/editor/common/languages/language'; +import { generateUuid } from 'vs/base/common/uuid'; class SimpleSnippetService implements ISnippetsService { declare readonly _serviceBrand: undefined; @@ -34,6 +35,9 @@ class SimpleSnippetService implements ISnippetsService { updateEnablement(): void { throw new Error(); } + updateUsageTimestamp(snippet: Snippet): void { + throw new Error(); + } } suite('SnippetsService', function () { @@ -59,7 +63,8 @@ suite('SnippetsService', function () { '', 'barCodeSnippet', '', - SnippetSource.User + SnippetSource.User, + generateUuid() ), new Snippet( ['fooLang'], 'bazzTest', @@ -67,7 +72,8 @@ suite('SnippetsService', function () { '', 'bazzCodeSnippet', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); }); @@ -128,7 +134,8 @@ suite('SnippetsService', function () { '', 's1', '', - SnippetSource.User + SnippetSource.User, + generateUuid() ), new Snippet( ['fooLang'], 'name', @@ -136,7 +143,8 @@ suite('SnippetsService', function () { '', 's2', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -206,7 +214,8 @@ suite('SnippetsService', function () { '', 'insert me', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -241,7 +250,8 @@ suite('SnippetsService', function () { '', '$0', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -263,7 +273,8 @@ suite('SnippetsService', function () { '', 'second', '', - SnippetSource.Extension + SnippetSource.Extension, + generateUuid() ), new Snippet( ['fooLang'], 'first', @@ -271,7 +282,8 @@ suite('SnippetsService', function () { '', 'first', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -299,7 +311,8 @@ suite('SnippetsService', function () { '', 'second', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -323,7 +336,8 @@ suite('SnippetsService', function () { '', 'second', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -342,7 +356,8 @@ suite('SnippetsService', function () { '', 'second', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -361,7 +376,8 @@ suite('SnippetsService', function () { '', 'second', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -384,7 +400,8 @@ suite('SnippetsService', function () { '', 'second', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -408,7 +425,8 @@ suite('SnippetsService', function () { '', 'second', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, languageConfigurationService); @@ -427,7 +445,8 @@ suite('SnippetsService', function () { '', 'second', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -446,7 +465,8 @@ suite('SnippetsService', function () { '', '<= #dly"', '', - SnippetSource.User + SnippetSource.User, + generateUuid() ), new Snippet( ['fooLang'], 'noblockwdelay', @@ -454,7 +474,8 @@ suite('SnippetsService', function () { '', 'eleven', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -484,7 +505,8 @@ suite('SnippetsService', function () { '', 'not word snippet', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -526,7 +548,8 @@ suite('SnippetsService', function () { '', '', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -558,7 +581,8 @@ suite('SnippetsService', function () { '', '[PSCustomObject] @{ Key = Value }', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, languageConfigurationService); @@ -583,7 +607,8 @@ suite('SnippetsService', function () { '', '~\\cite{$CLIPBOARD}', '', - SnippetSource.User + SnippetSource.User, + generateUuid() )]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -602,9 +627,9 @@ suite('SnippetsService', function () { test('still show suggestions in string when disable string suggestion #136611', async function () { snippetService = new SimpleSnippetService([ - new Snippet(['fooLang'], 'aaa', 'aaa', '', 'value', '', SnippetSource.User), - new Snippet(['fooLang'], 'bbb', 'bbb', '', 'value', '', SnippetSource.User), - // new Snippet(['fooLang'], '\'ccc', '\'ccc', '', 'value', '', SnippetSource.User) + new Snippet(['fooLang'], 'aaa', 'aaa', '', 'value', '', SnippetSource.User, generateUuid()), + new Snippet(['fooLang'], 'bbb', 'bbb', '', 'value', '', SnippetSource.User, generateUuid()), + // new Snippet(['fooLang'], '\'ccc', '\'ccc', '', 'value', '', SnippetSource.User, generateUuid()) ]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -624,9 +649,9 @@ suite('SnippetsService', function () { test('still show suggestions in string when disable string suggestion #136611', async function () { snippetService = new SimpleSnippetService([ - new Snippet(['fooLang'], 'aaa', 'aaa', '', 'value', '', SnippetSource.User), - new Snippet(['fooLang'], 'bbb', 'bbb', '', 'value', '', SnippetSource.User), - new Snippet(['fooLang'], '\'ccc', '\'ccc', '', 'value', '', SnippetSource.User) + new Snippet(['fooLang'], 'aaa', 'aaa', '', 'value', '', SnippetSource.User, generateUuid()), + new Snippet(['fooLang'], 'bbb', 'bbb', '', 'value', '', SnippetSource.User, generateUuid()), + new Snippet(['fooLang'], '\'ccc', '\'ccc', '', 'value', '', SnippetSource.User, generateUuid()) ]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -645,9 +670,9 @@ suite('SnippetsService', function () { test('Snippet suggestions are too eager #138707 (word)', async function () { snippetService = new SimpleSnippetService([ - new Snippet(['fooLang'], 'tys', 'tys', '', 'value', '', SnippetSource.User), - new Snippet(['fooLang'], 'hell_or_tell', 'hell_or_tell', '', 'value', '', SnippetSource.User), - new Snippet(['fooLang'], '^y', '^y', '', 'value', '', SnippetSource.User), + new Snippet(['fooLang'], 'tys', 'tys', '', 'value', '', SnippetSource.User, generateUuid()), + new Snippet(['fooLang'], 'hell_or_tell', 'hell_or_tell', '', 'value', '', SnippetSource.User, generateUuid()), + new Snippet(['fooLang'], '^y', '^y', '', 'value', '', SnippetSource.User, generateUuid()), ]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -666,9 +691,9 @@ suite('SnippetsService', function () { test('Snippet suggestions are too eager #138707 (no word)', async function () { snippetService = new SimpleSnippetService([ - new Snippet(['fooLang'], 'tys', 'tys', '', 'value', '', SnippetSource.User), - new Snippet(['fooLang'], 't', 't', '', 'value', '', SnippetSource.User), - new Snippet(['fooLang'], '^y', '^y', '', 'value', '', SnippetSource.User), + new Snippet(['fooLang'], 'tys', 'tys', '', 'value', '', SnippetSource.User, generateUuid()), + new Snippet(['fooLang'], 't', 't', '', 'value', '', SnippetSource.User, generateUuid()), + new Snippet(['fooLang'], '^y', '^y', '', 'value', '', SnippetSource.User, generateUuid()), ]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -687,8 +712,8 @@ suite('SnippetsService', function () { test('Snippet suggestions are too eager #138707 (word/word)', async function () { snippetService = new SimpleSnippetService([ - new Snippet(['fooLang'], 'async arrow function', 'async arrow function', '', 'value', '', SnippetSource.User), - new Snippet(['fooLang'], 'foobarrrrrr', 'foobarrrrrr', '', 'value', '', SnippetSource.User), + new Snippet(['fooLang'], 'async arrow function', 'async arrow function', '', 'value', '', SnippetSource.User, generateUuid()), + new Snippet(['fooLang'], 'foobarrrrrr', 'foobarrrrrr', '', 'value', '', SnippetSource.User, generateUuid()), ]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); @@ -707,7 +732,7 @@ suite('SnippetsService', function () { test('Strange and useless autosuggestion #region/#endregion PHP #140039', async function () { snippetService = new SimpleSnippetService([ - new Snippet(['fooLang'], 'reg', '#region', '', 'value', '', SnippetSource.User), + new Snippet(['fooLang'], 'reg', '#region', '', 'value', '', SnippetSource.User, generateUuid()), ]); @@ -725,9 +750,9 @@ suite('SnippetsService', function () { test.skip('Snippets disappear with . key #145960', async function () { snippetService = new SimpleSnippetService([ - new Snippet(['fooLang'], 'div', 'div', '', 'div', '', SnippetSource.User), - new Snippet(['fooLang'], 'div.', 'div.', '', 'div.', '', SnippetSource.User), - new Snippet(['fooLang'], 'div#', 'div#', '', 'div#', '', SnippetSource.User), + new Snippet(['fooLang'], 'div', 'div', '', 'div', '', SnippetSource.User, generateUuid()), + new Snippet(['fooLang'], 'div.', 'div.', '', 'div.', '', SnippetSource.User, generateUuid()), + new Snippet(['fooLang'], 'div#', 'div#', '', 'div#', '', SnippetSource.User, generateUuid()), ]); const provider = new SnippetCompletionProvider(languageService, snippetService, new TestLanguageConfigurationService()); From d41dd4d0247814bce35b98c6f7fc9c24c642f348 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 15 Jul 2022 13:13:06 +0200 Subject: [PATCH 081/121] send `workbenchActionExecuted` from CC to measure its success (#155297) fixes https://github.com/microsoft/vscode-internalbacklog/issues/3005 --- .../browser/parts/titlebar/commandCenterControl.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/browser/parts/titlebar/commandCenterControl.ts b/src/vs/workbench/browser/parts/titlebar/commandCenterControl.ts index 8ccb1dcc33a67..25e9213343e57 100644 --- a/src/vs/workbench/browser/parts/titlebar/commandCenterControl.ts +++ b/src/vs/workbench/browser/parts/titlebar/commandCenterControl.ts @@ -7,7 +7,7 @@ import { reset } from 'vs/base/browser/dom'; import { IHoverDelegate } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate'; import { renderIcon } from 'vs/base/browser/ui/iconLabel/iconLabels'; import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar'; -import { IAction } from 'vs/base/common/actions'; +import { IAction, WorkbenchActionExecutedClassification, WorkbenchActionExecutedEvent } from 'vs/base/common/actions'; import { Codicon } from 'vs/base/common/codicons'; import { Emitter, Event } from 'vs/base/common/event'; import { DisposableStore } from 'vs/base/common/lifecycle'; @@ -20,6 +20,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; +import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import * as colors from 'vs/platform/theme/common/colorRegistry'; import { WindowTitle } from 'vs/workbench/browser/parts/titlebar/windowTitle'; import { MENUBAR_SELECTION_BACKGROUND, MENUBAR_SELECTION_FOREGROUND, PANEL_BORDER, TITLE_BAR_ACTIVE_FOREGROUND } from 'vs/workbench/common/theme'; @@ -42,6 +43,7 @@ export class CommandCenterControl { @IMenuService menuService: IMenuService, @IQuickInputService quickInputService: IQuickInputService, @IKeybindingService keybindingService: IKeybindingService, + @ITelemetryService telemetryService: ITelemetryService, ) { this.element.classList.add('command-center'); @@ -129,6 +131,10 @@ export class CommandCenterControl { })); this._disposables.add(quickInputService.onShow(this._setVisibility.bind(this, false))); this._disposables.add(quickInputService.onHide(this._setVisibility.bind(this, true))); + + titleToolbar.actionRunner.onDidRun(e => { + telemetryService.publicLog2('workbenchActionExecuted', { id: e.action.id, from: 'commandCenter' }); + }); } private _setVisibility(show: boolean): void { From 245813cfbc5b27c21ab95aa19776ce551289813a Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 15 Jul 2022 14:12:56 +0200 Subject: [PATCH 082/121] tests - speed up unit tests (#149712) (#155147) * tests - convert history tracker to in-memory (#149712) * fix warnings from missing service * sqlite slowness * disable flush on write in tests unless disk tests * more runWithFakedTimers * disable flush also in pfs * fix compile --- src/vs/base/node/pfs.ts | 7 +- .../parts/storage/test/node/storage.test.ts | 69 ++++----- src/vs/base/test/node/pfs/pfs.test.ts | 13 +- .../common/inMemoryFilesystemProvider.ts | 4 + .../files/node/diskFileSystemProvider.ts | 11 +- .../files/test/node/diskFileService.test.ts | 14 +- .../test/browser/mainThreadEditors.test.ts | 4 +- .../snippets/browser/surroundWithSnippet.ts | 2 +- .../common/workingCopyHistoryTracker.ts | 3 +- .../test/browser/resourceWorkingCopy.test.ts | 25 ++-- .../browser/storedFileWorkingCopy.test.ts | 139 ++++++++++-------- .../workingCopyHistoryService.test.ts | 8 +- .../workingCopyHistoryTracker.test.ts | 68 +++++---- 13 files changed, 208 insertions(+), 159 deletions(-) diff --git a/src/vs/base/node/pfs.ts b/src/vs/base/node/pfs.ts index 2283c4a61d6c9..9b652eb627f84 100644 --- a/src/vs/base/node/pfs.ts +++ b/src/vs/base/node/pfs.ts @@ -390,6 +390,9 @@ interface IEnsuredWriteFileOptions extends IWriteFileOptions { } let canFlush = true; +export function configureFlushOnWrite(enabled: boolean): void { + canFlush = enabled; +} // Calls fs.writeFile() followed by a fs.sync() call to flush the changes to disk // We do this in cases where we want to make sure the data is really on disk and @@ -421,7 +424,7 @@ function doWriteFileAndFlush(path: string, data: string | Buffer | Uint8Array, o // In that case we disable flushing and warn to the console if (syncError) { console.warn('[node.js fs] fdatasync is now disabled for this session because it failed: ', syncError); - canFlush = false; + configureFlushOnWrite(false); } return fs.close(fd, closeError => callback(closeError)); @@ -455,7 +458,7 @@ export function writeFileSync(path: string, data: string | Buffer, options?: IWr fs.fdatasyncSync(fd); // https://github.com/microsoft/vscode/issues/9589 } catch (syncError) { console.warn('[node.js fs] fdatasyncSync is now disabled for this session because it failed: ', syncError); - canFlush = false; + configureFlushOnWrite(false); } } finally { fs.closeSync(fd); diff --git a/src/vs/base/parts/storage/test/node/storage.test.ts b/src/vs/base/parts/storage/test/node/storage.test.ts index f53fdb2c3877d..70ff91977be9e 100644 --- a/src/vs/base/parts/storage/test/node/storage.test.ts +++ b/src/vs/base/parts/storage/test/node/storage.test.ts @@ -670,56 +670,57 @@ flakySuite('SQLite Storage Library', function () { }); test('multiple concurrent writes execute in sequence', async () => { - - class TestStorage extends Storage { - getStorage(): IStorageDatabase { - return this.database; + return runWithFakedTimers({}, async () => { + class TestStorage extends Storage { + getStorage(): IStorageDatabase { + return this.database; + } } - } - const storage = new TestStorage(new SQLiteStorageDatabase(join(testdir, 'storage.db'))); + const storage = new TestStorage(new SQLiteStorageDatabase(join(testdir, 'storage.db'))); - await storage.init(); + await storage.init(); - storage.set('foo', 'bar'); - storage.set('some/foo/path', 'some/bar/path'); + storage.set('foo', 'bar'); + storage.set('some/foo/path', 'some/bar/path'); - await timeout(2); + await timeout(2); - storage.set('foo1', 'bar'); - storage.set('some/foo1/path', 'some/bar/path'); + storage.set('foo1', 'bar'); + storage.set('some/foo1/path', 'some/bar/path'); - await timeout(2); + await timeout(2); - storage.set('foo2', 'bar'); - storage.set('some/foo2/path', 'some/bar/path'); + storage.set('foo2', 'bar'); + storage.set('some/foo2/path', 'some/bar/path'); - await timeout(2); + await timeout(2); - storage.delete('foo1'); - storage.delete('some/foo1/path'); + storage.delete('foo1'); + storage.delete('some/foo1/path'); - await timeout(2); + await timeout(2); - storage.delete('foo4'); - storage.delete('some/foo4/path'); + storage.delete('foo4'); + storage.delete('some/foo4/path'); - await timeout(5); + await timeout(5); - storage.set('foo3', 'bar'); - await storage.set('some/foo3/path', 'some/bar/path'); + storage.set('foo3', 'bar'); + await storage.set('some/foo3/path', 'some/bar/path'); - const items = await storage.getStorage().getItems(); - strictEqual(items.get('foo'), 'bar'); - strictEqual(items.get('some/foo/path'), 'some/bar/path'); - strictEqual(items.has('foo1'), false); - strictEqual(items.has('some/foo1/path'), false); - strictEqual(items.get('foo2'), 'bar'); - strictEqual(items.get('some/foo2/path'), 'some/bar/path'); - strictEqual(items.get('foo3'), 'bar'); - strictEqual(items.get('some/foo3/path'), 'some/bar/path'); + const items = await storage.getStorage().getItems(); + strictEqual(items.get('foo'), 'bar'); + strictEqual(items.get('some/foo/path'), 'some/bar/path'); + strictEqual(items.has('foo1'), false); + strictEqual(items.has('some/foo1/path'), false); + strictEqual(items.get('foo2'), 'bar'); + strictEqual(items.get('some/foo2/path'), 'some/bar/path'); + strictEqual(items.get('foo3'), 'bar'); + strictEqual(items.get('some/foo3/path'), 'some/bar/path'); - await storage.close(); + await storage.close(); + }); }); test('lots of INSERT & DELETE (below inline max)', async () => { diff --git a/src/vs/base/test/node/pfs/pfs.test.ts b/src/vs/base/test/node/pfs/pfs.test.ts index e45782e236f65..4c15c3ce14318 100644 --- a/src/vs/base/test/node/pfs/pfs.test.ts +++ b/src/vs/base/test/node/pfs/pfs.test.ts @@ -11,21 +11,28 @@ import { VSBuffer } from 'vs/base/common/buffer'; import { randomPath } from 'vs/base/common/extpath'; import { join, sep } from 'vs/base/common/path'; import { isWindows } from 'vs/base/common/platform'; -import { Promises, RimRafMode, rimrafSync, SymlinkSupport, writeFileSync } from 'vs/base/node/pfs'; +import { configureFlushOnWrite, Promises, RimRafMode, rimrafSync, SymlinkSupport, writeFileSync } from 'vs/base/node/pfs'; import { flakySuite, getPathFromAmdModule, getRandomTestPath } from 'vs/base/test/node/testUtils'; +configureFlushOnWrite(false); // speed up all unit tests by disabling flush on write + flakySuite('PFS', function () { let testDir: string; setup(() => { + configureFlushOnWrite(true); // but enable flushing for the purpose of these tests testDir = getRandomTestPath(tmpdir(), 'vsctests', 'pfs'); return Promises.mkdir(testDir, { recursive: true }); }); - teardown(() => { - return Promises.rm(testDir); + teardown(async () => { + try { + await Promises.rm(testDir); + } finally { + configureFlushOnWrite(false); + } }); test('writeFile', async () => { diff --git a/src/vs/platform/files/common/inMemoryFilesystemProvider.ts b/src/vs/platform/files/common/inMemoryFilesystemProvider.ts index f4d13e998ecbd..5ee8e5366b647 100644 --- a/src/vs/platform/files/common/inMemoryFilesystemProvider.ts +++ b/src/vs/platform/files/common/inMemoryFilesystemProvider.ts @@ -143,6 +143,10 @@ export class InMemoryFileSystemProvider extends Disposable implements IFileSyste } async mkdir(resource: URI): Promise { + if (this._lookup(resource, true)) { + throw new FileSystemProviderError('file exists already', FileSystemProviderErrorCode.FileExists); + } + const basename = resources.basename(resource); const dirname = resources.dirname(resource); const parent = this._lookupAsDirectory(dirname, false); diff --git a/src/vs/platform/files/node/diskFileSystemProvider.ts b/src/vs/platform/files/node/diskFileSystemProvider.ts index 08c155e011e01..708221073ac4c 100644 --- a/src/vs/platform/files/node/diskFileSystemProvider.ts +++ b/src/vs/platform/files/node/diskFileSystemProvider.ts @@ -258,7 +258,12 @@ export class DiskFileSystemProvider extends AbstractDiskFileSystemProvider imple private readonly mapHandleToLock = new Map(); private readonly writeHandles = new Map(); - private canFlush: boolean = true; + + private static canFlush: boolean = true; + + static configureFlushOnWrite(enabled: boolean): void { + DiskFileSystemProvider.canFlush = enabled; + } async open(resource: URI, opts: IFileOpenOptions): Promise { const filePath = this.toFilePath(resource); @@ -389,13 +394,13 @@ export class DiskFileSystemProvider extends AbstractDiskFileSystemProvider imple // If a handle is closed that was used for writing, ensure // to flush the contents to disk if possible. - if (this.writeHandles.delete(fd) && this.canFlush) { + if (this.writeHandles.delete(fd) && DiskFileSystemProvider.canFlush) { try { await Promises.fdatasync(fd); // https://github.com/microsoft/vscode/issues/9589 } catch (error) { // In some exotic setups it is well possible that node fails to sync // In that case we disable flushing and log the error to our logger - this.canFlush = false; + DiskFileSystemProvider.configureFlushOnWrite(false); this.logService.error(error); } } diff --git a/src/vs/platform/files/test/node/diskFileService.test.ts b/src/vs/platform/files/test/node/diskFileService.test.ts index de1f452112254..c76b85fe292ff 100644 --- a/src/vs/platform/files/test/node/diskFileService.test.ts +++ b/src/vs/platform/files/test/node/diskFileService.test.ts @@ -127,6 +127,8 @@ export class TestDiskFileSystemProvider extends DiskFileSystemProvider { } } +DiskFileSystemProvider.configureFlushOnWrite(false); // speed up all unit tests by disabling flush on write + flakySuite('Disk File Service', function () { const testSchema = 'test'; @@ -140,6 +142,8 @@ flakySuite('Disk File Service', function () { const disposables = new DisposableStore(); setup(async () => { + DiskFileSystemProvider.configureFlushOnWrite(true); // but enable flushing for the purpose of these tests + const logService = new NullLogService(); service = new FileService(logService); @@ -160,10 +164,14 @@ flakySuite('Disk File Service', function () { await Promises.copy(sourceDir, testDir, { preserveSymlinks: false }); }); - teardown(() => { - disposables.clear(); + teardown(async () => { + try { + disposables.clear(); - return Promises.rm(testDir); + await Promises.rm(testDir); + } finally { + DiskFileSystemProvider.configureFlushOnWrite(false); + } }); test('createFolder', async () => { diff --git a/src/vs/workbench/api/test/browser/mainThreadEditors.test.ts b/src/vs/workbench/api/test/browser/mainThreadEditors.test.ts index 859c9c28ee83e..6ee05e73b5a4d 100644 --- a/src/vs/workbench/api/test/browser/mainThreadEditors.test.ts +++ b/src/vs/workbench/api/test/browser/mainThreadEditors.test.ts @@ -17,7 +17,7 @@ import { Range } from 'vs/editor/common/core/range'; import { Position } from 'vs/editor/common/core/position'; import { IModelService } from 'vs/editor/common/services/model'; import { EditOperation } from 'vs/editor/common/core/editOperation'; -import { TestFileService, TestEditorService, TestEditorGroupsService, TestEnvironmentService, TestLifecycleService } from 'vs/workbench/test/browser/workbenchTestServices'; +import { TestFileService, TestEditorService, TestEditorGroupsService, TestEnvironmentService, TestLifecycleService, TestWorkingCopyService } from 'vs/workbench/test/browser/workbenchTestServices'; import { BulkEditService } from 'vs/workbench/contrib/bulkEdit/browser/bulkEditService'; import { NullLogService, ILogService } from 'vs/platform/log/common/log'; import { ITextModelService, IResolvedTextEditorModel } from 'vs/editor/common/services/resolverService'; @@ -56,6 +56,7 @@ import { LanguageService } from 'vs/editor/common/services/languageService'; import { LanguageFeatureDebounceService } from 'vs/editor/common/services/languageFeatureDebounce'; import { LanguageFeaturesService } from 'vs/editor/common/services/languageFeaturesService'; import { MainThreadBulkEdits } from 'vs/workbench/api/browser/mainThreadBulkEdits'; +import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService'; suite('MainThreadEditors', () => { @@ -114,6 +115,7 @@ suite('MainThreadEditors', () => { services.set(IFileService, new TestFileService()); services.set(IEditorService, new TestEditorService()); services.set(ILifecycleService, new TestLifecycleService()); + services.set(IWorkingCopyService, new TestWorkingCopyService()); services.set(IEditorGroupsService, new TestEditorGroupsService()); services.set(ITextFileService, new class extends mock() { override isDirty() { return false; } diff --git a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts index 02805db79eb33..e8a9551fe192f 100644 --- a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts @@ -83,7 +83,7 @@ class SurroundWithSnippetEditorAction extends EditorAction2 { } SnippetController2.get(editor)?.insert(snippet.codeSnippet, { clipboardText }); - snippetService.updateUsageTimestamp(snippet); + snippetsService.updateUsageTimestamp(snippet); } } diff --git a/src/vs/workbench/services/workingCopy/common/workingCopyHistoryTracker.ts b/src/vs/workbench/services/workingCopy/common/workingCopyHistoryTracker.ts index ed05ae2c5ff7c..7e3d7a7c2b49e 100644 --- a/src/vs/workbench/services/workingCopy/common/workingCopyHistoryTracker.ts +++ b/src/vs/workbench/services/workingCopy/common/workingCopyHistoryTracker.ts @@ -193,7 +193,8 @@ export class WorkingCopyHistoryTracker extends Disposable implements IWorkbenchC private shouldTrackHistory(resource: URI, stat: IFileStatWithMetadata): boolean { if ( resource.scheme !== this.pathService.defaultUriScheme && // track history for all workspace resources - resource.scheme !== Schemas.vscodeUserData // track history for all settings + resource.scheme !== Schemas.vscodeUserData && // track history for all settings + resource.scheme !== Schemas.inMemory // track history for tests that use in-memory ) { return false; // do not support unknown resources } diff --git a/src/vs/workbench/services/workingCopy/test/browser/resourceWorkingCopy.test.ts b/src/vs/workbench/services/workingCopy/test/browser/resourceWorkingCopy.test.ts index 758c611b6a508..b7f6501ab428a 100644 --- a/src/vs/workbench/services/workingCopy/test/browser/resourceWorkingCopy.test.ts +++ b/src/vs/workbench/services/workingCopy/test/browser/resourceWorkingCopy.test.ts @@ -14,6 +14,7 @@ import { IRevertOptions, ISaveOptions } from 'vs/workbench/common/editor'; import { ResourceWorkingCopy } from 'vs/workbench/services/workingCopy/common/resourceWorkingCopy'; import { WorkingCopyCapabilities, IWorkingCopyBackup } from 'vs/workbench/services/workingCopy/common/workingCopy'; import { DisposableStore } from 'vs/base/common/lifecycle'; +import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler'; suite('ResourceWorkingCopy', function () { @@ -55,21 +56,23 @@ suite('ResourceWorkingCopy', function () { }); test('orphaned tracking', async () => { - assert.strictEqual(workingCopy.isOrphaned(), false); + runWithFakedTimers({}, async () => { + assert.strictEqual(workingCopy.isOrphaned(), false); - let onDidChangeOrphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); - accessor.fileService.notExistsSet.set(resource, true); - accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.DELETED }], false)); + let onDidChangeOrphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); + accessor.fileService.notExistsSet.set(resource, true); + accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.DELETED }], false)); - await onDidChangeOrphanedPromise; - assert.strictEqual(workingCopy.isOrphaned(), true); + await onDidChangeOrphanedPromise; + assert.strictEqual(workingCopy.isOrphaned(), true); - onDidChangeOrphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); - accessor.fileService.notExistsSet.delete(resource); - accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.ADDED }], false)); + onDidChangeOrphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); + accessor.fileService.notExistsSet.delete(resource); + accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.ADDED }], false)); - await onDidChangeOrphanedPromise; - assert.strictEqual(workingCopy.isOrphaned(), false); + await onDidChangeOrphanedPromise; + assert.strictEqual(workingCopy.isOrphaned(), false); + }); }); diff --git a/src/vs/workbench/services/workingCopy/test/browser/storedFileWorkingCopy.test.ts b/src/vs/workbench/services/workingCopy/test/browser/storedFileWorkingCopy.test.ts index 0fce73b2ce7d3..4dc6c6e598b1b 100644 --- a/src/vs/workbench/services/workingCopy/test/browser/storedFileWorkingCopy.test.ts +++ b/src/vs/workbench/services/workingCopy/test/browser/storedFileWorkingCopy.test.ts @@ -17,6 +17,7 @@ import { FileChangesEvent, FileChangeType, FileOperationError, FileOperationResu import { SaveReason, SaveSourceRegistry } from 'vs/workbench/common/editor'; import { Promises } from 'vs/base/common/async'; import { consumeReadable, consumeStream, isReadableStream } from 'vs/base/common/stream'; +import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler'; export class TestStoredFileWorkingCopyModel extends Disposable implements IStoredFileWorkingCopyModel { @@ -126,21 +127,23 @@ suite('StoredFileWorkingCopy', function () { }); test('orphaned tracking', async () => { - assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), false); + runWithFakedTimers({}, async () => { + assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), false); - let onDidChangeOrphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); - accessor.fileService.notExistsSet.set(resource, true); - accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.DELETED }], false)); + let onDidChangeOrphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); + accessor.fileService.notExistsSet.set(resource, true); + accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.DELETED }], false)); - await onDidChangeOrphanedPromise; - assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), true); + await onDidChangeOrphanedPromise; + assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), true); - onDidChangeOrphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); - accessor.fileService.notExistsSet.delete(resource); - accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.ADDED }], false)); + onDidChangeOrphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); + accessor.fileService.notExistsSet.delete(resource); + accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.ADDED }], false)); - await onDidChangeOrphanedPromise; - assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), false); + await onDidChangeOrphanedPromise; + assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), false); + }); }); test('dirty', async () => { @@ -294,56 +297,60 @@ suite('StoredFileWorkingCopy', function () { }); test('resolve (with backup, preserves metadata and orphaned state)', async () => { - await workingCopy.resolve({ contents: bufferToStream(VSBuffer.fromString('hello backup')) }); + runWithFakedTimers({}, async () => { + await workingCopy.resolve({ contents: bufferToStream(VSBuffer.fromString('hello backup')) }); - const orphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); + const orphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); - accessor.fileService.notExistsSet.set(resource, true); - accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.DELETED }], false)); + accessor.fileService.notExistsSet.set(resource, true); + accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.DELETED }], false)); - await orphanedPromise; - assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), true); + await orphanedPromise; + assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), true); - const backup = await workingCopy.backup(CancellationToken.None); - await accessor.workingCopyBackupService.backup(workingCopy, backup.content, undefined, backup.meta); + const backup = await workingCopy.backup(CancellationToken.None); + await accessor.workingCopyBackupService.backup(workingCopy, backup.content, undefined, backup.meta); - assert.strictEqual(accessor.workingCopyBackupService.hasBackupSync(workingCopy), true); + assert.strictEqual(accessor.workingCopyBackupService.hasBackupSync(workingCopy), true); - workingCopy.dispose(); + workingCopy.dispose(); - workingCopy = createWorkingCopy(); - await workingCopy.resolve(); + workingCopy = createWorkingCopy(); + await workingCopy.resolve(); - assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), true); + assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), true); - const backup2 = await workingCopy.backup(CancellationToken.None); - assert.deepStrictEqual(backup.meta, backup2.meta); + const backup2 = await workingCopy.backup(CancellationToken.None); + assert.deepStrictEqual(backup.meta, backup2.meta); + }); }); test('resolve (updates orphaned state accordingly)', async () => { - await workingCopy.resolve(); - - const orphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); - - accessor.fileService.notExistsSet.set(resource, true); - accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.DELETED }], false)); + runWithFakedTimers({}, async () => { + await workingCopy.resolve(); - await orphanedPromise; - assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), true); + const orphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); - // resolving clears orphaned state when successful - accessor.fileService.notExistsSet.delete(resource); - await workingCopy.resolve({ forceReadFromFile: true }); - assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), false); + accessor.fileService.notExistsSet.set(resource, true); + accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.DELETED }], false)); - // resolving adds orphaned state when fail to read - try { - accessor.fileService.readShouldThrowError = new FileOperationError('file not found', FileOperationResult.FILE_NOT_FOUND); - await workingCopy.resolve(); + await orphanedPromise; assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), true); - } finally { - accessor.fileService.readShouldThrowError = undefined; - } + + // resolving clears orphaned state when successful + accessor.fileService.notExistsSet.delete(resource); + await workingCopy.resolve({ forceReadFromFile: true }); + assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), false); + + // resolving adds orphaned state when fail to read + try { + accessor.fileService.readShouldThrowError = new FileOperationError('file not found', FileOperationResult.FILE_NOT_FOUND); + await workingCopy.resolve(); + assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), true); + } finally { + accessor.fileService.readShouldThrowError = undefined; + } + }); }); test('resolve (FILE_NOT_MODIFIED_SINCE can be handled for resolved working copies)', async () => { @@ -573,32 +580,34 @@ suite('StoredFileWorkingCopy', function () { }); test('save (no errors) - save clears orphaned', async () => { - let savedCounter = 0; - workingCopy.onDidSave(e => { - savedCounter++; - }); + runWithFakedTimers({}, async () => { + let savedCounter = 0; + workingCopy.onDidSave(e => { + savedCounter++; + }); - let saveErrorCounter = 0; - workingCopy.onDidSaveError(() => { - saveErrorCounter++; - }); + let saveErrorCounter = 0; + workingCopy.onDidSaveError(() => { + saveErrorCounter++; + }); - await workingCopy.resolve(); + await workingCopy.resolve(); - // save clears orphaned - const orphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); + // save clears orphaned + const orphanedPromise = Event.toPromise(workingCopy.onDidChangeOrphaned); - accessor.fileService.notExistsSet.set(resource, true); - accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.DELETED }], false)); + accessor.fileService.notExistsSet.set(resource, true); + accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource, type: FileChangeType.DELETED }], false)); - await orphanedPromise; - assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), true); + await orphanedPromise; + assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), true); - await workingCopy.save({ force: true }); - assert.strictEqual(savedCounter, 1); - assert.strictEqual(saveErrorCounter, 0); - assert.strictEqual(workingCopy.isDirty(), false); - assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), false); + await workingCopy.save({ force: true }); + assert.strictEqual(savedCounter, 1); + assert.strictEqual(saveErrorCounter, 0); + assert.strictEqual(workingCopy.isDirty(), false); + assert.strictEqual(workingCopy.hasState(StoredFileWorkingCopyState.ORPHAN), false); + }); }); test('save (errors)', async () => { diff --git a/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryService.test.ts b/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryService.test.ts index 6bf694104dda1..169bbdfc8bf63 100644 --- a/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryService.test.ts +++ b/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryService.test.ts @@ -30,12 +30,12 @@ import { firstOrDefault } from 'vs/base/common/arrays'; class TestWorkbenchEnvironmentService extends NativeWorkbenchEnvironmentService { - constructor(private readonly testDir: string) { - super({ ...TestNativeWindowConfiguration, 'user-data-dir': testDir }, TestProductService); + constructor(private readonly testDir: URI | string) { + super({ ...TestNativeWindowConfiguration, 'user-data-dir': URI.isUri(testDir) ? testDir.fsPath : testDir }, TestProductService); } override get localHistoryHome() { - return joinPath(URI.file(this.testDir), 'History'); + return joinPath(URI.isUri(this.testDir) ? this.testDir : URI.file(this.testDir), 'History'); } } @@ -45,7 +45,7 @@ export class TestWorkingCopyHistoryService extends NativeWorkingCopyHistoryServi readonly _configurationService: TestConfigurationService; readonly _lifecycleService: TestLifecycleService; - constructor(testDir: string) { + constructor(testDir: URI | string) { const environmentService = new TestWorkbenchEnvironmentService(testDir); const logService = new NullLogService(); const fileService = new FileService(logService); diff --git a/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryTracker.test.ts b/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryTracker.test.ts index 945f8e4b6ab58..931ac6cbaef3b 100644 --- a/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryTracker.test.ts +++ b/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryTracker.test.ts @@ -5,12 +5,10 @@ import * as assert from 'assert'; import { Event } from 'vs/base/common/event'; -import { flakySuite } from 'vs/base/test/common/testUtils'; import { TestContextService, TestWorkingCopy } from 'vs/workbench/test/common/workbenchTestServices'; -import { getRandomTestPath } from 'vs/base/test/node/testUtils'; +import { randomPath } from 'vs/base/common/extpath'; import { tmpdir } from 'os'; import { join } from 'vs/base/common/path'; -import { Promises } from 'vs/base/node/pfs'; import { URI } from 'vs/base/common/uri'; import { TestWorkingCopyHistoryService } from 'vs/workbench/services/workingCopy/test/electron-browser/workingCopyHistoryService.test'; import { WorkingCopyHistoryTracker } from 'vs/workbench/services/workingCopy/common/workingCopyHistoryTracker'; @@ -28,22 +26,26 @@ import { TestNotificationService } from 'vs/platform/notification/test/common/te import { CancellationToken } from 'vs/base/common/cancellation'; import { IWorkingCopyHistoryEntry, IWorkingCopyHistoryEntryDescriptor } from 'vs/workbench/services/workingCopy/common/workingCopyHistory'; import { assertIsDefined } from 'vs/base/common/types'; +import { VSBuffer } from 'vs/base/common/buffer'; +import { InMemoryFileSystemProvider } from 'vs/platform/files/common/inMemoryFilesystemProvider'; +import { IDisposable } from 'vs/base/common/lifecycle'; -flakySuite('WorkingCopyHistoryTracker', () => { +suite('WorkingCopyHistoryTracker', () => { - let testDir: string; - let historyHome: string; - let workHome: string; + let testDir: URI; + let historyHome: URI; + let workHome: URI; let workingCopyHistoryService: TestWorkingCopyHistoryService; let workingCopyService: WorkingCopyService; let fileService: IFileService; let configurationService: TestConfigurationService; + let inMemoryFileSystemDisposable: IDisposable; let tracker: WorkingCopyHistoryTracker; - let testFile1Path: string; - let testFile2Path: string; + let testFile1Path: URI; + let testFile2Path: URI; const testFile1PathContents = 'Hello Foo'; const testFile2PathContents = [ @@ -65,25 +67,27 @@ flakySuite('WorkingCopyHistoryTracker', () => { } setup(async () => { - testDir = getRandomTestPath(tmpdir(), 'vsctests', 'workingcopyhistorytracker'); - historyHome = join(testDir, 'User', 'History'); - workHome = join(testDir, 'work'); + testDir = URI.file(randomPath(join(tmpdir(), 'vsctests', 'workingcopyhistorytracker'))).with({ scheme: Schemas.inMemory }); + historyHome = joinPath(testDir, 'User', 'History'); + workHome = joinPath(testDir, 'work'); workingCopyHistoryService = new TestWorkingCopyHistoryService(testDir); workingCopyService = new WorkingCopyService(); fileService = workingCopyHistoryService._fileService; configurationService = workingCopyHistoryService._configurationService; + inMemoryFileSystemDisposable = fileService.registerProvider(Schemas.inMemory, new InMemoryFileSystemProvider()); + tracker = createTracker(); - await Promises.mkdir(historyHome, { recursive: true }); - await Promises.mkdir(workHome, { recursive: true }); + await fileService.createFolder(historyHome); + await fileService.createFolder(workHome); - testFile1Path = join(workHome, 'foo.txt'); - testFile2Path = join(workHome, 'bar.txt'); + testFile1Path = joinPath(workHome, 'foo.txt'); + testFile2Path = joinPath(workHome, 'bar.txt'); - await Promises.writeFile(testFile1Path, testFile1PathContents); - await Promises.writeFile(testFile2Path, testFile2PathContents); + await fileService.writeFile(testFile1Path, VSBuffer.fromString(testFile1PathContents)); + await fileService.writeFile(testFile2Path, VSBuffer.fromString(testFile2PathContents)); }); function createTracker() { @@ -99,17 +103,19 @@ flakySuite('WorkingCopyHistoryTracker', () => { ); } - teardown(() => { + teardown(async () => { workingCopyHistoryService.dispose(); workingCopyService.dispose(); tracker.dispose(); - return Promises.rm(testDir); + await fileService.del(testDir, { recursive: true }); + + inMemoryFileSystemDisposable.dispose(); }); test('history entry added on save', async () => { - const workingCopy1 = new TestWorkingCopy(URI.file(testFile1Path)); - const workingCopy2 = new TestWorkingCopy(URI.file(testFile2Path)); + const workingCopy1 = new TestWorkingCopy(testFile1Path); + const workingCopy2 = new TestWorkingCopy(testFile2Path); const stat1 = await fileService.resolve(workingCopy1.resource, { resolveMetadata: true }); const stat2 = await fileService.resolve(workingCopy2.resource, { resolveMetadata: true }); @@ -136,7 +142,7 @@ flakySuite('WorkingCopyHistoryTracker', () => { }); test('history entry skipped when setting disabled (globally)', async () => { - configurationService.setUserConfiguration('workbench.localHistory.enabled', false, URI.file(testFile1Path)); + configurationService.setUserConfiguration('workbench.localHistory.enabled', false, testFile1Path); return assertNoLocalHistoryEntryAddedWithSettingsConfigured(); }); @@ -152,14 +158,14 @@ flakySuite('WorkingCopyHistoryTracker', () => { }); test('history entry skipped when too large', async () => { - configurationService.setUserConfiguration('workbench.localHistory.maxFileSize', 0, URI.file(testFile1Path)); + configurationService.setUserConfiguration('workbench.localHistory.maxFileSize', 0, testFile1Path); return assertNoLocalHistoryEntryAddedWithSettingsConfigured(); }); async function assertNoLocalHistoryEntryAddedWithSettingsConfigured(): Promise { - const workingCopy1 = new TestWorkingCopy(URI.file(testFile1Path)); - const workingCopy2 = new TestWorkingCopy(URI.file(testFile2Path)); + const workingCopy1 = new TestWorkingCopy(testFile1Path); + const workingCopy2 = new TestWorkingCopy(testFile2Path); const stat1 = await fileService.resolve(workingCopy1.resource, { resolveMetadata: true }); const stat2 = await fileService.resolve(workingCopy2.resource, { resolveMetadata: true }); @@ -187,7 +193,7 @@ flakySuite('WorkingCopyHistoryTracker', () => { test('entries moved (file rename)', async () => { const entriesMoved = Event.toPromise(workingCopyHistoryService.onDidMoveEntries); - const workingCopy = new TestWorkingCopy(URI.file(testFile1Path)); + const workingCopy = new TestWorkingCopy(testFile1Path); const entry1 = await addEntry({ resource: workingCopy.resource, source: 'test-source' }, CancellationToken.None); const entry2 = await addEntry({ resource: workingCopy.resource, source: 'test-source' }, CancellationToken.None); @@ -233,8 +239,8 @@ flakySuite('WorkingCopyHistoryTracker', () => { test('entries moved (folder rename)', async () => { const entriesMoved = Event.toPromise(workingCopyHistoryService.onDidMoveEntries); - const workingCopy1 = new TestWorkingCopy(URI.file(testFile1Path)); - const workingCopy2 = new TestWorkingCopy(URI.file(testFile2Path)); + const workingCopy1 = new TestWorkingCopy(testFile1Path); + const workingCopy2 = new TestWorkingCopy(testFile2Path); const entry1A = await addEntry({ resource: workingCopy1.resource, source: 'test-source' }, CancellationToken.None); const entry2A = await addEntry({ resource: workingCopy1.resource, source: 'test-source' }, CancellationToken.None); @@ -250,8 +256,8 @@ flakySuite('WorkingCopyHistoryTracker', () => { entries = await workingCopyHistoryService.getEntries(workingCopy2.resource, CancellationToken.None); assert.strictEqual(entries.length, 3); - const renamedWorkHome = joinPath(dirname(URI.file(workHome)), 'renamed'); - await workingCopyHistoryService._fileService.move(URI.file(workHome), renamedWorkHome); + const renamedWorkHome = joinPath(dirname(testDir), 'renamed'); + await workingCopyHistoryService._fileService.move(workHome, renamedWorkHome); const renamedWorkingCopy1Resource = joinPath(renamedWorkHome, basename(workingCopy1.resource)); const renamedWorkingCopy2Resource = joinPath(renamedWorkHome, basename(workingCopy2.resource)); From 14dfbbd6412dfb093dd72ce9c304fbcd1588e2a5 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 15 Jul 2022 14:43:47 +0200 Subject: [PATCH 083/121] surround with code action needs non-empty selection, uses active end of selection --- .../contrib/snippets/browser/surroundWithSnippet.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts index e8a9551fe192f..c582bf54e7d49 100644 --- a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts @@ -116,7 +116,12 @@ class SurroundWithSnippetCodeActionProvider implements CodeActionProvider, IWork async provideCodeActions(model: ITextModel, range: Range | Selection): Promise { - const snippets = await getSurroundableSnippets(this._snippetService, model, range.getEndPosition()); + if (range.isEmpty()) { + return undefined; + } + + const position = Selection.isISelection(range) ? range.getPosition() : range.getStartPosition(); + const snippets = await getSurroundableSnippets(this._snippetService, model, position); if (!snippets.length) { return undefined; } From 8aaa0777ed850151634ff2066c1b70c787d49900 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 15 Jul 2022 14:50:47 +0200 Subject: [PATCH 084/121] no hidden snippets as code action --- .../contrib/snippets/browser/surroundWithSnippet.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts index c582bf54e7d49..7c0842812dd33 100644 --- a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts @@ -27,13 +27,13 @@ import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWo import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; import { Position } from 'vs/editor/common/core/position'; -async function getSurroundableSnippets(snippetsService: ISnippetsService, model: ITextModel, position: Position): Promise { +async function getSurroundableSnippets(snippetsService: ISnippetsService, model: ITextModel, position: Position, includeDisabledSnippets: boolean): Promise { const { lineNumber, column } = position; model.tokenization.tokenizeIfCheap(lineNumber); const languageId = model.getLanguageIdAtPosition(lineNumber, column); - const allSnippets = await snippetsService.getSnippets(languageId, { includeNoPrefixSnippets: true, includeDisabledSnippets: true }); + const allSnippets = await snippetsService.getSnippets(languageId, { includeNoPrefixSnippets: true, includeDisabledSnippets }); return allSnippets.filter(snippet => snippet.usesSelection); } @@ -67,7 +67,7 @@ class SurroundWithSnippetEditorAction extends EditorAction2 { const snippetsService = accessor.get(ISnippetsService); const clipboardService = accessor.get(IClipboardService); - const snippets = await getSurroundableSnippets(snippetsService, editor.getModel(), editor.getPosition()); + const snippets = await getSurroundableSnippets(snippetsService, editor.getModel(), editor.getPosition(), true); if (!snippets.length) { return; } @@ -121,7 +121,7 @@ class SurroundWithSnippetCodeActionProvider implements CodeActionProvider, IWork } const position = Selection.isISelection(range) ? range.getPosition() : range.getStartPosition(); - const snippets = await getSurroundableSnippets(this._snippetService, model, position); + const snippets = await getSurroundableSnippets(this._snippetService, model, position, false); if (!snippets.length) { return undefined; } From f071ac591c9be632e5a6b4e35c3acc685c447189 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 15 Jul 2022 15:38:55 +0200 Subject: [PATCH 085/121] add concept of top level snippet and allow to get snippets without language filter --- .../contrib/snippets/browser/insertSnippet.ts | 1 + .../snippets/browser/snippets.contribution.ts | 7 ++- .../contrib/snippets/browser/snippetsFile.ts | 10 ++-- .../snippets/browser/snippetsService.ts | 39 ++++++++++--- .../snippets/test/browser/snippetFile.test.ts | 20 +++---- .../test/browser/snippetsRewrite.test.ts | 4 +- .../test/browser/snippetsService.test.ts | 56 +++++++++++++------ 7 files changed, 95 insertions(+), 42 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts b/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts index 2d84a9a71a5da..f52422764cae4 100644 --- a/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts @@ -95,6 +95,7 @@ class InsertSnippetAction extends EditorAction { if (snippet) { return resolve(new Snippet( + false, [], '', '', diff --git a/src/vs/workbench/contrib/snippets/browser/snippets.contribution.ts b/src/vs/workbench/contrib/snippets/browser/snippets.contribution.ts index 02b6c4b4238df..ac1e213fc5595 100644 --- a/src/vs/workbench/contrib/snippets/browser/snippets.contribution.ts +++ b/src/vs/workbench/contrib/snippets/browser/snippets.contribution.ts @@ -16,6 +16,7 @@ export interface ISnippetGetOptions { includeDisabledSnippets?: boolean; includeNoPrefixSnippets?: boolean; noRecencySort?: boolean; + topLevelSnippets?: boolean; } export interface ISnippetsService { @@ -30,7 +31,7 @@ export interface ISnippetsService { updateUsageTimestamp(snippet: Snippet): void; - getSnippets(languageId: string, opt?: ISnippetGetOptions): Promise; + getSnippets(languageId: string | undefined, opt?: ISnippetGetOptions): Promise; getSnippetsSync(languageId: string, opt?: ISnippetGetOptions): Snippet[]; } @@ -42,6 +43,10 @@ const snippetSchemaProperties: IJSONSchemaMap = { description: nls.localize('snippetSchema.json.prefix', 'The prefix to use when selecting the snippet in intellisense'), type: ['string', 'array'] }, + isTopLevel: { + description: nls.localize('snippetSchema.json.isTopLevel', 'The snippet is only applicable to empty files.'), + type: 'string' + }, body: { markdownDescription: nls.localize('snippetSchema.json.body', 'The snippet content. Use `$1`, `${1:defaultText}` to define cursor positions, use `$0` for the final cursor position. Insert variable values with `${varName}` and `${varName:defaultText}`, e.g. `This is file: $TM_FILENAME`.'), type: ['string', 'array'], diff --git a/src/vs/workbench/contrib/snippets/browser/snippetsFile.ts b/src/vs/workbench/contrib/snippets/browser/snippetsFile.ts index 72a3e74f64cfb..b6ce272ef288f 100644 --- a/src/vs/workbench/contrib/snippets/browser/snippetsFile.ts +++ b/src/vs/workbench/contrib/snippets/browser/snippetsFile.ts @@ -8,7 +8,6 @@ import { localize } from 'vs/nls'; import { extname, basename } from 'vs/base/common/path'; import { SnippetParser, Variable, Placeholder, Text } from 'vs/editor/contrib/snippet/browser/snippetParser'; import { KnownSnippetVariableNames } from 'vs/editor/contrib/snippet/browser/snippetVariables'; -import { isFalsyOrWhitespace } from 'vs/base/common/strings'; import { URI } from 'vs/base/common/uri'; import { IFileService } from 'vs/platform/files/common/files'; import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions'; @@ -106,6 +105,7 @@ export class Snippet { readonly prefixLow: string; constructor( + readonly isTopLevel: boolean, readonly scopes: string[], readonly name: string, readonly prefix: string, @@ -143,8 +143,9 @@ export class Snippet { interface JsonSerializedSnippet { + isTopLevel?: boolean; body: string | string[]; - scope: string; + scope?: string; prefix: string | string[] | undefined; description: string; } @@ -260,7 +261,7 @@ export class SnippetFile { private _parseSnippet(name: string, snippet: JsonSerializedSnippet, bucket: Snippet[]): void { - let { prefix, body, description } = snippet; + let { isTopLevel, prefix, body, description } = snippet; if (!prefix) { prefix = ''; @@ -281,7 +282,7 @@ export class SnippetFile { if (this.defaultScopes) { scopes = this.defaultScopes; } else if (typeof snippet.scope === 'string') { - scopes = snippet.scope.split(',').map(s => s.trim()).filter(s => !isFalsyOrWhitespace(s)); + scopes = snippet.scope.split(',').map(s => s.trim()).filter(Boolean); } else { scopes = []; } @@ -305,6 +306,7 @@ export class SnippetFile { for (const _prefix of Array.isArray(prefix) ? prefix : Iterable.single(prefix)) { bucket.push(new Snippet( + Boolean(isTopLevel), scopes, name, _prefix, diff --git a/src/vs/workbench/contrib/snippets/browser/snippetsService.ts b/src/vs/workbench/contrib/snippets/browser/snippetsService.ts index da0e5e26960b2..918411b564c74 100644 --- a/src/vs/workbench/contrib/snippets/browser/snippetsService.ts +++ b/src/vs/workbench/contrib/snippets/browser/snippetsService.ts @@ -31,6 +31,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry'; import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile'; +import { insertInto } from 'vs/base/common/arrays'; namespace snippetExt { @@ -265,16 +266,25 @@ class SnippetsService implements ISnippetsService { return this._files.values(); } - async getSnippets(languageId: string, opts?: ISnippetGetOptions): Promise { + async getSnippets(languageId: string | undefined, opts?: ISnippetGetOptions): Promise { await this._joinSnippets(); const result: Snippet[] = []; const promises: Promise[] = []; - if (this._languageService.isRegisteredLanguageId(languageId)) { + if (languageId) { + if (this._languageService.isRegisteredLanguageId(languageId)) { + for (const file of this._files.values()) { + promises.push(file.load() + .then(file => file.select(languageId, result)) + .catch(err => this._logService.error(err, file.location.toString())) + ); + } + } + } else { for (const file of this._files.values()) { promises.push(file.load() - .then(file => file.select(languageId, result)) + .then(file => insertInto(result, result.length, file.data)) .catch(err => this._logService.error(err, file.location.toString())) ); } @@ -297,10 +307,25 @@ class SnippetsService implements ISnippetsService { } private _filterAndSortSnippets(snippets: Snippet[], opts?: ISnippetGetOptions): Snippet[] { - const result = snippets.filter(snippet => { - return (snippet.prefix || opts?.includeNoPrefixSnippets) // prefix or no-prefix wanted - && (this.isEnabled(snippet) || opts?.includeDisabledSnippets); // enabled or disabled wanted - }); + + const result: Snippet[] = []; + + for (const snippet of snippets) { + if (!snippet.prefix && !opts?.includeNoPrefixSnippets) { + // prefix or no-prefix wanted + continue; + } + if (!this.isEnabled(snippet) && !opts?.includeDisabledSnippets) { + // enabled or disabled wanted + continue; + } + if (typeof opts?.topLevelSnippets === 'boolean' && opts.topLevelSnippets !== snippet.isTopLevel) { + // isTopLevel requested but mismatching + continue; + } + result.push(snippet); + } + return result.sort((a, b) => { let result = 0; diff --git a/src/vs/workbench/contrib/snippets/test/browser/snippetFile.test.ts b/src/vs/workbench/contrib/snippets/test/browser/snippetFile.test.ts index b2f87092ad1ba..e9bb5b9853ce2 100644 --- a/src/vs/workbench/contrib/snippets/test/browser/snippetFile.test.ts +++ b/src/vs/workbench/contrib/snippets/test/browser/snippetFile.test.ts @@ -25,12 +25,12 @@ suite('Snippets', function () { assert.strictEqual(bucket.length, 0); file = new TestSnippetFile(URI.file('somepath/foo.code-snippets'), [ - new Snippet(['foo'], 'FooSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), - new Snippet(['foo'], 'FooSnippet2', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), - new Snippet(['bar'], 'BarSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), - new Snippet(['bar.comment'], 'BarSnippet2', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), - new Snippet(['bar.strings'], 'BarSnippet2', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), - new Snippet(['bazz', 'bazz'], 'BazzSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(false, ['foo'], 'FooSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(false, ['foo'], 'FooSnippet2', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(false, ['bar'], 'BarSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(false, ['bar.comment'], 'BarSnippet2', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(false, ['bar.strings'], 'BarSnippet2', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(false, ['bazz', 'bazz'], 'BazzSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), ]); bucket = []; @@ -57,8 +57,8 @@ suite('Snippets', function () { test('SnippetFile#select - any scope', function () { const file = new TestSnippetFile(URI.file('somepath/foo.code-snippets'), [ - new Snippet([], 'AnySnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), - new Snippet(['foo'], 'FooSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(false, [], 'AnySnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), + new Snippet(false, ['foo'], 'FooSnippet1', 'foo', '', 'snippet', 'test', SnippetSource.User, generateUuid()), ]); const bucket: Snippet[] = []; @@ -70,7 +70,7 @@ suite('Snippets', function () { test('Snippet#needsClipboard', function () { function assertNeedsClipboard(body: string, expected: boolean): void { - const snippet = new Snippet(['foo'], 'FooSnippet1', 'foo', '', body, 'test', SnippetSource.User, generateUuid()); + const snippet = new Snippet(false, ['foo'], 'FooSnippet1', 'foo', '', body, 'test', SnippetSource.User, generateUuid()); assert.strictEqual(snippet.needsClipboard, expected); assert.strictEqual(SnippetParser.guessNeedsClipboard(body), expected); @@ -87,7 +87,7 @@ suite('Snippets', function () { test('Snippet#isTrivial', function () { function assertIsTrivial(body: string, expected: boolean): void { - const snippet = new Snippet(['foo'], 'FooSnippet1', 'foo', '', body, 'test', SnippetSource.User, generateUuid()); + const snippet = new Snippet(false, ['foo'], 'FooSnippet1', 'foo', '', body, 'test', SnippetSource.User, generateUuid()); assert.strictEqual(snippet.isTrivial, expected); } diff --git a/src/vs/workbench/contrib/snippets/test/browser/snippetsRewrite.test.ts b/src/vs/workbench/contrib/snippets/test/browser/snippetsRewrite.test.ts index ac5a579fcfdc2..54e7e2794f0da 100644 --- a/src/vs/workbench/contrib/snippets/test/browser/snippetsRewrite.test.ts +++ b/src/vs/workbench/contrib/snippets/test/browser/snippetsRewrite.test.ts @@ -10,7 +10,7 @@ import { Snippet, SnippetSource } from 'vs/workbench/contrib/snippets/browser/sn suite('SnippetRewrite', function () { function assertRewrite(input: string, expected: string | boolean): void { - const actual = new Snippet(['foo'], 'foo', 'foo', 'foo', input, 'foo', SnippetSource.User, generateUuid()); + const actual = new Snippet(false, ['foo'], 'foo', 'foo', 'foo', input, 'foo', SnippetSource.User, generateUuid()); if (typeof expected === 'boolean') { assert.strictEqual(actual.codeSnippet, input); } else { @@ -48,7 +48,7 @@ suite('SnippetRewrite', function () { }); test('lazy bogous variable rewrite', function () { - const snippet = new Snippet(['fooLang'], 'foo', 'prefix', 'desc', 'This is ${bogous} because it is a ${var}', 'source', SnippetSource.Extension, generateUuid()); + const snippet = new Snippet(false, ['fooLang'], 'foo', 'prefix', 'desc', 'This is ${bogous} because it is a ${var}', 'source', SnippetSource.Extension, generateUuid()); assert.strictEqual(snippet.body, 'This is ${bogous} because it is a ${var}'); assert.strictEqual(snippet.codeSnippet, 'This is ${1:bogous} because it is a ${2:var}'); assert.strictEqual(snippet.isBogous, true); diff --git a/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts b/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts index 81156296016f3..14485ae11a71d 100644 --- a/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts +++ b/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts @@ -57,6 +57,7 @@ suite('SnippetsService', function () { extensions: ['.fooLang',] })); snippetService = new SimpleSnippetService([new Snippet( + false, ['fooLang'], 'barTest', 'bar', @@ -66,6 +67,7 @@ suite('SnippetsService', function () { SnippetSource.User, generateUuid() ), new Snippet( + false, ['fooLang'], 'bazzTest', 'bazz', @@ -126,8 +128,8 @@ suite('SnippetsService', function () { }); test('snippet completions - with different prefixes', async function () { - snippetService = new SimpleSnippetService([new Snippet( + false, ['fooLang'], 'barTest', 'bar', @@ -137,6 +139,7 @@ suite('SnippetsService', function () { SnippetSource.User, generateUuid() ), new Snippet( + false, ['fooLang'], 'name', 'bar-bar', @@ -208,6 +211,7 @@ suite('SnippetsService', function () { test('Cannot use " Date: Fri, 15 Jul 2022 16:55:14 +0200 Subject: [PATCH 086/121] make snippet-contribution a proper contrib-file, remove local registration into contrib-file, move command into their own folder, have a command to populate a file from a top-level snippet --- .../commands/abstractSnippetsActions.ts | 29 +++++ .../{ => commands}/configureSnippets.ts | 29 ++--- .../browser/commands/emptyFileSnippets.ts | 114 ++++++++++++++++++ .../browser/{ => commands}/insertSnippet.ts | 34 +++--- .../{ => commands}/surroundWithSnippet.ts | 32 ++--- .../browser/snippetCompletionProvider.ts | 2 +- .../contrib/snippets/browser/snippetPicker.ts | 2 +- .../snippets/browser/snippets.contribution.ts | 63 +++++----- .../contrib/snippets/browser/snippets.ts | 33 +++++ .../snippets/browser/snippetsService.ts | 6 +- .../contrib/snippets/browser/tabCompletion.ts | 2 +- .../test/browser/snippetsService.test.ts | 2 +- src/vs/workbench/workbench.common.main.ts | 5 - 13 files changed, 256 insertions(+), 97 deletions(-) create mode 100644 src/vs/workbench/contrib/snippets/browser/commands/abstractSnippetsActions.ts rename src/vs/workbench/contrib/snippets/browser/{ => commands}/configureSnippets.ts (95%) create mode 100644 src/vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets.ts rename src/vs/workbench/contrib/snippets/browser/{ => commands}/insertSnippet.ts (84%) rename src/vs/workbench/contrib/snippets/browser/{ => commands}/surroundWithSnippet.ts (84%) create mode 100644 src/vs/workbench/contrib/snippets/browser/snippets.ts diff --git a/src/vs/workbench/contrib/snippets/browser/commands/abstractSnippetsActions.ts b/src/vs/workbench/contrib/snippets/browser/commands/abstractSnippetsActions.ts new file mode 100644 index 0000000000000..46f62be9e1c2f --- /dev/null +++ b/src/vs/workbench/contrib/snippets/browser/commands/abstractSnippetsActions.ts @@ -0,0 +1,29 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { EditorAction2 } from 'vs/editor/browser/editorExtensions'; +import { localize } from 'vs/nls'; +import { Action2, IAction2Options } from 'vs/platform/actions/common/actions'; + +const defaultOptions: Partial = { + category: { + value: localize('snippets', 'Snippets'), + original: 'Snippets' + }, +}; + +export abstract class SnippetsAction extends Action2 { + + constructor(desc: Readonly) { + super({ ...defaultOptions, ...desc }); + } +} + +export abstract class SnippetEditorAction extends EditorAction2 { + + constructor(desc: Readonly) { + super({ ...defaultOptions, ...desc }); + } +} diff --git a/src/vs/workbench/contrib/snippets/browser/configureSnippets.ts b/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts similarity index 95% rename from src/vs/workbench/contrib/snippets/browser/configureSnippets.ts rename to src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts index 917e0da44e437..3bc1b0b6b8935 100644 --- a/src/vs/workbench/contrib/snippets/browser/configureSnippets.ts +++ b/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts @@ -3,21 +3,22 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as nls from 'vs/nls'; -import { ILanguageService } from 'vs/editor/common/languages/language'; +import { isValidBasename } from 'vs/base/common/extpath'; import { extname } from 'vs/base/common/path'; -import { MenuId, registerAction2, Action2 } from 'vs/platform/actions/common/actions'; -import { IOpenerService } from 'vs/platform/opener/common/opener'; +import { basename, joinPath } from 'vs/base/common/resources'; import { URI } from 'vs/base/common/uri'; -import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets.contribution'; -import { IQuickPickItem, IQuickInputService, QuickPickInput } from 'vs/platform/quickinput/common/quickInput'; -import { SnippetSource } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; -import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { ILanguageService } from 'vs/editor/common/languages/language'; +import * as nls from 'vs/nls'; +import { MenuId } from 'vs/platform/actions/common/actions'; import { IFileService } from 'vs/platform/files/common/files'; -import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; -import { isValidBasename } from 'vs/base/common/extpath'; -import { joinPath, basename } from 'vs/base/common/resources'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; +import { IOpenerService } from 'vs/platform/opener/common/opener'; +import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput'; +import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { SnippetsAction } from 'vs/workbench/contrib/snippets/browser/commands/abstractSnippetsActions'; +import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets'; +import { SnippetSource } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; +import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile'; namespace ISnippetPick { @@ -199,7 +200,7 @@ async function createLanguageSnippetFile(pick: ISnippetPick, fileService: IFileS await textFileService.write(pick.filepath, contents); } -registerAction2(class ConfigureSnippets extends Action2 { +export class ConfigureSnippets extends SnippetsAction { constructor() { super({ @@ -221,7 +222,7 @@ registerAction2(class ConfigureSnippets extends Action2 { }); } - async run(accessor: ServicesAccessor, ...args: any[]): Promise { + async run(accessor: ServicesAccessor): Promise { const snippetService = accessor.get(ISnippetsService); const quickInputService = accessor.get(IQuickInputService); @@ -275,4 +276,4 @@ registerAction2(class ConfigureSnippets extends Action2 { } } -}); +} diff --git a/src/vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets.ts b/src/vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets.ts new file mode 100644 index 0000000000000..85376e61a7010 --- /dev/null +++ b/src/vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets.ts @@ -0,0 +1,114 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { groupBy, isFalsyOrEmpty } from 'vs/base/common/arrays'; +import { compare } from 'vs/base/common/strings'; +import { getCodeEditor } from 'vs/editor/browser/editorBrowser'; +import { ILanguageService } from 'vs/editor/common/languages/language'; +import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetController2'; +import { localize } from 'vs/nls'; +import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; +import { IQuickInputService, IQuickPickItem, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput'; +import { SnippetsAction } from 'vs/workbench/contrib/snippets/browser/commands/abstractSnippetsActions'; +import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets'; +import { Snippet } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; + +export class SelectSnippetForEmptyFile extends SnippetsAction { + + constructor() { + super({ + id: 'workbench.action.populateFromSnippet', + title: { + value: localize('label', 'Populate File from Snippet'), + original: 'Populate File from Snippet' + }, + f1: true, + }); + } + + async run(accessor: ServicesAccessor): Promise { + const snippetService = accessor.get(ISnippetsService); + const quickInputService = accessor.get(IQuickInputService); + const editorService = accessor.get(IEditorService); + const langService = accessor.get(ILanguageService); + + const editor = getCodeEditor(editorService.activeTextEditorControl); + if (!editor || !editor.hasModel()) { + return; + } + + const snippets = await snippetService.getSnippets(undefined, { topLevelSnippets: true, noRecencySort: true, includeNoPrefixSnippets: true }); + if (snippets.length === 0) { + return; + } + + const selection = await this._pick(quickInputService, langService, snippets); + if (!selection) { + return; + } + + if (editor.hasModel()) { + // apply snippet edit -> replaces everything + SnippetController2.get(editor)?.apply([{ + range: editor.getModel().getFullModelRange(), + template: selection.snippet.body + }]); + + // set language if possible + if (langService.isRegisteredLanguageId(selection.langId)) { + editor.getModel().setMode(selection.langId); + } + } + } + + private async _pick(quickInputService: IQuickInputService, langService: ILanguageService, snippets: Snippet[]) { + + // spread snippet onto each language it supports + type SnippetAndLanguage = { langId: string; snippet: Snippet }; + const all: SnippetAndLanguage[] = []; + for (const snippet of snippets) { + if (isFalsyOrEmpty(snippet.scopes)) { + all.push({ langId: '', snippet }); + } else { + for (const langId of snippet.scopes) { + all.push({ langId, snippet }); + } + } + } + + type SnippetAndLanguagePick = IQuickPickItem & { snippet: SnippetAndLanguage }; + const picks: (SnippetAndLanguagePick | IQuickPickSeparator)[] = []; + + const groups = groupBy(all, (a, b) => compare(a.langId, b.langId)); + + for (const group of groups) { + let first = true; + for (const item of group) { + + if (first) { + picks.push({ + type: 'separator', + label: langService.getLanguageName(item.langId) ?? item.langId + }); + first = false; + } + + picks.push({ + snippet: item, + label: item.snippet.prefix || item.snippet.name, + detail: item.snippet.description + }); + } + } + + const pick = await quickInputService.pick(picks, { + placeHolder: localize('placeholder', 'Select a snippet'), + matchOnDetail: true, + }); + + return pick?.snippet; + } +} diff --git a/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts b/src/vs/workbench/contrib/snippets/browser/commands/insertSnippet.ts similarity index 84% rename from src/vs/workbench/contrib/snippets/browser/insertSnippet.ts rename to src/vs/workbench/contrib/snippets/browser/commands/insertSnippet.ts index f52422764cae4..aba3f4c5582c7 100644 --- a/src/vs/workbench/contrib/snippets/browser/insertSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/commands/insertSnippet.ts @@ -3,19 +3,18 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as nls from 'vs/nls'; -import { registerEditorAction, ServicesAccessor, EditorAction } from 'vs/editor/browser/editorExtensions'; +import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; +import { ServicesAccessor } from 'vs/editor/browser/editorExtensions'; +import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { ILanguageService } from 'vs/editor/common/languages/language'; -import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands'; -import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets.contribution'; import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetController2'; -import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; -import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { Snippet, SnippetSource } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; +import * as nls from 'vs/nls'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { SnippetEditorAction } from 'vs/workbench/contrib/snippets/browser/commands/abstractSnippetsActions'; import { pickSnippet } from 'vs/workbench/contrib/snippets/browser/snippetPicker'; - +import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets'; +import { Snippet, SnippetSource } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; class Args { @@ -45,13 +44,16 @@ class Args { ) { } } -class InsertSnippetAction extends EditorAction { +export class InsertSnippetAction extends SnippetEditorAction { constructor() { super({ id: 'editor.action.insertSnippet', - label: nls.localize('snippet.suggestions.label', "Insert Snippet"), - alias: 'Insert Snippet', + title: { + value: nls.localize('snippet.suggestions.label', "Insert Snippet"), + original: 'Insert Snippet' + }, + f1: true, precondition: EditorContextKeys.writable, description: { description: `Insert Snippet`, @@ -77,7 +79,8 @@ class InsertSnippetAction extends EditorAction { }); } - async run(accessor: ServicesAccessor, editor: ICodeEditor, arg: any): Promise { + async runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, arg: any) { + const languageService = accessor.get(ILanguageService); const snippetService = accessor.get(ISnippetsService); @@ -148,10 +151,3 @@ class InsertSnippetAction extends EditorAction { snippetService.updateUsageTimestamp(snippet); } } - -registerEditorAction(InsertSnippetAction); - -// compatibility command to make sure old keybinding are still working -CommandsRegistry.registerCommand('editor.action.showSnippets', accessor => { - return accessor.get(ICommandService).executeCommand('editor.action.insertSnippet'); -}); diff --git a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts b/src/vs/workbench/contrib/snippets/browser/commands/surroundWithSnippet.ts similarity index 84% rename from src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts rename to src/vs/workbench/contrib/snippets/browser/commands/surroundWithSnippet.ts index 7c0842812dd33..7a771724f3ab8 100644 --- a/src/vs/workbench/contrib/snippets/browser/surroundWithSnippet.ts +++ b/src/vs/workbench/contrib/snippets/browser/commands/surroundWithSnippet.ts @@ -3,29 +3,26 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { IDisposable } from 'vs/base/common/lifecycle'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { EditorAction2 } from 'vs/editor/browser/editorExtensions'; +import { Position } from 'vs/editor/common/core/position'; +import { IRange, Range } from 'vs/editor/common/core/range'; +import { Selection } from 'vs/editor/common/core/selection'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; +import { CodeAction, CodeActionList, CodeActionProvider } from 'vs/editor/common/languages'; +import { ITextModel } from 'vs/editor/common/model'; +import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; +import { CodeActionKind } from 'vs/editor/contrib/codeAction/browser/types'; import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetController2'; import { localize } from 'vs/nls'; -import { registerAction2 } from 'vs/platform/actions/common/actions'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; +import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; +import { SnippetEditorAction } from 'vs/workbench/contrib/snippets/browser/commands/abstractSnippetsActions'; import { pickSnippet } from 'vs/workbench/contrib/snippets/browser/snippetPicker'; -import { ISnippetsService } from './snippets.contribution'; -import { IDisposable } from 'vs/base/common/lifecycle'; -import { ITextModel } from 'vs/editor/common/model'; -import { CodeAction, CodeActionProvider, CodeActionList } from 'vs/editor/common/languages'; -import { CodeActionKind } from 'vs/editor/contrib/codeAction/browser/types'; -import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; -import { Range, IRange } from 'vs/editor/common/core/range'; -import { Selection } from 'vs/editor/common/core/selection'; import { Snippet } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; -import { Registry } from 'vs/platform/registry/common/platform'; -import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWorkbenchContribution } from 'vs/workbench/common/contributions'; -import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; -import { Position } from 'vs/editor/common/core/position'; +import { ISnippetsService } from '../snippets'; async function getSurroundableSnippets(snippetsService: ISnippetsService, model: ITextModel, position: Position, includeDisabledSnippets: boolean): Promise { @@ -37,7 +34,7 @@ async function getSurroundableSnippets(snippetsService: ISnippetsService, model: return allSnippets.filter(snippet => snippet.usesSelection); } -class SurroundWithSnippetEditorAction extends EditorAction2 { +export class SurroundWithSnippetEditorAction extends SnippetEditorAction { static readonly options = { id: 'editor.action.surroundWithSnippet', @@ -88,7 +85,7 @@ class SurroundWithSnippetEditorAction extends EditorAction2 { } -class SurroundWithSnippetCodeActionProvider implements CodeActionProvider, IWorkbenchContribution { +export class SurroundWithSnippetCodeActionProvider implements CodeActionProvider, IWorkbenchContribution { private static readonly _MAX_CODE_ACTIONS = 4; @@ -160,6 +157,3 @@ class SurroundWithSnippetCodeActionProvider implements CodeActionProvider, IWork }; } } - -registerAction2(SurroundWithSnippetEditorAction); -Registry.as(WorkbenchExtensions.Workbench).registerWorkbenchContribution(SurroundWithSnippetCodeActionProvider, LifecyclePhase.Restored); diff --git a/src/vs/workbench/contrib/snippets/browser/snippetCompletionProvider.ts b/src/vs/workbench/contrib/snippets/browser/snippetCompletionProvider.ts index 7e8c6555e5c72..6569bf2ce1f82 100644 --- a/src/vs/workbench/contrib/snippets/browser/snippetCompletionProvider.ts +++ b/src/vs/workbench/contrib/snippets/browser/snippetCompletionProvider.ts @@ -12,7 +12,7 @@ import { CompletionItem, CompletionItemKind, CompletionItemProvider, CompletionL import { ILanguageService } from 'vs/editor/common/languages/language'; import { SnippetParser } from 'vs/editor/contrib/snippet/browser/snippetParser'; import { localize } from 'vs/nls'; -import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets.contribution'; +import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets'; import { Snippet, SnippetSource } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; import { isPatternInWord } from 'vs/base/common/filters'; import { StopWatch } from 'vs/base/common/stopwatch'; diff --git a/src/vs/workbench/contrib/snippets/browser/snippetPicker.ts b/src/vs/workbench/contrib/snippets/browser/snippetPicker.ts index 0814ea32312c0..0f72c05ab5014 100644 --- a/src/vs/workbench/contrib/snippets/browser/snippetPicker.ts +++ b/src/vs/workbench/contrib/snippets/browser/snippetPicker.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as nls from 'vs/nls'; -import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets.contribution'; +import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets'; import { Snippet, SnippetSource } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; import { IQuickPickItem, IQuickInputService, QuickPickInput } from 'vs/platform/quickinput/common/quickInput'; import { Codicon } from 'vs/base/common/codicons'; diff --git a/src/vs/workbench/contrib/snippets/browser/snippets.contribution.ts b/src/vs/workbench/contrib/snippets/browser/snippets.contribution.ts index ac1e213fc5595..39f0c8233c5dc 100644 --- a/src/vs/workbench/contrib/snippets/browser/snippets.contribution.ts +++ b/src/vs/workbench/contrib/snippets/browser/snippets.contribution.ts @@ -4,38 +4,37 @@ *--------------------------------------------------------------------------------------------*/ import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema'; -import { Registry } from 'vs/platform/registry/common/platform'; -import * as JSONContributionRegistry from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; import * as nls from 'vs/nls'; -import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; -import { SnippetFile, Snippet } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; - -export const ISnippetsService = createDecorator('snippetService'); - -export interface ISnippetGetOptions { - includeDisabledSnippets?: boolean; - includeNoPrefixSnippets?: boolean; - noRecencySort?: boolean; - topLevelSnippets?: boolean; -} - -export interface ISnippetsService { - - readonly _serviceBrand: undefined; - - getSnippetFiles(): Promise>; - - isEnabled(snippet: Snippet): boolean; - - updateEnablement(snippet: Snippet, enabled: boolean): void; - - updateUsageTimestamp(snippet: Snippet): void; - - getSnippets(languageId: string | undefined, opt?: ISnippetGetOptions): Promise; - - getSnippetsSync(languageId: string, opt?: ISnippetGetOptions): Snippet[]; -} - +import { registerAction2 } from 'vs/platform/actions/common/actions'; +import { CommandsRegistry } from 'vs/platform/commands/common/commands'; +import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; +import * as JSONContributionRegistry from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; +import { Registry } from 'vs/platform/registry/common/platform'; +import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; +import { ConfigureSnippets } from 'vs/workbench/contrib/snippets/browser/commands/configureSnippets'; +import { SelectSnippetForEmptyFile } from 'vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets'; +import { InsertSnippetAction } from 'vs/workbench/contrib/snippets/browser/commands/insertSnippet'; +import { SurroundWithSnippetCodeActionProvider, SurroundWithSnippetEditorAction } from 'vs/workbench/contrib/snippets/browser/commands/surroundWithSnippet'; +import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets'; +import { SnippetsService } from 'vs/workbench/contrib/snippets/browser/snippetsService'; +import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; + +import 'vs/workbench/contrib/snippets/browser/tabCompletion'; + +// service +registerSingleton(ISnippetsService, SnippetsService, true); + +// actions +registerAction2(InsertSnippetAction); +CommandsRegistry.registerCommandAlias('editor.action.showSnippets', 'editor.action.insertSnippet'); +registerAction2(SurroundWithSnippetEditorAction); +registerAction2(ConfigureSnippets); +registerAction2(SelectSnippetForEmptyFile); + +// workbench contribs +Registry.as(WorkbenchExtensions.Workbench).registerWorkbenchContribution(SurroundWithSnippetCodeActionProvider, LifecyclePhase.Restored); + +// schema const languageScopeSchemaId = 'vscode://schemas/snippets'; const snippetSchemaProperties: IJSONSchemaMap = { @@ -45,7 +44,7 @@ const snippetSchemaProperties: IJSONSchemaMap = { }, isTopLevel: { description: nls.localize('snippetSchema.json.isTopLevel', 'The snippet is only applicable to empty files.'), - type: 'string' + type: 'boolean' }, body: { markdownDescription: nls.localize('snippetSchema.json.body', 'The snippet content. Use `$1`, `${1:defaultText}` to define cursor positions, use `$0` for the final cursor position. Insert variable values with `${varName}` and `${varName:defaultText}`, e.g. `This is file: $TM_FILENAME`.'), diff --git a/src/vs/workbench/contrib/snippets/browser/snippets.ts b/src/vs/workbench/contrib/snippets/browser/snippets.ts new file mode 100644 index 0000000000000..fa485ab0f2fb7 --- /dev/null +++ b/src/vs/workbench/contrib/snippets/browser/snippets.ts @@ -0,0 +1,33 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; +import { SnippetFile, Snippet } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; + +export const ISnippetsService = createDecorator('snippetService'); + +export interface ISnippetGetOptions { + includeDisabledSnippets?: boolean; + includeNoPrefixSnippets?: boolean; + noRecencySort?: boolean; + topLevelSnippets?: boolean; +} + +export interface ISnippetsService { + + readonly _serviceBrand: undefined; + + getSnippetFiles(): Promise>; + + isEnabled(snippet: Snippet): boolean; + + updateEnablement(snippet: Snippet, enabled: boolean): void; + + updateUsageTimestamp(snippet: Snippet): void; + + getSnippets(languageId: string | undefined, opt?: ISnippetGetOptions): Promise; + + getSnippetsSync(languageId: string, opt?: ISnippetGetOptions): Snippet[]; +} diff --git a/src/vs/workbench/contrib/snippets/browser/snippetsService.ts b/src/vs/workbench/contrib/snippets/browser/snippetsService.ts index 918411b564c74..3c5ed85f665c3 100644 --- a/src/vs/workbench/contrib/snippets/browser/snippetsService.ts +++ b/src/vs/workbench/contrib/snippets/browser/snippetsService.ts @@ -14,11 +14,10 @@ import { setSnippetSuggestSupport } from 'vs/editor/contrib/suggest/browser/sugg import { localize } from 'vs/nls'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { FileChangeType, IFileService } from 'vs/platform/files/common/files'; -import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { ILifecycleService, LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; import { ILogService } from 'vs/platform/log/common/log'; import { IWorkspace, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; -import { ISnippetGetOptions, ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets.contribution'; +import { ISnippetGetOptions, ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets'; import { Snippet, SnippetFile, SnippetSource } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; import { ExtensionsRegistry, IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry'; import { languagesExtPoint } from 'vs/workbench/services/language/common/languageService'; @@ -204,7 +203,7 @@ class SnippetUsageTimestamps { } } -class SnippetsService implements ISnippetsService { +export class SnippetsService implements ISnippetsService { declare readonly _serviceBrand: undefined; @@ -504,7 +503,6 @@ class SnippetsService implements ISnippetsService { } } -registerSingleton(ISnippetsService, SnippetsService, true); export interface ISimpleModel { getLineContent(lineNumber: number): string; diff --git a/src/vs/workbench/contrib/snippets/browser/tabCompletion.ts b/src/vs/workbench/contrib/snippets/browser/tabCompletion.ts index 1f4afaa0a94b2..0abc197abeb44 100644 --- a/src/vs/workbench/contrib/snippets/browser/tabCompletion.ts +++ b/src/vs/workbench/contrib/snippets/browser/tabCompletion.ts @@ -6,7 +6,7 @@ import { KeyCode } from 'vs/base/common/keyCodes'; import { RawContextKey, IContextKeyService, ContextKeyExpr, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; -import { ISnippetsService } from './snippets.contribution'; +import { ISnippetsService } from './snippets'; import { getNonWhitespacePrefix } from './snippetsService'; import { IDisposable } from 'vs/base/common/lifecycle'; import { IEditorContribution } from 'vs/editor/common/editorCommon'; diff --git a/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts b/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts index 14485ae11a71d..a414f31246d3e 100644 --- a/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts +++ b/src/vs/workbench/contrib/snippets/test/browser/snippetsService.test.ts @@ -7,7 +7,7 @@ import * as assert from 'assert'; import { SnippetCompletion, SnippetCompletionProvider } from 'vs/workbench/contrib/snippets/browser/snippetCompletionProvider'; import { Position } from 'vs/editor/common/core/position'; import { createModelServices, instantiateTextModel } from 'vs/editor/test/common/testTextModel'; -import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets.contribution'; +import { ISnippetsService } from "vs/workbench/contrib/snippets/browser/snippets"; import { Snippet, SnippetSource } from 'vs/workbench/contrib/snippets/browser/snippetsFile'; import { CompletionContext, CompletionItemLabel, CompletionItemRanges, CompletionTriggerKind } from 'vs/editor/common/languages'; import { DisposableStore } from 'vs/base/common/lifecycle'; diff --git a/src/vs/workbench/workbench.common.main.ts b/src/vs/workbench/workbench.common.main.ts index f3deec51ef412..3a6eb7416ffad 100644 --- a/src/vs/workbench/workbench.common.main.ts +++ b/src/vs/workbench/workbench.common.main.ts @@ -264,11 +264,6 @@ import 'vs/workbench/contrib/keybindings/browser/keybindings.contribution'; // Snippets import 'vs/workbench/contrib/snippets/browser/snippets.contribution'; -import 'vs/workbench/contrib/snippets/browser/snippetsService'; -import 'vs/workbench/contrib/snippets/browser/insertSnippet'; -import 'vs/workbench/contrib/snippets/browser/surroundWithSnippet'; -import 'vs/workbench/contrib/snippets/browser/configureSnippets'; -import 'vs/workbench/contrib/snippets/browser/tabCompletion'; // Formatter Help import 'vs/workbench/contrib/format/browser/format.contribution'; From c17e5712b654f3d11510b2fcc0dc43c83d8ebf29 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Fri, 15 Jul 2022 14:24:40 +0200 Subject: [PATCH 087/121] Add syntax highlighting for .env files without extensions (#155298) Add syntax highlighting for .env files without extensions. Fixes #154111 --- extensions/ini/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/ini/package.json b/extensions/ini/package.json index 324e4c87f6e63..aa98ee3a353a1 100644 --- a/extensions/ini/package.json +++ b/extensions/ini/package.json @@ -37,7 +37,8 @@ ".editorconfig" ], "filenames": [ - "gitconfig" + "gitconfig", + ".env" ], "filenamePatterns": [ "**/.config/git/config", From 3f3e62b1f323b6dfe8d6c539b42137720718ea51 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 15 Jul 2022 08:14:48 +0200 Subject: [PATCH 088/121] rename `TitleBarContext` to `TitleBarTitleContext` because that's what it is --- src/vs/platform/actions/common/actions.ts | 2 +- src/vs/workbench/browser/parts/titlebar/titlebarPart.ts | 6 +++--- src/vs/workbench/electron-sandbox/window.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index cbf2991ee7c8f..fa8516d57008a 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -108,7 +108,7 @@ export class MenuId { static readonly TestPeekElement = new MenuId('TestPeekElement'); static readonly TestPeekTitle = new MenuId('TestPeekTitle'); static readonly TouchBarContext = new MenuId('TouchBarContext'); - static readonly TitleBarContext = new MenuId('TitleBarContext'); + static readonly TitleBarTitleContext = new MenuId('TitleBarTitleContext'); static readonly TunnelContext = new MenuId('TunnelContext'); static readonly TunnelPrivacy = new MenuId('TunnelPrivacy'); static readonly TunnelProtocol = new MenuId('TunnelProtocol'); diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index 17b5eb918bb95..a46890b498460 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -82,7 +82,7 @@ export class TitlebarPart extends Part implements ITitleService { private readonly windowTitle: WindowTitle; - private readonly contextMenu: IMenu; + private readonly titleContextMenu: IMenu; constructor( @IContextMenuService private readonly contextMenuService: IContextMenuService, @@ -99,7 +99,7 @@ export class TitlebarPart extends Part implements ITitleService { ) { super(Parts.TITLEBAR_PART, { hasTitle: false }, themeService, storageService, layoutService); this.windowTitle = this._register(instantiationService.createInstance(WindowTitle)); - this.contextMenu = this._register(menuService.createMenu(MenuId.TitleBarContext, contextKeyService)); + this.titleContextMenu = this._register(menuService.createMenu(MenuId.TitleBarTitleContext, contextKeyService)); this.titleBarStyle = getTitleBarStyle(this.configurationService); @@ -387,7 +387,7 @@ export class TitlebarPart extends Part implements ITitleService { // Fill in contributed actions const actions: IAction[] = []; - const actionsDisposable = createAndFillInContextMenuActions(this.contextMenu, undefined, actions); + const actionsDisposable = createAndFillInContextMenuActions(this.titleContextMenu, undefined, actions); // Show it this.contextMenuService.showContextMenu({ diff --git a/src/vs/workbench/electron-sandbox/window.ts b/src/vs/workbench/electron-sandbox/window.ts index af2e33d72d202..1c685df8bfb62 100644 --- a/src/vs/workbench/electron-sandbox/window.ts +++ b/src/vs/workbench/electron-sandbox/window.ts @@ -603,7 +603,7 @@ export class NativeWindow extends Disposable { const commandId = `workbench.action.revealPathInFinder${i}`; this.customTitleContextMenuDisposable.add(CommandsRegistry.registerCommand(commandId, () => this.nativeHostService.showItemInFolder(path.fsPath))); - this.customTitleContextMenuDisposable.add(MenuRegistry.appendMenuItem(MenuId.TitleBarContext, { command: { id: commandId, title: label || posix.sep }, order: -i })); + this.customTitleContextMenuDisposable.add(MenuRegistry.appendMenuItem(MenuId.TitleBarTitleContext, { command: { id: commandId, title: label || posix.sep }, order: -i })); } } From e3b4651e7d12dea522c64525c10c25e0e6cf0ac7 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 15 Jul 2022 17:24:41 +0200 Subject: [PATCH 089/121] tweak label --- .../contrib/snippets/browser/commands/emptyFileSnippets.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets.ts b/src/vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets.ts index 85376e61a7010..739cb837dfaf3 100644 --- a/src/vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets.ts +++ b/src/vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets.ts @@ -22,8 +22,8 @@ export class SelectSnippetForEmptyFile extends SnippetsAction { super({ id: 'workbench.action.populateFromSnippet', title: { - value: localize('label', 'Populate File from Snippet'), - original: 'Populate File from Snippet' + value: localize('label', 'Populate from Snippet'), + original: 'Populate from Snippet' }, f1: true, }); From db779036aaa9055b65a2cd58669d7f31fb9b4f4c Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 15 Jul 2022 08:36:17 +0200 Subject: [PATCH 090/121] add context menu to hide/show CC and layout controls --- src/vs/platform/actions/common/actions.ts | 1 + .../browser/parts/titlebar/titlebarPart.ts | 85 ++++++++++--------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index fa8516d57008a..a11e1185e92ec 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -108,6 +108,7 @@ export class MenuId { static readonly TestPeekElement = new MenuId('TestPeekElement'); static readonly TestPeekTitle = new MenuId('TestPeekTitle'); static readonly TouchBarContext = new MenuId('TouchBarContext'); + static readonly TitleBarContext = new MenuId('TitleBarContext'); static readonly TitleBarTitleContext = new MenuId('TitleBarTitleContext'); static readonly TunnelContext = new MenuId('TunnelContext'); static readonly TunnelPrivacy = new MenuId('TunnelPrivacy'); diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index a46890b498460..0a26e1ceb24a4 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -11,7 +11,7 @@ import { getZoomFactor } from 'vs/base/browser/browser'; import { MenuBarVisibility, getTitleBarStyle, getMenuBarVisibility } from 'vs/platform/window/common/window'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { StandardMouseEvent } from 'vs/base/browser/mouseEvent'; -import { IAction, toAction } from 'vs/base/common/actions'; +import { IAction } from 'vs/base/common/actions'; import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration'; import { DisposableStore, dispose } from 'vs/base/common/lifecycle'; import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService'; @@ -21,13 +21,13 @@ import { isMacintosh, isWindows, isLinux, isWeb } from 'vs/base/common/platform' import { Color } from 'vs/base/common/color'; import { EventType, EventHelper, Dimension, isAncestor, append, $, addDisposableListener, runAtThisOrScheduleAtNextAnimationFrame, prepend, reset } from 'vs/base/browser/dom'; import { CustomMenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl'; -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { Emitter, Event } from 'vs/base/common/event'; import { IStorageService } from 'vs/platform/storage/common/storage'; import { Parts, IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService'; import { createActionViewItem, createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem'; -import { IMenuService, IMenu, MenuId } from 'vs/platform/actions/common/actions'; -import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { Action2, IMenuService, MenuId, registerAction2 } from 'vs/platform/actions/common/actions'; +import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IHostService } from 'vs/workbench/services/host/browser/host'; import { Codicon } from 'vs/base/common/codicons'; import { getIconRegistry } from 'vs/platform/theme/common/iconRegistry'; @@ -82,8 +82,6 @@ export class TitlebarPart extends Part implements ITitleService { private readonly windowTitle: WindowTitle; - private readonly titleContextMenu: IMenu; - constructor( @IContextMenuService private readonly contextMenuService: IContextMenuService, @IConfigurationService protected readonly configurationService: IConfigurationService, @@ -99,7 +97,6 @@ export class TitlebarPart extends Part implements ITitleService { ) { super(Parts.TITLEBAR_PART, { hasTitle: false }, themeService, storageService, layoutService); this.windowTitle = this._register(instantiationService.createInstance(WindowTitle)); - this.titleContextMenu = this._register(menuService.createMenu(MenuId.TitleBarTitleContext, contextKeyService)); this.titleBarStyle = getTitleBarStyle(this.configurationService); @@ -276,13 +273,6 @@ export class TitlebarPart extends Part implements ITitleService { allowContextMenu: true }); - this._register(addDisposableListener(this.layoutControls, EventType.CONTEXT_MENU, e => { - EventHelper.stop(e); - - this.onLayoutControlContextMenu(e, this.layoutControls!); - })); - - const menu = this._register(this.menuService.createMenu(MenuId.LayoutControlMenu, this.contextKeyService)); const updateLayoutMenu = () => { if (!this.layoutToolbar) { @@ -305,11 +295,10 @@ export class TitlebarPart extends Part implements ITitleService { // Context menu on title [EventType.CONTEXT_MENU, EventType.MOUSE_DOWN].forEach(event => { - this._register(addDisposableListener(this.title, event, e => { + this._register(addDisposableListener(this.rootContainer, event, e => { if (e.type === EventType.CONTEXT_MENU || e.metaKey) { EventHelper.stop(e); - - this.onContextMenu(e); + this.onContextMenu(e, e.target === this.title ? MenuId.TitleBarTitleContext : MenuId.TitleBarContext); } })); }); @@ -380,42 +369,23 @@ export class TitlebarPart extends Part implements ITitleService { } } - private onContextMenu(e: MouseEvent): void { + private onContextMenu(e: MouseEvent, menuId: MenuId): void { // Find target anchor const event = new StandardMouseEvent(e); const anchor = { x: event.posx, y: event.posy }; // Fill in contributed actions + const menu = this.menuService.createMenu(menuId, this.contextKeyService); const actions: IAction[] = []; - const actionsDisposable = createAndFillInContextMenuActions(this.titleContextMenu, undefined, actions); - - // Show it - this.contextMenuService.showContextMenu({ - getAnchor: () => anchor, - getActions: () => actions, - onHide: () => dispose(actionsDisposable) - }); - } - - private onLayoutControlContextMenu(e: MouseEvent, el: HTMLElement): void { - // Find target anchor - const event = new StandardMouseEvent(e); - const anchor = { x: event.posx, y: event.posy }; - - const actions: IAction[] = []; - actions.push(toAction({ - id: 'layoutControl.hide', - label: localize('layoutControl.hide', "Hide Layout Control"), - run: () => { - this.configurationService.updateValue('workbench.layoutControl.enabled', false); - } - })); + const actionsDisposable = createAndFillInContextMenuActions(menu, undefined, actions); + menu.dispose(); // Show it this.contextMenuService.showContextMenu({ getAnchor: () => anchor, getActions: () => actions, - domForShadowRoot: el + onHide: () => dispose(actionsDisposable), + domForShadowRoot: event.target }); } @@ -499,3 +469,34 @@ registerThemingParticipant((theme, collector) => { `); } }); + + +class ToogleConfigAction extends Action2 { + + constructor(private readonly section: string, title: string, order: number) { + super({ + id: `toggle.${section}`, + title, + toggled: ContextKeyExpr.equals(`config.${section}`, true), + menu: { id: MenuId.TitleBarContext, order } + }); + } + + run(accessor: ServicesAccessor, ...args: any[]): void { + const configService = accessor.get(IConfigurationService); + const value = configService.getValue(this.section); + configService.updateValue(this.section, !value); + } +} + +registerAction2(class ToogleCommandCenter extends ToogleConfigAction { + constructor() { + super('window.commandCenter', localize('toggle.commandCenter', 'Show Command Center'), 1); + } +}); + +registerAction2(class ToogleLayoutControl extends ToogleConfigAction { + constructor() { + super('workbench.layoutControl.enabled', localize('toggle.layout', 'Show Layout Controls'), 1); + } +}); From 0b734bfebe18966552b24e23d2110dd4e76e4a2c Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 15 Jul 2022 18:05:41 +0200 Subject: [PATCH 091/121] add "start with snippet" to empty editor text, change things to use formatted text renderer (fixes https://github.com/microsoft/vscode/issues/155293) --- src/vs/base/browser/formattedTextRenderer.ts | 2 +- .../browser/untitledTextEditorHint.ts | 106 ++++++++---------- .../browser/commands/emptyFileSnippets.ts | 4 +- 3 files changed, 53 insertions(+), 59 deletions(-) diff --git a/src/vs/base/browser/formattedTextRenderer.ts b/src/vs/base/browser/formattedTextRenderer.ts index daef833851a05..2ae545682cdca 100644 --- a/src/vs/base/browser/formattedTextRenderer.ts +++ b/src/vs/base/browser/formattedTextRenderer.ts @@ -8,7 +8,7 @@ import { IMouseEvent } from 'vs/base/browser/mouseEvent'; import { DisposableStore } from 'vs/base/common/lifecycle'; export interface IContentActionHandler { - callback: (content: string, event?: IMouseEvent) => void; + callback: (content: string, event: IMouseEvent) => void; readonly disposables: DisposableStore; } diff --git a/src/vs/workbench/contrib/codeEditor/browser/untitledTextEditorHint.ts b/src/vs/workbench/contrib/codeEditor/browser/untitledTextEditorHint.ts index 14c97806e0929..bac3e7535193d 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/untitledTextEditorHint.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/untitledTextEditorHint.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as dom from 'vs/base/browser/dom'; -import { dispose, IDisposable } from 'vs/base/common/lifecycle'; +import { DisposableStore, dispose, IDisposable } from 'vs/base/common/lifecycle'; import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser'; import { localize } from 'vs/nls'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; @@ -17,9 +17,10 @@ import { Schemas } from 'vs/base/common/network'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { ConfigurationChangedEvent, EditorOption } from 'vs/editor/common/config/editorOptions'; import { registerEditorContribution } from 'vs/editor/browser/editorExtensions'; -import { EventType as GestureEventType, Gesture } from 'vs/base/browser/touch'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; +import { IContentActionHandler, renderFormattedText } from 'vs/base/browser/formattedTextRenderer'; +import { SelectSnippetForEmptyFile } from 'vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets'; const $ = dom.$; @@ -70,7 +71,7 @@ class UntitledTextEditorHintContentWidget implements IContentWidget { private static readonly ID = 'editor.widget.untitledHint'; private domNode: HTMLElement | undefined; - private toDispose: IDisposable[]; + private toDispose: DisposableStore; constructor( private readonly editor: ICodeEditor, @@ -79,9 +80,9 @@ class UntitledTextEditorHintContentWidget implements IContentWidget { private readonly configurationService: IConfigurationService, private readonly keybindingService: IKeybindingService, ) { - this.toDispose = []; - this.toDispose.push(editor.onDidChangeModelContent(() => this.onDidChangeModelContent())); - this.toDispose.push(this.editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => { + this.toDispose = new DisposableStore(); + this.toDispose.add(editor.onDidChangeModelContent(() => this.onDidChangeModelContent())); + this.toDispose.add(this.editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => { if (this.domNode && e.hasChanged(EditorOption.fontInfo)) { this.editor.applyFontInfo(this.domNode); } @@ -107,49 +108,43 @@ class UntitledTextEditorHintContentWidget implements IContentWidget { this.domNode = $('.untitled-hint'); this.domNode.style.width = 'max-content'; - const language = $('a.language-mode'); - language.style.cursor = 'pointer'; - language.innerText = localize('selectAlanguage2', "Select a language"); - const languageKeyBinding = this.keybindingService.lookupKeybinding(ChangeLanguageAction.ID); - const languageKeybindingLabel = languageKeyBinding?.getLabel(); - if (languageKeybindingLabel) { - language.title = localize('keyboardBindingTooltip', "{0}", languageKeybindingLabel); - } - this.domNode.appendChild(language); - - const or = $('span'); - or.innerText = localize('or', " or ",); - this.domNode.appendChild(or); - - const editorType = $('a.editor-type'); - editorType.style.cursor = 'pointer'; - editorType.innerText = localize('openADifferentEditor', "open a different editor"); - const selectEditorTypeKeyBinding = this.keybindingService.lookupKeybinding('welcome.showNewFileEntries'); - const selectEditorTypeKeybindingLabel = selectEditorTypeKeyBinding?.getLabel(); - if (selectEditorTypeKeybindingLabel) { - editorType.title = localize('keyboardBindingTooltip', "{0}", selectEditorTypeKeybindingLabel); - } - this.domNode.appendChild(editorType); - - const toGetStarted = $('span'); - toGetStarted.innerText = localize('toGetStarted', " to get started."); - this.domNode.appendChild(toGetStarted); - - this.domNode.appendChild($('br')); - - const startTyping = $('span'); - startTyping.innerText = localize('startTyping', "Start typing to dismiss or "); - this.domNode.appendChild(startTyping); + const hintMsg = localize({ key: 'message', comment: ['Presereve double-square brackets and their order'] }, '[[Select a language]], [[start with a snippet]], or [[open a different editor]] to get started.\nStart typing to dismiss or [[don\'t show]] this again.'); + const hintHandler: IContentActionHandler = { + disposables: this.toDispose, + callback: (index, event) => { + switch (index) { + case '0': + languageOnClickOrTap(event.browserEvent); + break; + case '1': + snippetOnClickOrTab(event.browserEvent); + break; + case '2': + chooseEditorOnClickOrTap(event.browserEvent); + break; + case '3': + dontShowOnClickOrTap(); + break; + } + } + }; - const dontShow = $('a'); - dontShow.style.cursor = 'pointer'; - dontShow.innerText = localize('dontshow', "don't show"); - this.domNode.appendChild(dontShow); + const hintElement = renderFormattedText(hintMsg, { + actionHandler: hintHandler, + renderCodeSegments: false, + }); + this.domNode.append(hintElement); + + // ugly way to associate keybindings... + const keybindingsLookup = [ChangeLanguageAction.ID, SelectSnippetForEmptyFile.Id, 'welcome.showNewFileEntries']; + for (const anchor of hintElement.querySelectorAll('A')) { + (anchor).style.cursor = 'pointer'; + const id = keybindingsLookup.shift(); + const title = id && this.keybindingService.lookupKeybinding(id)?.getLabel(); + (anchor).title = title ?? ''; + } - const thisAgain = $('span'); - thisAgain.innerText = localize('thisAgain', " this again."); - this.domNode.appendChild(thisAgain); - this.toDispose.push(Gesture.addTarget(this.domNode)); + // the actual command handlers... const languageOnClickOrTap = async (e: MouseEvent) => { e.stopPropagation(); // Need to focus editor before so current editor becomes active and the command is properly executed @@ -157,9 +152,12 @@ class UntitledTextEditorHintContentWidget implements IContentWidget { await this.commandService.executeCommand(ChangeLanguageAction.ID, { from: 'hint' }); this.editor.focus(); }; - this.toDispose.push(dom.addDisposableListener(language, 'click', languageOnClickOrTap)); - this.toDispose.push(dom.addDisposableListener(language, GestureEventType.Tap, languageOnClickOrTap)); - this.toDispose.push(Gesture.addTarget(language)); + + const snippetOnClickOrTab = async (e: MouseEvent) => { + e.stopPropagation(); + this.editor.focus(); + this.commandService.executeCommand(SelectSnippetForEmptyFile.Id, { from: 'hint' }); + }; const chooseEditorOnClickOrTap = async (e: MouseEvent) => { e.stopPropagation(); @@ -172,20 +170,14 @@ class UntitledTextEditorHintContentWidget implements IContentWidget { this.editorGroupsService.activeGroup.closeEditor(activeEditorInput, { preserveFocus: true }); } }; - this.toDispose.push(dom.addDisposableListener(editorType, 'click', chooseEditorOnClickOrTap)); - this.toDispose.push(dom.addDisposableListener(editorType, GestureEventType.Tap, chooseEditorOnClickOrTap)); - this.toDispose.push(Gesture.addTarget(editorType)); const dontShowOnClickOrTap = () => { this.configurationService.updateValue(untitledTextEditorHintSetting, 'hidden'); this.dispose(); this.editor.focus(); }; - this.toDispose.push(dom.addDisposableListener(dontShow, 'click', dontShowOnClickOrTap)); - this.toDispose.push(dom.addDisposableListener(dontShow, GestureEventType.Tap, dontShowOnClickOrTap)); - this.toDispose.push(Gesture.addTarget(dontShow)); - this.toDispose.push(dom.addDisposableListener(this.domNode, 'click', () => { + this.toDispose.add(dom.addDisposableListener(this.domNode, 'click', () => { this.editor.focus(); })); diff --git a/src/vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets.ts b/src/vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets.ts index 739cb837dfaf3..963c92e60cb7b 100644 --- a/src/vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets.ts +++ b/src/vs/workbench/contrib/snippets/browser/commands/emptyFileSnippets.ts @@ -18,9 +18,11 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic export class SelectSnippetForEmptyFile extends SnippetsAction { + static readonly Id = 'workbench.action.populateFromSnippet'; + constructor() { super({ - id: 'workbench.action.populateFromSnippet', + id: SelectSnippetForEmptyFile.Id, title: { value: localize('label', 'Populate from Snippet'), original: 'Populate from Snippet' From 0c82754e088d14ef71f4602768dea4ac508b6b37 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 15 Jul 2022 08:42:01 +0200 Subject: [PATCH 092/121] fix order --- src/vs/workbench/browser/parts/titlebar/titlebarPart.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index 0a26e1ceb24a4..6eedbc0896388 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -497,6 +497,6 @@ registerAction2(class ToogleCommandCenter extends ToogleConfigAction { registerAction2(class ToogleLayoutControl extends ToogleConfigAction { constructor() { - super('workbench.layoutControl.enabled', localize('toggle.layout', 'Show Layout Controls'), 1); + super('workbench.layoutControl.enabled', localize('toggle.layout', 'Show Layout Controls'), 2); } }); From 74636a9b223e9157a8cc495cd01d5182b2f0402f Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Fri, 15 Jul 2022 15:53:07 +0200 Subject: [PATCH 093/121] Commit Button - Fix issue related to button opacity when button is disabled (#155301) Fix issue related to button opacity when button is disabled --- src/vs/base/browser/ui/button/button.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vs/base/browser/ui/button/button.css b/src/vs/base/browser/ui/button/button.css index cade1d85c64dd..f5c80d0918427 100644 --- a/src/vs/base/browser/ui/button/button.css +++ b/src/vs/base/browser/ui/button/button.css @@ -46,7 +46,9 @@ outline-offset: -1px !important; } -.monaco-button-dropdown.disabled .monaco-button-dropdown-separator { +.monaco-button-dropdown.disabled > .monaco-button.disabled, +.monaco-button-dropdown.disabled > .monaco-button.disabled:focus, +.monaco-button-dropdown.disabled > .monaco-button-dropdown-separator { opacity: 0.4; } From a112981898417cd32466a10389fdff048c7f6a17 Mon Sep 17 00:00:00 2001 From: SteVen Batten Date: Fri, 15 Jul 2022 14:29:26 -0700 Subject: [PATCH 094/121] system context menu on Windows --- src/vs/platform/native/common/native.ts | 2 ++ .../electron-main/nativeHostMainService.ts | 1 + .../platform/window/electron-main/window.ts | 1 + .../platform/windows/electron-main/window.ts | 19 +++++++++++++++++++ .../platform/windows/electron-main/windows.ts | 1 + .../electron-main/windowsMainService.ts | 4 ++++ .../test/electron-main/windowsFinder.test.ts | 1 + .../browser/actions/layoutActions.ts | 3 +++ .../parts/titlebar/media/titlebarpart.css | 2 +- .../browser/parts/titlebar/titlebarPart.ts | 6 +++--- .../parts/titlebar/titlebarPart.ts | 15 ++++++++++++++- .../electron-browser/workbenchTestServices.ts | 1 + 12 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/vs/platform/native/common/native.ts b/src/vs/platform/native/common/native.ts index 5698299eb3c72..569f00ad4f984 100644 --- a/src/vs/platform/native/common/native.ts +++ b/src/vs/platform/native/common/native.ts @@ -55,6 +55,8 @@ export interface ICommonNativeHostService { readonly onDidChangePassword: Event<{ service: string; account: string }>; + readonly onDidTriggerSystemContextMenu: Event<{ windowId: number; x: number; y: number }>; + // Window getWindows(): Promise; getWindowCount(): Promise; diff --git a/src/vs/platform/native/electron-main/nativeHostMainService.ts b/src/vs/platform/native/electron-main/nativeHostMainService.ts index 3cfca90776697..9eb4bca8be91e 100644 --- a/src/vs/platform/native/electron-main/nativeHostMainService.ts +++ b/src/vs/platform/native/electron-main/nativeHostMainService.ts @@ -74,6 +74,7 @@ export class NativeHostMainService extends Disposable implements INativeHostMain //#region Events readonly onDidOpenWindow = Event.map(this.windowsMainService.onDidOpenWindow, window => window.id); + readonly onDidTriggerSystemContextMenu = Event.filter(Event.map(this.windowsMainService.onDidTriggerSystemContextMenu, ({ window, x, y }) => { return { windowId: window.id, x, y }; }), ({ windowId }) => !!this.windowsMainService.getWindowById(windowId)); readonly onDidMaximizeWindow = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-maximize', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId)); readonly onDidUnmaximizeWindow = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-unmaximize', (event, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId)); diff --git a/src/vs/platform/window/electron-main/window.ts b/src/vs/platform/window/electron-main/window.ts index e6f0513a76db9..0f80ee0390382 100644 --- a/src/vs/platform/window/electron-main/window.ts +++ b/src/vs/platform/window/electron-main/window.ts @@ -17,6 +17,7 @@ export interface ICodeWindow extends IDisposable { readonly onWillLoad: Event; readonly onDidSignalReady: Event; + readonly onDidTriggerSystemContextMenu: Event<{ x: number; y: number }>; readonly onDidClose: Event; readonly onDidDestroy: Event; diff --git a/src/vs/platform/windows/electron-main/window.ts b/src/vs/platform/windows/electron-main/window.ts index 216d743026fa9..4812c641e22f1 100644 --- a/src/vs/platform/windows/electron-main/window.ts +++ b/src/vs/platform/windows/electron-main/window.ts @@ -90,6 +90,9 @@ export class CodeWindow extends Disposable implements ICodeWindow { private readonly _onDidSignalReady = this._register(new Emitter()); readonly onDidSignalReady = this._onDidSignalReady.event; + private readonly _onDidTriggerSystemContextMenu = this._register(new Emitter<{ x: number; y: number }>()); + readonly onDidTriggerSystemContextMenu = this._onDidTriggerSystemContextMenu.event; + private readonly _onDidClose = this._register(new Emitter()); readonly onDidClose = this._onDidClose.event; @@ -286,6 +289,22 @@ export class CodeWindow extends Disposable implements ICodeWindow { this._win.setSheetOffset(22); // offset dialogs by the height of the custom title bar if we have any } + // Windows Custom System Context Menu + // See https://github.com/electron/electron/issues/24893 + if (isWindows && useCustomTitleStyle) { + const WM_INITMENU = 0x0116; + this._win.hookWindowMessage(WM_INITMENU, () => { + const [x, y] = this._win.getPosition(); + const cursorPos = screen.getCursorScreenPoint(); + + this._win.setEnabled(false); + this._win.setEnabled(true); + + this._onDidTriggerSystemContextMenu.fire({ x: cursorPos.x - x, y: cursorPos.y - y }); + return 0; // skip native menu + }); + } + // TODO@electron (Electron 4 regression): when running on multiple displays where the target display // to open the window has a larger resolution than the primary display, the window will not size // correctly unless we set the bounds again (https://github.com/microsoft/vscode/issues/74872) diff --git a/src/vs/platform/windows/electron-main/windows.ts b/src/vs/platform/windows/electron-main/windows.ts index 36f847959e0e9..dda572f4120be 100644 --- a/src/vs/platform/windows/electron-main/windows.ts +++ b/src/vs/platform/windows/electron-main/windows.ts @@ -22,6 +22,7 @@ export interface IWindowsMainService { readonly onDidOpenWindow: Event; readonly onDidSignalReadyWindow: Event; + readonly onDidTriggerSystemContextMenu: Event<{ window: ICodeWindow; x: number; y: number }>; readonly onDidDestroyWindow: Event; open(openConfig: IOpenConfiguration): ICodeWindow[]; diff --git a/src/vs/platform/windows/electron-main/windowsMainService.ts b/src/vs/platform/windows/electron-main/windowsMainService.ts index af32788dce5fa..51c83544e3464 100644 --- a/src/vs/platform/windows/electron-main/windowsMainService.ts +++ b/src/vs/platform/windows/electron-main/windowsMainService.ts @@ -187,6 +187,9 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic private readonly _onDidChangeWindowsCount = this._register(new Emitter()); readonly onDidChangeWindowsCount = this._onDidChangeWindowsCount.event; + private readonly _onDidTriggerSystemContextMenu = this._register(new Emitter<{ window: ICodeWindow; x: number; y: number }>()); + readonly onDidTriggerSystemContextMenu = this._onDidTriggerSystemContextMenu.event; + private readonly windowsStateHandler = this._register(new WindowsStateHandler(this, this.stateMainService, this.lifecycleMainService, this.logService, this.configurationService)); constructor( @@ -1379,6 +1382,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic once(createdWindow.onDidSignalReady)(() => this._onDidSignalReadyWindow.fire(createdWindow)); once(createdWindow.onDidClose)(() => this.onWindowClosed(createdWindow)); once(createdWindow.onDidDestroy)(() => this._onDidDestroyWindow.fire(createdWindow)); + createdWindow.onDidTriggerSystemContextMenu(({ x, y }) => this._onDidTriggerSystemContextMenu.fire({ window: createdWindow, x, y })); const webContents = assertIsDefined(createdWindow.win?.webContents); webContents.removeAllListeners('devtools-reload-page'); // remove built in listener so we can handle this on our own diff --git a/src/vs/platform/windows/test/electron-main/windowsFinder.test.ts b/src/vs/platform/windows/test/electron-main/windowsFinder.test.ts index 827801bf89132..3fba62c1b4d1a 100644 --- a/src/vs/platform/windows/test/electron-main/windowsFinder.test.ts +++ b/src/vs/platform/windows/test/electron-main/windowsFinder.test.ts @@ -34,6 +34,7 @@ suite('WindowsFinder', () => { function createTestCodeWindow(options: { lastFocusTime: number; openedFolderUri?: URI; openedWorkspace?: IWorkspaceIdentifier }): ICodeWindow { return new class implements ICodeWindow { onWillLoad: Event = Event.None; + onDidTriggerSystemContextMenu: Event<{ x: number; y: number }> = Event.None; onDidSignalReady: Event = Event.None; onDidClose: Event = Event.None; onDidDestroy: Event = Event.None; diff --git a/src/vs/workbench/browser/actions/layoutActions.ts b/src/vs/workbench/browser/actions/layoutActions.ts index 9bf977172a887..f32ff09736cf9 100644 --- a/src/vs/workbench/browser/actions/layoutActions.ts +++ b/src/vs/workbench/browser/actions/layoutActions.ts @@ -583,6 +583,9 @@ if (isWindows || isLinux || isWeb) { id: MenuId.MenubarAppearanceMenu, group: '2_workbench_layout', order: 0 + }, { + id: MenuId.TitleBarContext, + order: 0 }] }); } diff --git a/src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css b/src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css index 9b4d5aada91bc..5f3f76d376db8 100644 --- a/src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css +++ b/src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css @@ -191,7 +191,7 @@ width: 35px; height: 100%; position: relative; - z-index: 3000; + z-index: 2500; flex-shrink: 0; } diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index 6eedbc0896388..a3f2972bd4bc6 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -17,7 +17,7 @@ import { DisposableStore, dispose } from 'vs/base/common/lifecycle'; import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService'; import { IThemeService, registerThemingParticipant, ThemeIcon } from 'vs/platform/theme/common/themeService'; import { TITLE_BAR_ACTIVE_BACKGROUND, TITLE_BAR_ACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_BACKGROUND, TITLE_BAR_BORDER, WORKBENCH_BACKGROUND } from 'vs/workbench/common/theme'; -import { isMacintosh, isWindows, isLinux, isWeb } from 'vs/base/common/platform'; +import { isMacintosh, isWindows, isLinux, isWeb, isNative } from 'vs/base/common/platform'; import { Color } from 'vs/base/common/color'; import { EventType, EventHelper, Dimension, isAncestor, append, $, addDisposableListener, runAtThisOrScheduleAtNextAnimationFrame, prepend, reset } from 'vs/base/browser/dom'; import { CustomMenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl'; @@ -369,7 +369,7 @@ export class TitlebarPart extends Part implements ITitleService { } } - private onContextMenu(e: MouseEvent, menuId: MenuId): void { + protected onContextMenu(e: MouseEvent, menuId: MenuId): void { // Find target anchor const event = new StandardMouseEvent(e); const anchor = { x: event.posx, y: event.posy }; @@ -385,7 +385,7 @@ export class TitlebarPart extends Part implements ITitleService { getAnchor: () => anchor, getActions: () => actions, onHide: () => dispose(actionsDisposable), - domForShadowRoot: event.target + domForShadowRoot: isMacintosh && isNative ? event.target : undefined }); } diff --git a/src/vs/workbench/electron-sandbox/parts/titlebar/titlebarPart.ts b/src/vs/workbench/electron-sandbox/parts/titlebar/titlebarPart.ts index 7e3dd0559f3d8..18eff4547bbbf 100644 --- a/src/vs/workbench/electron-sandbox/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/electron-sandbox/parts/titlebar/titlebarPart.ts @@ -11,7 +11,7 @@ import { IStorageService } from 'vs/platform/storage/common/storage'; import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/environmentService'; import { IHostService } from 'vs/workbench/services/host/browser/host'; import { isMacintosh, isWindows, isLinux } from 'vs/base/common/platform'; -import { IMenuService } from 'vs/platform/actions/common/actions'; +import { IMenuService, MenuId } from 'vs/platform/actions/common/actions'; import { TitlebarPart as BrowserTitleBarPart } from 'vs/workbench/browser/parts/titlebar/titlebarPart'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { IThemeService } from 'vs/platform/theme/common/themeService'; @@ -195,6 +195,19 @@ export class TitlebarPart extends BrowserTitleBarPart { this._register(this.layoutService.onDidChangeWindowMaximized(maximized => this.onDidChangeWindowMaximized(maximized))); this.onDidChangeWindowMaximized(this.layoutService.isWindowMaximized()); + + // Window System Context Menu + // See https://github.com/electron/electron/issues/24893 + if (isWindows) { + this._register(this.nativeHostService.onDidTriggerSystemContextMenu(({ windowId, x, y }) => { + if (this.nativeHostService.windowId !== windowId) { + return; + } + + const zoomFactor = getZoomFactor(); + this.onContextMenu(new MouseEvent('mouseup', { clientX: x / zoomFactor, clientY: y / zoomFactor }), MenuId.TitleBarContext); + })); + } } return ret; diff --git a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts index f4fce1346e21b..16a83da3eacae 100644 --- a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts @@ -205,6 +205,7 @@ export class TestNativeHostService implements INativeHostService { onDidResumeOS: Event = Event.None; onDidChangeColorScheme = Event.None; onDidChangePassword = Event.None; + onDidTriggerSystemContextMenu: Event<{ windowId: number; x: number; y: number }> = Event.None; onDidChangeDisplay = Event.None; windowCount = Promise.resolve(1); From 8810fa7c1f86cfbf6afe5be47bbdbc4a3f662b24 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Fri, 15 Jul 2022 08:08:13 -0700 Subject: [PATCH 095/121] set to udf after (#155304) --- src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts index 0499c4cd0b599..22c53792466fd 100644 --- a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts @@ -882,6 +882,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { watchingProblemMatcher.aboutToStart(); let delayer: Async.Delayer | undefined = undefined; [terminal, error] = this._terminalForTask ? [this._terminalForTask, undefined] : await this._createTerminal(task, resolver, workspaceFolder); + this._terminalForTask = undefined; if (error) { return Promise.reject(new Error((error).message)); @@ -964,6 +965,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { }); } else { [terminal, error] = this._terminalForTask ? [this._terminalForTask, undefined] : await this._createTerminal(task, resolver, workspaceFolder); + this._terminalForTask = undefined; if (error) { return Promise.reject(new Error((error).message)); From c54d15c5081b21cf7f48d52e027e5f56b404df93 Mon Sep 17 00:00:00 2001 From: SteVen Batten Date: Fri, 15 Jul 2022 14:40:27 -0700 Subject: [PATCH 096/121] formatting --- src/vs/workbench/browser/actions/layoutActions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/browser/actions/layoutActions.ts b/src/vs/workbench/browser/actions/layoutActions.ts index f32ff09736cf9..3890ccfb5ba48 100644 --- a/src/vs/workbench/browser/actions/layoutActions.ts +++ b/src/vs/workbench/browser/actions/layoutActions.ts @@ -584,8 +584,8 @@ if (isWindows || isLinux || isWeb) { group: '2_workbench_layout', order: 0 }, { - id: MenuId.TitleBarContext, - order: 0 + id: MenuId.TitleBarContext, + order: 0 }] }); } From c54be2fda2ee9aac9ff27b280ec592cac818cb9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Fri, 15 Jul 2022 17:27:02 +0200 Subject: [PATCH 097/121] dom: h should allow ids and multiple class names (#155311) --- src/vs/base/browser/dom.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts index 4d08566a4f615..2e8651879ef77 100644 --- a/src/vs/base/browser/dom.ts +++ b/src/vs/base/browser/dom.ts @@ -1788,10 +1788,21 @@ export function h(tag: string, ...args: [] | [attributes: { $: string } & DomNod children = args[1]; } - const [tagName, className] = tag.split('.'); + const match = SELECTOR_REGEX.exec(tag); + + if (!match) { + throw new Error('Bad use of h'); + } + + const tagName = match[1] || 'div'; const el = document.createElement(tagName); - if (className) { - el.className = className; + + if (match[3]) { + el.id = match[3]; + } + + if (match[4]) { + el.className = match[4].replace(/\./g, ' ').trim(); } const result: Record = {}; From d771fbb9f501ee8bf301f26bce674d7a937af619 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Fri, 15 Jul 2022 18:15:12 +0200 Subject: [PATCH 098/121] Fixes #155179 by implementing DeprecatedExtensionMigratorContribution (#155318) * Fixes #155179 by implementing DeprecatedExtensionMigratorContribution * Fixes CI. --- build/lib/i18n.resources.json | 4 + ...eprecatedExtensionMigrator.contribution.ts | 103 ++++++++++++++++++ src/vs/workbench/workbench.common.main.ts | 3 + 3 files changed, 110 insertions(+) create mode 100644 src/vs/workbench/contrib/deprecatedExtensionMigrator/browser/deprecatedExtensionMigrator.contribution.ts diff --git a/build/lib/i18n.resources.json b/build/lib/i18n.resources.json index 2ab4a471fb6bc..7fa1a6519a722 100644 --- a/build/lib/i18n.resources.json +++ b/build/lib/i18n.resources.json @@ -294,6 +294,10 @@ "name": "vs/workbench/contrib/audioCues", "project": "vscode-workbench" }, + { + "name": "vs/workbench/contrib/deprecatedExtensionMigrator", + "project": "vscode-workbench" + }, { "name": "vs/workbench/contrib/offline", "project": "vscode-workbench" diff --git a/src/vs/workbench/contrib/deprecatedExtensionMigrator/browser/deprecatedExtensionMigrator.contribution.ts b/src/vs/workbench/contrib/deprecatedExtensionMigrator/browser/deprecatedExtensionMigrator.contribution.ts new file mode 100644 index 0000000000000..3abb2f55315fe --- /dev/null +++ b/src/vs/workbench/contrib/deprecatedExtensionMigrator/browser/deprecatedExtensionMigrator.contribution.ts @@ -0,0 +1,103 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { Action } from 'vs/base/common/actions'; +import { onUnexpectedError } from 'vs/base/common/errors'; +import { isDefined } from 'vs/base/common/types'; +import { localize } from 'vs/nls'; +import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; +import { IOpenerService } from 'vs/platform/opener/common/opener'; +import { Registry } from 'vs/platform/registry/common/platform'; +import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; +import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; +import { IExtensionsWorkbenchService } from 'vs/workbench/contrib/extensions/common/extensions'; +import { EnablementState } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; +import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; + +class DeprecatedExtensionMigratorContribution { + constructor( + @IConfigurationService private readonly configurationService: IConfigurationService, + @IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService, + @IStorageService private readonly storageService: IStorageService, + @INotificationService private readonly notificationService: INotificationService, + @IOpenerService private readonly openerService: IOpenerService + ) { + this.init().catch(onUnexpectedError); + } + + private async init(): Promise { + const bracketPairColorizerId = 'coenraads.bracket-pair-colorizer'; + + await this.extensionsWorkbenchService.queryLocal(); + const extension = this.extensionsWorkbenchService.installed.find(e => e.identifier.id === bracketPairColorizerId); + if ( + !extension || + ((extension.enablementState !== EnablementState.EnabledGlobally) && + (extension.enablementState !== EnablementState.EnabledWorkspace)) + ) { + return; + } + + const state = await this.getState(); + const disablementLogEntry = state.disablementLog.some(d => d.extensionId === bracketPairColorizerId); + + if (disablementLogEntry) { + return; + } + + state.disablementLog.push({ extensionId: bracketPairColorizerId, disablementDateTime: new Date().getTime() }); + await this.setState(state); + + await this.extensionsWorkbenchService.setEnablement(extension, EnablementState.DisabledGlobally); + + const nativeBracketPairColorizationEnabledKey = 'editor.bracketPairColorization.enabled'; + const bracketPairColorizationEnabled = !!this.configurationService.inspect(nativeBracketPairColorizationEnabledKey).user; + + this.notificationService.notify({ + message: localize('bracketPairColorizer.notification', "The extension 'Bracket pair Colorizer' got disabled because it was deprecated."), + severity: Severity.Info, + actions: { + primary: [ + new Action('', localize('bracketPairColorizer.notification.action.uninstall', "Uninstall Extension"), undefined, undefined, () => { + this.extensionsWorkbenchService.uninstall(extension); + }), + ], + secondary: [ + !bracketPairColorizationEnabled ? new Action('', localize('bracketPairColorizer.notification.action.enableNative', "Enable Native Bracket Pair Colorization"), undefined, undefined, () => { + this.configurationService.updateValue(nativeBracketPairColorizationEnabledKey, true, ConfigurationTarget.USER); + }) : undefined, + new Action('', localize('bracketPairColorizer.notification.action.showMoreInfo', "More Info"), undefined, undefined, () => { + this.openerService.open('https://github.com/microsoft/vscode/issues/155179'); + }), + ].filter(isDefined), + } + }); + } + + private readonly storageKey = 'deprecatedExtensionMigrator.state'; + + private async getState(): Promise { + const jsonStr = await this.storageService.get(this.storageKey, StorageScope.APPLICATION, ''); + if (jsonStr === '') { + return { disablementLog: [] }; + } + return JSON.parse(jsonStr) as State; + } + + private async setState(state: State): Promise { + const json = JSON.stringify(state); + await this.storageService.store(this.storageKey, json, StorageScope.APPLICATION, StorageTarget.USER); + } +} + +interface State { + disablementLog: { + extensionId: string; + disablementDateTime: number; + }[]; +} + +Registry.as(WorkbenchExtensions.Workbench).registerWorkbenchContribution(DeprecatedExtensionMigratorContribution, LifecyclePhase.Restored); diff --git a/src/vs/workbench/workbench.common.main.ts b/src/vs/workbench/workbench.common.main.ts index f3deec51ef412..5c4f5d8715abe 100644 --- a/src/vs/workbench/workbench.common.main.ts +++ b/src/vs/workbench/workbench.common.main.ts @@ -349,4 +349,7 @@ import 'vs/workbench/contrib/list/browser/list.contribution'; // Audio Cues import 'vs/workbench/contrib/audioCues/browser/audioCues.contribution'; +// Deprecated Extension Migrator +import 'vs/workbench/contrib/deprecatedExtensionMigrator/browser/deprecatedExtensionMigrator.contribution'; + //#endregion From 88d3f85eb518ec9a5b0b83aeaf4851154ff3b0d5 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Fri, 15 Jul 2022 18:16:32 +0200 Subject: [PATCH 099/121] A11y bug: OS color settings are not respected (#155319) A11y bug: OS color settings are not respected. Fixes #155243 --- src/vs/platform/theme/electron-main/themeMainService.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vs/platform/theme/electron-main/themeMainService.ts b/src/vs/platform/theme/electron-main/themeMainService.ts index cd212ea11dac1..caa1e0b6f45f9 100644 --- a/src/vs/platform/theme/electron-main/themeMainService.ts +++ b/src/vs/platform/theme/electron-main/themeMainService.ts @@ -64,8 +64,7 @@ export class ThemeMainService extends Disposable implements IThemeMainService { } else if (isMacintosh) { // high contrast is set if one of shouldUseInvertedColorScheme or shouldUseHighContrastColors is set, reflecting the 'Invert colours' and `Increase contrast` settings in MacOS if (nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors) { - // when the colors are inverted, negate shouldUseDarkColors - return { dark: nativeTheme.shouldUseDarkColors !== nativeTheme.shouldUseInvertedColorScheme, highContrast: true }; + return { dark: nativeTheme.shouldUseDarkColors, highContrast: true }; } } else if (isLinux) { // ubuntu gnome seems to have 3 states, light dark and high contrast From c7b7d2b7a71fc0b83839f00b3074b10543c45887 Mon Sep 17 00:00:00 2001 From: Andrea Mah <31675041+andreamah@users.noreply.github.com> Date: Fri, 15 Jul 2022 09:52:17 -0700 Subject: [PATCH 100/121] Add "Go to Last Failed Cell" Button (#154443) * Add go to last failed cell function --- .../browser/controller/executeActions.ts | 52 ++++++++++++++++++- .../browser/media/notebookToolbar.css | 4 ++ .../notebookExecutionStateServiceImpl.ts | 36 +++++++++++-- .../notebookEditorWidgetContextKeys.ts | 13 ++++- .../notebook/common/notebookContextKeys.ts | 1 + .../common/notebookExecutionStateService.ts | 6 +++ .../test/browser/testNotebookEditor.ts | 8 ++- 7 files changed, 111 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts b/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts index 3e54598b92b52..7b190d89c14e2 100644 --- a/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts +++ b/src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts @@ -15,7 +15,7 @@ import { ThemeIcon } from 'vs/platform/theme/common/themeService'; import { EditorsOrder } from 'vs/workbench/common/editor'; import { insertCell } from 'vs/workbench/contrib/notebook/browser/controller/cellOperations'; import { cellExecutionArgs, CellToolbarOrder, CELL_TITLE_CELL_GROUP_ID, executeNotebookCondition, getContextFromActiveEditor, getContextFromUri, INotebookActionContext, INotebookCellActionContext, INotebookCellToolbarActionContext, INotebookCommandContext, NotebookAction, NotebookCellAction, NotebookMultiCellAction, NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT, parseMultiCellExecutionArgs } from 'vs/workbench/contrib/notebook/browser/controller/coreActions'; -import { NOTEBOOK_CELL_EXECUTING, NOTEBOOK_CELL_EXECUTION_STATE, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_TYPE, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_KERNEL_SOURCE_COUNT, NOTEBOOK_MISSING_KERNEL_EXTENSION } from 'vs/workbench/contrib/notebook/common/notebookContextKeys'; +import { NOTEBOOK_CELL_EXECUTING, NOTEBOOK_CELL_EXECUTION_STATE, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_TYPE, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_KERNEL_SOURCE_COUNT, NOTEBOOK_LAST_CELL_FAILED, NOTEBOOK_MISSING_KERNEL_EXTENSION } from 'vs/workbench/contrib/notebook/common/notebookContextKeys'; import { CellEditState, CellFocusMode, EXECUTE_CELL_COMMAND_ID } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; import * as icons from 'vs/workbench/contrib/notebook/browser/notebookIcons'; import { CellKind, NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon'; @@ -35,6 +35,7 @@ const EXECUTE_CELL_AND_BELOW = 'notebook.cell.executeCellAndBelow'; const EXECUTE_CELLS_ABOVE = 'notebook.cell.executeCellsAbove'; const RENDER_ALL_MARKDOWN_CELLS = 'notebook.renderAllMarkdownCells'; const REVEAL_RUNNING_CELL = 'notebook.revealRunningCell'; +const REVEAL_LAST_FAILED_CELL = 'notebook.revealLastFailedCell'; // If this changes, update getCodeCellExecutionContextKeyService to match export const executeCondition = ContextKeyExpr.and( @@ -594,3 +595,52 @@ registerAction2(class RevealRunningCellAction extends NotebookAction { } } }); + +registerAction2(class RevealLastFailedCellAction extends NotebookAction { + constructor() { + super({ + id: REVEAL_LAST_FAILED_CELL, + title: localize('revealLastFailedCell', "Go to Most Recently Failed Cell"), + tooltip: localize('revealLastFailedCell', "Go to Most Recently Failed Cell"), + shortTitle: localize('revealLastFailedCellShort', "Go To"), + precondition: NOTEBOOK_LAST_CELL_FAILED, + menu: [ + { + id: MenuId.EditorTitle, + when: ContextKeyExpr.and( + NOTEBOOK_IS_ACTIVE_EDITOR, + NOTEBOOK_LAST_CELL_FAILED, + NOTEBOOK_HAS_RUNNING_CELL.toNegated(), + ContextKeyExpr.notEquals('config.notebook.globalToolbar', true) + ), + group: 'navigation', + order: 0 + }, + { + id: MenuId.NotebookToolbar, + when: ContextKeyExpr.and( + NOTEBOOK_IS_ACTIVE_EDITOR, + NOTEBOOK_LAST_CELL_FAILED, + NOTEBOOK_HAS_RUNNING_CELL.toNegated(), + ContextKeyExpr.equals('config.notebook.globalToolbar', true) + ), + group: 'navigation/execute', + order: 0 + }, + ], + icon: icons.errorStateIcon, + }); + } + + async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext): Promise { + const notebookExecutionStateService = accessor.get(INotebookExecutionStateService); + const notebook = context.notebookEditor.textModel.uri; + const lastFailedCellHandle = notebookExecutionStateService.getLastFailedCellForNotebook(notebook); + if (lastFailedCellHandle !== undefined) { + const lastFailedCell = context.notebookEditor.getCellByHandle(lastFailedCellHandle); + if (lastFailedCell) { + context.notebookEditor.focusNotebookCell(lastFailedCell, 'container'); + } + } + } +}); diff --git a/src/vs/workbench/contrib/notebook/browser/media/notebookToolbar.css b/src/vs/workbench/contrib/notebook/browser/media/notebookToolbar.css index 4b61bafdfd84e..f7ddb6665a70a 100644 --- a/src/vs/workbench/contrib/notebook/browser/media/notebookToolbar.css +++ b/src/vs/workbench/contrib/notebook/browser/media/notebookToolbar.css @@ -80,3 +80,7 @@ .monaco-workbench .notebookOverlay .notebook-toolbar-container .monaco-action-bar:not(.vertical) .action-item.active { background-color: unset; } + +.monaco-workbench .notebookOverlay .notebook-toolbar-container .monaco-action-bar .action-item .codicon-notebook-state-error { + color: var(--notebook-cell-status-icon-error); +} diff --git a/src/vs/workbench/contrib/notebook/browser/notebookExecutionStateServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/notebookExecutionStateServiceImpl.ts index e32dbce7ba8f8..0cf3e56c598ef 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookExecutionStateServiceImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookExecutionStateServiceImpl.ts @@ -13,7 +13,7 @@ import { ILogService } from 'vs/platform/log/common/log'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; import { CellEditType, CellUri, ICellEditOperation, NotebookCellExecutionState, NotebookCellInternalMetadata, NotebookTextModelWillAddRemoveEvent } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { CellExecutionUpdateType, INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/notebookExecutionService'; -import { ICellExecuteUpdate, ICellExecutionComplete, ICellExecutionStateChangedEvent, ICellExecutionStateUpdate, INotebookCellExecution, INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; +import { ICellExecuteUpdate, ICellExecutionComplete, ICellExecutionStateChangedEvent, ICellExecutionStateUpdate, INotebookCellExecution, INotebookExecutionStateService, INotebookFailStateChangedEvent } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService'; export class NotebookExecutionStateService extends Disposable implements INotebookExecutionStateService { @@ -22,10 +22,14 @@ export class NotebookExecutionStateService extends Disposable implements INotebo private readonly _executions = new ResourceMap>(); private readonly _notebookListeners = new ResourceMap(); private readonly _cellListeners = new ResourceMap(); + private readonly _lastFailedCells = new ResourceMap(); private readonly _onDidChangeCellExecution = this._register(new Emitter()); onDidChangeCellExecution = this._onDidChangeCellExecution.event; + private readonly _onDidChangeLastRunFailState = this._register(new Emitter()); + onDidChangeLastRunFailState = this._onDidChangeLastRunFailState.event; + constructor( @IInstantiationService private readonly _instantiationService: IInstantiationService, @ILogService private readonly _logService: ILogService, @@ -34,6 +38,10 @@ export class NotebookExecutionStateService extends Disposable implements INotebo super(); } + getLastFailedCellForNotebook(notebook: URI): number | undefined { + return this._lastFailedCells.get(notebook); + } + forceCancelNotebookExecutions(notebookUri: URI): void { const notebookExecutions = this._executions.get(notebookUri); if (!notebookExecutions) { @@ -68,7 +76,7 @@ export class NotebookExecutionStateService extends Disposable implements INotebo this._onDidChangeCellExecution.fire(new NotebookExecutionEvent(notebookUri, cellHandle, exe)); } - private _onCellExecutionDidComplete(notebookUri: URI, cellHandle: number, exe: CellExecution): void { + private _onCellExecutionDidComplete(notebookUri: URI, cellHandle: number, exe: CellExecution, lastRunSuccess?: boolean): void { const notebookExecutions = this._executions.get(notebookUri); if (!notebookExecutions) { this._logService.debug(`NotebookExecutionStateService#_onCellExecutionDidComplete - unknown notebook ${notebookUri.toString()}`); @@ -86,6 +94,14 @@ export class NotebookExecutionStateService extends Disposable implements INotebo this._notebookListeners.delete(notebookUri); } + if (lastRunSuccess !== undefined) { + if (lastRunSuccess) { + this._clearLastFailedCell(notebookUri); + } else { + this._setLastFailedCell(notebookUri, cellHandle); + } + } + this._onDidChangeCellExecution.fire(new NotebookExecutionEvent(notebookUri, cellHandle)); } @@ -119,12 +135,22 @@ export class NotebookExecutionStateService extends Disposable implements INotebo const exe: CellExecution = this._instantiationService.createInstance(CellExecution, cellHandle, notebook); const disposable = combinedDisposable( exe.onDidUpdate(() => this._onCellExecutionDidChange(notebookUri, cellHandle, exe)), - exe.onDidComplete(() => this._onCellExecutionDidComplete(notebookUri, cellHandle, exe))); + exe.onDidComplete(lastRunSuccess => this._onCellExecutionDidComplete(notebookUri, cellHandle, exe, lastRunSuccess))); this._cellListeners.set(CellUri.generate(notebookUri, cellHandle), disposable); return exe; } + private _setLastFailedCell(notebook: URI, cellHandle: number) { + this._lastFailedCells.set(notebook, cellHandle); + this._onDidChangeLastRunFailState.fire({ failed: true, notebook }); + } + + private _clearLastFailedCell(notebook: URI) { + this._lastFailedCells.delete(notebook); + this._onDidChangeLastRunFailState.fire({ failed: false, notebook: notebook }); + } + override dispose(): void { super.dispose(); this._executions.forEach(executionMap => { @@ -250,7 +276,7 @@ class CellExecution extends Disposable implements INotebookCellExecution { private readonly _onDidUpdate = this._register(new Emitter()); readonly onDidUpdate = this._onDidUpdate.event; - private readonly _onDidComplete = this._register(new Emitter()); + private readonly _onDidComplete = this._register(new Emitter()); readonly onDidComplete = this._onDidComplete.event; private _state: NotebookCellExecutionState = NotebookCellExecutionState.Unconfirmed; @@ -350,7 +376,7 @@ class CellExecution extends Disposable implements INotebookCellExecution { this._applyExecutionEdits([edit]); } - this._onDidComplete.fire(); + this._onDidComplete.fire(completionData.lastRunSuccess); } private _applyExecutionEdits(edits: ICellEditOperation[]): void { diff --git a/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.ts b/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.ts index 3702ac26261f5..27384f830d49d 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.ts @@ -6,8 +6,8 @@ import { DisposableStore, dispose, IDisposable } from 'vs/base/common/lifecycle'; import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { ICellViewModel, INotebookEditorDelegate, KERNEL_EXTENSIONS } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; -import { NOTEBOOK_CELL_TOOLBAR_LOCATION, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_KERNEL, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_KERNEL_SELECTED, NOTEBOOK_KERNEL_SOURCE_COUNT, NOTEBOOK_MISSING_KERNEL_EXTENSION, NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON, NOTEBOOK_VIEW_TYPE } from 'vs/workbench/contrib/notebook/common/notebookContextKeys'; -import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; +import { NOTEBOOK_CELL_TOOLBAR_LOCATION, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_KERNEL, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_KERNEL_SELECTED, NOTEBOOK_KERNEL_SOURCE_COUNT, NOTEBOOK_LAST_CELL_FAILED, NOTEBOOK_MISSING_KERNEL_EXTENSION, NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON, NOTEBOOK_VIEW_TYPE } from 'vs/workbench/contrib/notebook/common/notebookContextKeys'; +import { INotebookExecutionStateService, INotebookFailStateChangedEvent } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; @@ -24,6 +24,7 @@ export class NotebookEditorContextKeys { private readonly _viewType!: IContextKey; private readonly _missingKernelExtension: IContextKey; private readonly _cellToolbarLocation: IContextKey<'left' | 'right' | 'hidden'>; + private readonly _lastCellFailed: IContextKey; private readonly _disposables = new DisposableStore(); private readonly _viewModelDisposables = new DisposableStore(); @@ -47,6 +48,7 @@ export class NotebookEditorContextKeys { this._missingKernelExtension = NOTEBOOK_MISSING_KERNEL_EXTENSION.bindTo(contextKeyService); this._notebookKernelSourceCount = NOTEBOOK_KERNEL_SOURCE_COUNT.bindTo(contextKeyService); this._cellToolbarLocation = NOTEBOOK_CELL_TOOLBAR_LOCATION.bindTo(contextKeyService); + this._lastCellFailed = NOTEBOOK_LAST_CELL_FAILED.bindTo(contextKeyService); this._handleDidChangeModel(); this._updateForNotebookOptions(); @@ -58,6 +60,7 @@ export class NotebookEditorContextKeys { this._disposables.add(_editor.notebookOptions.onDidChangeOptions(this._updateForNotebookOptions, this)); this._disposables.add(_extensionService.onDidChangeExtensions(this._updateForInstalledExtension, this)); this._disposables.add(_notebookExecutionStateService.onDidChangeCellExecution(this._updateForCellExecution, this)); + this._disposables.add(_notebookExecutionStateService.onDidChangeLastRunFailState(this._updateForLastRunFailState, this)); } dispose(): void { @@ -132,6 +135,12 @@ export class NotebookEditorContextKeys { } } + private _updateForLastRunFailState(e: INotebookFailStateChangedEvent): void { + if (e.notebook === this._editor.textModel?.uri) { + this._lastCellFailed.set(e.failed); + } + } + private async _updateForInstalledExtension(): Promise { if (!this._editor.hasModel()) { return; diff --git a/src/vs/workbench/contrib/notebook/common/notebookContextKeys.ts b/src/vs/workbench/contrib/notebook/common/notebookContextKeys.ts index e629ed034d26b..fd9692eba0f4f 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookContextKeys.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookContextKeys.ts @@ -24,6 +24,7 @@ export const NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON = new RawContextKey('notebookBreakpointMargin', false); export const NOTEBOOK_CELL_TOOLBAR_LOCATION = new RawContextKey<'left' | 'right' | 'hidden'>('notebookCellToolbarLocation', 'left'); export const NOTEBOOK_CURSOR_NAVIGATION_MODE = new RawContextKey('notebookCursorNavigationMode', false); +export const NOTEBOOK_LAST_CELL_FAILED = new RawContextKey('notebookLastCellFailed', false); // Cell keys export const NOTEBOOK_VIEW_TYPE = new RawContextKey('notebookType', undefined); diff --git a/src/vs/workbench/contrib/notebook/common/notebookExecutionStateService.ts b/src/vs/workbench/contrib/notebook/common/notebookExecutionStateService.ts index f6317245bb18e..d1fbe75907f49 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookExecutionStateService.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookExecutionStateService.ts @@ -39,6 +39,10 @@ export interface ICellExecutionStateChangedEvent { affectsCell(cell: URI): boolean; affectsNotebook(notebook: URI): boolean; } +export interface INotebookFailStateChangedEvent { + failed: boolean; + notebook: URI; +} export const INotebookExecutionStateService = createDecorator('INotebookExecutionStateService'); @@ -46,11 +50,13 @@ export interface INotebookExecutionStateService { _serviceBrand: undefined; onDidChangeCellExecution: Event; + onDidChangeLastRunFailState: Event; forceCancelNotebookExecutions(notebookUri: URI): void; getCellExecutionStatesForNotebook(notebook: URI): INotebookCellExecution[]; getCellExecution(cellUri: URI): INotebookCellExecution | undefined; createCellExecution(notebook: URI, cellHandle: number): INotebookCellExecution; + getLastFailedCellForNotebook(notebook: URI): number | undefined; } export interface INotebookCellExecution { diff --git a/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts b/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts index 8570bf9146a1a..6b16b20461f1c 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts @@ -44,7 +44,7 @@ import { ViewContext } from 'vs/workbench/contrib/notebook/browser/viewModel/vie import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; import { CellKind, CellUri, INotebookDiffEditorModel, INotebookEditorModel, INotebookSearchOptions, IOutputDto, IResolvedNotebookEditorModel, NotebookCellExecutionState, NotebookCellMetadata, SelectionStateType } from 'vs/workbench/contrib/notebook/common/notebookCommon'; -import { ICellExecuteUpdate, ICellExecutionComplete, ICellExecutionStateChangedEvent, INotebookCellExecution, INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; +import { ICellExecuteUpdate, ICellExecutionComplete, ICellExecutionStateChangedEvent, INotebookCellExecution, INotebookExecutionStateService, INotebookFailStateChangedEvent } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; import { NotebookOptions } from 'vs/workbench/contrib/notebook/common/notebookOptions'; import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange'; import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService'; @@ -405,11 +405,17 @@ class TestCellExecution implements INotebookCellExecution { } class TestNotebookExecutionStateService implements INotebookExecutionStateService { + + getLastFailedCellForNotebook(notebook: URI): number | undefined { + return; + } + _serviceBrand: undefined; private _executions = new ResourceMap(); onDidChangeCellExecution = new Emitter().event; + onDidChangeLastRunFailState = new Emitter().event; forceCancelNotebookExecutions(notebookUri: URI): void { } From c7444588c90325afd2eee7d19f35383f97e5c8a3 Mon Sep 17 00:00:00 2001 From: Andrea Mah <31675041+andreamah@users.noreply.github.com> Date: Fri, 15 Jul 2022 10:25:30 -0700 Subject: [PATCH 101/121] Flexible-width Find Menu in Notebook (#154550) Fixes #141516 --- .../find/notebookFindReplaceWidget.css | 7 +- .../contrib/find/notebookFindReplaceWidget.ts | 78 ++++++++++++++++++- .../contrib/find/notebookFindWidget.ts | 4 +- 3 files changed, 82 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindReplaceWidget.css b/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindReplaceWidget.css index d9701c95197a6..52cfc8adcaccb 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindReplaceWidget.css +++ b/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindReplaceWidget.css @@ -9,9 +9,9 @@ position: absolute; top: -45px; right: 18px; - width: 318px; + width: var(--notebook-find-width); max-width: calc(100% - 28px - 28px - 8px); - pointer-events: none; + padding:0 var(--notebook-find-horizontal-padding); transition: top 200ms linear; visibility: hidden; } @@ -158,3 +158,6 @@ .monaco-workbench .simple-fr-replace-part .monaco-inputbox > .ibwrapper > .input { height: 24px; } +.monaco-workbench .simple-fr-find-part-wrapper .monaco-sash { + left: 0 !important; +} diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindReplaceWidget.ts b/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindReplaceWidget.ts index 59f060f642115..f2d0a44853c85 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindReplaceWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindReplaceWidget.ts @@ -18,7 +18,7 @@ import * as nls from 'vs/nls'; import { ContextScopedReplaceInput, registerAndCreateHistoryNavigationContext } from 'vs/platform/history/browser/contextScopedHistoryWidget'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView'; -import { editorWidgetBackground, editorWidgetForeground, inputActiveOptionBackground, inputActiveOptionBorder, inputActiveOptionForeground, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationInfoForeground, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationWarningForeground, widgetShadow } from 'vs/platform/theme/common/colorRegistry'; +import { editorWidgetBackground, editorWidgetBorder, editorWidgetForeground, editorWidgetResizeBorder, inputActiveOptionBackground, inputActiveOptionBorder, inputActiveOptionForeground, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationInfoForeground, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationWarningForeground, widgetShadow } from 'vs/platform/theme/common/colorRegistry'; import { registerIcon, widgetClose } from 'vs/platform/theme/common/iconRegistry'; import { attachProgressBarStyler } from 'vs/platform/theme/common/styler'; import { IColorTheme, IThemeService, registerThemingParticipant, ThemeIcon } from 'vs/platform/theme/common/themeService'; @@ -35,6 +35,8 @@ import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar'; import { filterIcon } from 'vs/workbench/contrib/extensions/browser/extensionsIcons'; import { NotebookFindFilters } from 'vs/workbench/contrib/notebook/browser/contrib/find/findFilters'; import { isSafari } from 'vs/base/common/platform'; +import { ISashEvent, Orientation, Sash } from 'vs/base/browser/ui/sash/sash'; +import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; const NLS_FIND_INPUT_LABEL = nls.localize('label.find', "Find"); const NLS_FIND_INPUT_PLACEHOLDER = nls.localize('placeholder.find', "Find"); @@ -55,6 +57,8 @@ const NOTEBOOK_FIND_IN_MARKUP_PREVIEW = nls.localize('notebook.find.filter.findI const NOTEBOOK_FIND_IN_CODE_INPUT = nls.localize('notebook.find.filter.findInCodeInput', "Code Cell Source"); const NOTEBOOK_FIND_IN_CODE_OUTPUT = nls.localize('notebook.find.filter.findInCodeOutput', "Cell Output"); +const NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH = 318; +const NOTEBOOK_FIND_WIDGET_INITIAL_HORIZONTAL_PADDING = 4; class NotebookFindFilterActionViewItem extends DropdownMenuActionViewItem { constructor(readonly filters: NotebookFindFilters, action: IAction, actionRunner: IActionRunner, @IContextMenuService contextMenuService: IContextMenuService) { super(action, @@ -256,6 +260,8 @@ export abstract class SimpleFindReplaceWidget extends Widget { protected _replaceBtn!: SimpleButton; protected _replaceAllBtn!: SimpleButton; + private readonly _resizeSash: Sash; + private _resizeOriginalWidth = NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH; private _isVisible: boolean = false; private _isReplaceVisible: boolean = false; @@ -274,7 +280,8 @@ export abstract class SimpleFindReplaceWidget extends Widget { @IMenuService readonly menuService: IMenuService, @IContextMenuService readonly contextMenuService: IContextMenuService, @IInstantiationService readonly instantiationService: IInstantiationService, - protected readonly _state: FindReplaceState = new FindReplaceState() + protected readonly _state: FindReplaceState = new FindReplaceState(), + protected readonly _notebookEditor: INotebookEditor, ) { super(); @@ -339,7 +346,8 @@ export abstract class SimpleFindReplaceWidget extends Widget { this.updateButtons(this.foundMatch); return { content: e.message }; } - } + }, + flexibleWidth: true, } )); @@ -474,6 +482,58 @@ export abstract class SimpleFindReplaceWidget extends Widget { this._innerReplaceDomNode.appendChild(this._replaceBtn.domNode); this._innerReplaceDomNode.appendChild(this._replaceAllBtn.domNode); + + this._resizeSash = this._register(new Sash(this._domNode, { getVerticalSashLeft: () => 0 }, { orientation: Orientation.VERTICAL, size: 2 })); + + this._register(this._resizeSash.onDidStart(() => { + this._resizeOriginalWidth = this._getDomWidth(); + })); + + this._register(this._resizeSash.onDidChange((evt: ISashEvent) => { + let width = this._resizeOriginalWidth + evt.startX - evt.currentX; + if (width < NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH) { + width = NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH; + } + + const maxWidth = this._getMaxWidth(); + if (width > maxWidth) { + width = maxWidth; + } + + this._domNode.style.width = `${width}px`; + + if (this._isReplaceVisible) { + this._replaceInput.width = dom.getTotalWidth(this._findInput.domNode); + } + + this._findInput.inputBox.layout(); + })); + + this._register(this._resizeSash.onDidReset(() => { + // users double click on the sash + // try to emulate what happens with editor findWidget + const currentWidth = this._getDomWidth(); + let width = NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH; + + if (currentWidth <= NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH) { + width = this._getMaxWidth(); + } + + this._domNode.style.width = `${width}px`; + if (this._isReplaceVisible) { + this._replaceInput.width = dom.getTotalWidth(this._findInput.domNode); + } + + this._findInput.inputBox.layout(); + })); + } + + private _getMaxWidth() { + return this._notebookEditor.getLayoutInfo().width - 64; + } + + private _getDomWidth() { + return dom.getTotalWidth(this._domNode) - (NOTEBOOK_FIND_WIDGET_INITIAL_HORIZONTAL_PADDING * 2); } getCellToolbarActions(menu: IMenu): { primary: IAction[]; secondary: IAction[] } { @@ -727,4 +787,16 @@ registerThemingParticipant((theme, collector) => { if (inputActiveOptionBackgroundColor) { collector.addRule(`.simple-fr-find-part .find-filter-button > .monaco-action-bar .action-label.notebook-filters.checked { background-color: ${inputActiveOptionBackgroundColor}; }`); } + + const resizeBorderBackground = theme.getColor(editorWidgetResizeBorder) ?? theme.getColor(editorWidgetBorder); + if (resizeBorderBackground) { + collector.addRule(`.monaco-workbench .simple-fr-find-part-wrapper .monaco-sash { background-color: ${resizeBorderBackground}; }`); + } + + collector.addRule(` + :root { + --notebook-find-width: ${NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH}px; + --notebook-find-horizontal-padding: ${NOTEBOOK_FIND_WIDGET_INITIAL_HORIZONTAL_PADDING}px; + } + `); }); diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.ts b/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.ts index c027d8137d4b8..9c38190c3423e 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.ts @@ -48,7 +48,7 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote private _findModel: FindModel; constructor( - private readonly _notebookEditor: INotebookEditor, + _notebookEditor: INotebookEditor, @IContextViewService contextViewService: IContextViewService, @IContextKeyService contextKeyService: IContextKeyService, @IThemeService themeService: IThemeService, @@ -57,7 +57,7 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote @IMenuService menuService: IMenuService, @IInstantiationService instantiationService: IInstantiationService, ) { - super(contextViewService, contextKeyService, themeService, configurationService, menuService, contextMenuService, instantiationService, new FindReplaceState()); + super(contextViewService, contextKeyService, themeService, configurationService, menuService, contextMenuService, instantiationService, new FindReplaceState(), _notebookEditor); this._findModel = new FindModel(this._notebookEditor, this._state, this._configurationService); DOM.append(this._notebookEditor.getDomNode(), this.getDomNode()); From 89ba7c4bcf91e2ad14c944f0a47d1991d9cf1e5a Mon Sep 17 00:00:00 2001 From: Jan Bicker Date: Fri, 15 Jul 2022 19:38:04 +0200 Subject: [PATCH 102/121] Fixed wrong SignatureInformation.activeParameter comment (#155279) Fixed SignatureInformation.activeParameter comment --- src/vscode-dts/vscode.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vscode-dts/vscode.d.ts b/src/vscode-dts/vscode.d.ts index 8956456447ae2..8ddc0b0377fd9 100644 --- a/src/vscode-dts/vscode.d.ts +++ b/src/vscode-dts/vscode.d.ts @@ -4037,7 +4037,7 @@ declare module 'vscode' { /** * The index of the active parameter. * - * If provided, this is used in place of {@linkcode SignatureHelp.activeSignature}. + * If provided, this is used in place of {@linkcode SignatureHelp.activeParameter}. */ activeParameter?: number; From fb8c048b8c09bfe441aa6be400af6222fb7aeef1 Mon Sep 17 00:00:00 2001 From: Miguel Solorio Date: Fri, 15 Jul 2022 10:58:09 -0700 Subject: [PATCH 103/121] Button separator color on high-contrast themes (#155316) Button separator color on high-contrast themes (Fixes #155285) --- src/vs/platform/theme/common/colorRegistry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/platform/theme/common/colorRegistry.ts b/src/vs/platform/theme/common/colorRegistry.ts index 0be76bfc597a7..411247c6bc3c0 100644 --- a/src/vs/platform/theme/common/colorRegistry.ts +++ b/src/vs/platform/theme/common/colorRegistry.ts @@ -266,7 +266,7 @@ export const checkboxForeground = registerColor('checkbox.foreground', { dark: s export const checkboxBorder = registerColor('checkbox.border', { dark: selectBorder, light: selectBorder, hcDark: selectBorder, hcLight: selectBorder }, nls.localize('checkbox.border', "Border color of checkbox widget.")); export const buttonForeground = registerColor('button.foreground', { dark: Color.white, light: Color.white, hcDark: Color.white, hcLight: Color.white }, nls.localize('buttonForeground', "Button foreground color.")); -export const buttonSeparator = registerColor('button.separator', { dark: transparent(buttonForeground, .4), light: transparent(buttonForeground, .4), hcDark: transparent(buttonForeground, .4), hcLight: transparent(buttonForeground, .4) }, nls.localize('buttonSeparator', "Button separator color.")); +export const buttonSeparator = registerColor('button.separator', { dark: transparent(buttonForeground, .4), light: transparent(buttonForeground, .4), hcDark: null, hcLight: transparent(buttonForeground, .4) }, nls.localize('buttonSeparator', "Button separator color.")); export const buttonBackground = registerColor('button.background', { dark: '#0E639C', light: '#007ACC', hcDark: null, hcLight: '#0F4A85' }, nls.localize('buttonBackground', "Button background color.")); export const buttonHoverBackground = registerColor('button.hoverBackground', { dark: lighten(buttonBackground, 0.2), light: darken(buttonBackground, 0.2), hcDark: null, hcLight: null }, nls.localize('buttonHoverBackground', "Button background color when hovering.")); export const buttonBorder = registerColor('button.border', { dark: contrastBorder, light: contrastBorder, hcDark: contrastBorder, hcLight: contrastBorder }, nls.localize('buttonBorder', "Button border color.")); From a49fc769cd3fa6512f28d8009062f246bb1df8b9 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Fri, 15 Jul 2022 14:49:16 -0400 Subject: [PATCH 104/121] Fix #155131 (#155334) * Cleanup expansion context key * Fix #155131 --- .../files/browser/views/explorerView.ts | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/vs/workbench/contrib/files/browser/views/explorerView.ts b/src/vs/workbench/contrib/files/browser/views/explorerView.ts index 6185a906efa93..a9cd6b8a8c98c 100644 --- a/src/vs/workbench/contrib/files/browser/views/explorerView.ts +++ b/src/vs/workbench/contrib/files/browser/views/explorerView.ts @@ -67,23 +67,28 @@ interface IExplorerViewStyles { listDropBackground?: Color; } -// Accepts a single or multiple workspace folders -function hasExpandedRootChild(tree: WorkbenchCompressibleAsyncDataTree, treeInput: ExplorerItem | ExplorerItem[]): boolean { - const inputsToCheck = []; - if (Array.isArray(treeInput)) { - inputsToCheck.push(...treeInput.filter(folder => tree.hasNode(folder) && !tree.isCollapsed(folder))); - } else { - inputsToCheck.push(treeInput); - } - - for (const folder of inputsToCheck) { - for (const [, child] of folder.children.entries()) { - if (tree.hasNode(child) && tree.isCollapsible(child) && !tree.isCollapsed(child)) { - return true; +function hasExpandedRootChild(tree: WorkbenchCompressibleAsyncDataTree, treeInput: ExplorerItem[]): boolean { + for (const folder of treeInput) { + if (tree.hasNode(folder) && !tree.isCollapsed(folder)) { + for (const [, child] of folder.children.entries()) { + if (tree.hasNode(child) && tree.isCollapsible(child) && !tree.isCollapsed(child)) { + return true; + } } } } + return false; +} +/** + * Whether or not any of the nodes in the tree are expanded + */ +function hasExpandedNode(tree: WorkbenchCompressibleAsyncDataTree, treeInput: ExplorerItem[]): boolean { + for (const folder of treeInput) { + if (tree.hasNode(folder) && !tree.isCollapsed(folder)) { + return true; + } + } return false; } @@ -786,15 +791,6 @@ export class ExplorerView extends ViewPane implements IExplorerView { this.tree.domFocus(); } - const treeInput = this.tree.getInput(); - if (Array.isArray(treeInput)) { - treeInput.forEach(folder => { - folder.children.forEach(child => this.tree.hasNode(child) && this.tree.expand(child, true)); - }); - - return; - } - this.tree.expandAll(); } @@ -871,7 +867,9 @@ export class ExplorerView extends ViewPane implements IExplorerView { if (treeInput === undefined) { return; } - this.viewHasSomeCollapsibleRootItem.set(hasExpandedRootChild(this.tree, treeInput)); + const treeInputArray = Array.isArray(treeInput) ? treeInput : Array.from(treeInput.children.values()); + // Has collapsible root when anything is expanded + this.viewHasSomeCollapsibleRootItem.set(hasExpandedNode(this.tree, treeInputArray)); } styleListDropBackground(styles: IExplorerViewStyles): void { From 07a8547253ea89364c5d902d78c37c24f6ba5d51 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Fri, 15 Jul 2022 15:51:51 -0700 Subject: [PATCH 105/121] Add ability to continue desktop edit session in vscode.dev --- extensions/github/package.json | 25 ++++++++++++++++++++----- extensions/github/src/commands.ts | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/extensions/github/package.json b/extensions/github/package.json index fb33fbaf3a57a..a5de87a74b765 100644 --- a/extensions/github/package.json +++ b/extensions/github/package.json @@ -26,7 +26,8 @@ } }, "enabledApiProposals": [ - "contribShareMenu" + "contribShareMenu", + "contribEditSessions" ], "contributes": { "commands": [ @@ -37,10 +38,20 @@ { "command": "github.copyVscodeDevLink", "title": "Copy vscode.dev Link" - }, - { - "command": "github.copyVscodeDevLinkFile", - "title": "Copy vscode.dev Link" + }, + { + "command": "github.copyVscodeDevLinkFile", + "title": "Copy vscode.dev Link" + }, + { + "command": "github.openOnVscodeDev", + "title": "Open on vscode.dev" + } + ], + "continueEditSession": [ + { + "command": "github.openOnVscodeDev", + "when": "github.hasGitHubRepo" } ], "menus": { @@ -56,6 +67,10 @@ { "command": "github.copyVscodeDevLinkFile", "when": "false" + }, + { + "command": "github.openOnVscodeDev", + "when": "false" } ], "file/share": [ diff --git a/extensions/github/src/commands.ts b/extensions/github/src/commands.ts index 8c68f36bfc65d..40a6927146dbc 100644 --- a/extensions/github/src/commands.ts +++ b/extensions/github/src/commands.ts @@ -20,6 +20,16 @@ async function copyVscodeDevLink(gitAPI: GitAPI, useSelection: boolean) { } } +async function openVscodeDevLink(gitAPI: GitAPI): Promise { + try { + const permalink = getPermalink(gitAPI, true, 'https://vscode.dev/github'); + return permalink ? vscode.Uri.parse(permalink) : undefined; + } catch (err) { + vscode.window.showErrorMessage(err.message); + return undefined; + } +} + export function registerCommands(gitAPI: GitAPI): vscode.Disposable { const disposables = new DisposableStore(); @@ -39,5 +49,9 @@ export function registerCommands(gitAPI: GitAPI): vscode.Disposable { return copyVscodeDevLink(gitAPI, false); })); + disposables.add(vscode.commands.registerCommand('github.openOnVscodeDev', async () => { + return openVscodeDevLink(gitAPI); + })); + return disposables; } From 42cbe989d6742d6390dcbda885f29c2318d2fd50 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Fri, 15 Jul 2022 12:17:24 -0700 Subject: [PATCH 106/121] Fix notebook perf markers (#155266) Fixes #135834 --- .../notebook/browser/notebookEditor.ts | 17 +++++---- .../notebook/browser/notebookEditorWidget.ts | 10 +++--- .../notebook/common/notebookEditorInput.ts | 6 ++-- .../notebook/common/notebookPerformance.ts | 36 ++++++------------- 4 files changed, 26 insertions(+), 43 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts index 99d1d8de1f0ce..06e09afc3a7d5 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts @@ -33,7 +33,7 @@ import { NotebooKernelActionViewItem } from 'vs/workbench/contrib/notebook/brows import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; import { NOTEBOOK_EDITOR_ID } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput'; -import { clearMarks, getAndClearMarks, mark } from 'vs/workbench/contrib/notebook/common/notebookPerformance'; +import { NotebookPerfMarks } from 'vs/workbench/contrib/notebook/common/notebookPerformance'; import { IEditorDropService } from 'vs/workbench/services/editor/browser/editorDropService'; import { GroupsOrder, IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; @@ -172,8 +172,8 @@ export class NotebookEditor extends EditorPane implements IEditorPaneWithSelecti override async setInput(input: NotebookEditorInput, options: INotebookEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken, noRetry?: boolean): Promise { try { - clearMarks(input.resource); - mark(input.resource, 'startTime'); + const perf = new NotebookPerfMarks(); + perf.mark('startTime'); const group = this.group!; this._inputListener.value = input.onDidChangeCapabilities(() => this._onDidChangeInputCapabilities(input)); @@ -203,8 +203,8 @@ export class NotebookEditor extends EditorPane implements IEditorPaneWithSelecti // only now `setInput` and yield/await. this is AFTER the actual widget is ready. This is very important // so that others synchronously receive a notebook editor with the correct widget being set await super.setInput(input, options, context, token); - const model = await input.resolve(); - mark(input.resource, 'inputLoaded'); + const model = await input.resolve(perf); + perf.mark('inputLoaded'); // Check for cancellation if (token.isCancellationRequested) { @@ -230,7 +230,7 @@ export class NotebookEditor extends EditorPane implements IEditorPaneWithSelecti const viewState = options?.viewState ?? this._loadNotebookEditorViewState(input); this._widget.value?.setParentContextKeyService(this._contextKeyService); - await this._widget.value!.setModel(model.notebook, viewState); + await this._widget.value!.setModel(model.notebook, viewState, perf); const isReadOnly = input.hasCapability(EditorInputCapabilities.Readonly); await this._widget.value!.setOptions({ ...options, isReadOnly }); this._widgetDisposableStore.add(this._widget.value!.onDidFocusWidget(() => this._onDidFocusWidget.fire())); @@ -240,7 +240,7 @@ export class NotebookEditor extends EditorPane implements IEditorPaneWithSelecti containsGroup: (group) => this.group?.id === group.id })); - mark(input.resource, 'editorLoaded'); + perf.mark('editorLoaded'); type WorkbenchNotebookOpenClassification = { owner: 'rebornix'; @@ -266,8 +266,7 @@ export class NotebookEditor extends EditorPane implements IEditorPaneWithSelecti editorLoaded: number; }; - const perfMarks = getAndClearMarks(input.resource); - + const perfMarks = perf.value; if (perfMarks) { const startTime = perfMarks['startTime']; const extensionActivated = perfMarks['extensionActivated']; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 6402451333d9c..b0dad86e9bb7c 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -77,7 +77,6 @@ import { INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/ import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService'; import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService'; import { NotebookOptions, OutputInnerContainerTopPadding } from 'vs/workbench/contrib/notebook/common/notebookOptions'; -import { mark } from 'vs/workbench/contrib/notebook/common/notebookPerformance'; import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange'; import { INotebookRendererMessagingService } from 'vs/workbench/contrib/notebook/common/notebookRendererMessagingService'; import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService'; @@ -85,6 +84,7 @@ import { editorGutterModifiedBackground } from 'vs/workbench/contrib/scm/browser import { IWebview } from 'vs/workbench/contrib/webview/browser/webview'; import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; +import { NotebookPerfMarks } from 'vs/workbench/contrib/notebook/common/notebookPerformance'; const $ = DOM.$; @@ -1080,12 +1080,12 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD this.scopedContextKeyService.updateParent(parentContextKeyService); } - async setModel(textModel: NotebookTextModel, viewState: INotebookEditorViewState | undefined): Promise { + async setModel(textModel: NotebookTextModel, viewState: INotebookEditorViewState | undefined, perf?: NotebookPerfMarks): Promise { if (this.viewModel === undefined || !this.viewModel.equal(textModel)) { const oldTopInsertToolbarHeight = this._notebookOptions.computeTopInsertToolbarHeight(this.viewModel?.viewType); const oldBottomToolbarDimensions = this._notebookOptions.computeBottomToolbarDimensions(this.viewModel?.viewType); this._detachModel(); - await this._attachModel(textModel, viewState); + await this._attachModel(textModel, viewState, perf); const newTopInsertToolbarHeight = this._notebookOptions.computeTopInsertToolbarHeight(this.viewModel?.viewType); const newBottomToolbarDimensions = this._notebookOptions.computeBottomToolbarDimensions(this.viewModel?.viewType); @@ -1389,7 +1389,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD this._list.attachWebview(this._webview.element); } - private async _attachModel(textModel: NotebookTextModel, viewState: INotebookEditorViewState | undefined) { + private async _attachModel(textModel: NotebookTextModel, viewState: INotebookEditorViewState | undefined, perf?: NotebookPerfMarks) { await this._createWebview(this.getId(), textModel.uri); this.viewModel = this.instantiationService.createInstance(NotebookViewModel, textModel.viewType, textModel, this._viewContext, this.getLayoutInfo(), { isReadOnly: this._readOnly }); this._viewContext.eventDispatcher.emit([new NotebookLayoutChangedEvent({ width: true, fontInfo: true }, this.getLayoutInfo())]); @@ -1472,7 +1472,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD // init rendering await this._warmupWithMarkdownRenderer(this.viewModel, viewState); - mark(textModel.uri, 'customMarkdownLoaded'); + perf?.mark('customMarkdownLoaded'); // model attached this._localCellStateListeners = this.viewModel.viewCells.map(cell => this._bindCellListener(cell)); diff --git a/src/vs/workbench/contrib/notebook/common/notebookEditorInput.ts b/src/vs/workbench/contrib/notebook/common/notebookEditorInput.ts index b8cbd4985d0f1..54e0ac40f5ec9 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookEditorInput.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookEditorInput.ts @@ -16,7 +16,6 @@ import { IDisposable, IReference } from 'vs/base/common/lifecycle'; import { CellEditType, IResolvedNotebookEditorModel } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { ILabelService } from 'vs/platform/label/common/label'; import { Schemas } from 'vs/base/common/network'; -import { mark } from 'vs/workbench/contrib/notebook/common/notebookPerformance'; import { FileSystemProviderCapabilities, IFileService } from 'vs/platform/files/common/files'; import { AbstractResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput'; import { IResourceEditorInput } from 'vs/platform/editor/common/editor'; @@ -24,6 +23,7 @@ import { onUnexpectedError } from 'vs/base/common/errors'; import { VSBuffer } from 'vs/base/common/buffer'; import { IWorkingCopyIdentifier } from 'vs/workbench/services/workingCopy/common/workingCopy'; import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider'; +import { NotebookPerfMarks } from 'vs/workbench/contrib/notebook/common/notebookPerformance'; export interface NotebookEditorInputOptions { startDirty?: boolean; @@ -231,12 +231,12 @@ export class NotebookEditorInput extends AbstractResourceEditorInput { } } - override async resolve(): Promise { + override async resolve(perf?: NotebookPerfMarks): Promise { if (!await this._notebookService.canResolve(this.viewType)) { return null; } - mark(this.resource, 'extensionActivated'); + perf?.mark('extensionActivated'); // we are now loading the notebook and don't need to listen to // "other" loading anymore diff --git a/src/vs/workbench/contrib/notebook/common/notebookPerformance.ts b/src/vs/workbench/contrib/notebook/common/notebookPerformance.ts index bd59c7bfbf1c6..c47b6eeeb2cef 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookPerformance.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookPerformance.ts @@ -3,39 +3,23 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { URI } from 'vs/base/common/uri'; - export type PerfName = 'startTime' | 'extensionActivated' | 'inputLoaded' | 'webviewCommLoaded' | 'customMarkdownLoaded' | 'editorLoaded'; type PerformanceMark = { [key in PerfName]?: number }; -const perfMarks = new Map(); +export class NotebookPerfMarks { + private _marks: PerformanceMark = {}; + + get value(): PerformanceMark { + return { ...this._marks }; + } -export function mark(resource: URI, name: PerfName): void { - const key = resource.toString(); - if (!perfMarks.has(key)) { - const perfMark: PerformanceMark = {}; - perfMark[name] = Date.now(); - perfMarks.set(key, perfMark); - } else { - if (perfMarks.get(key)![name]) { + mark(name: PerfName): void { + if (this._marks[name]) { console.error(`Skipping overwrite of notebook perf value: ${name}`); return; } - perfMarks.get(key)![name] = Date.now(); - } -} -export function clearMarks(resource: URI): void { - const key = resource.toString(); - - perfMarks.delete(key); -} - -export function getAndClearMarks(resource: URI): PerformanceMark | null { - const key = resource.toString(); - - const perfMark = perfMarks.get(key) || null; - perfMarks.delete(key); - return perfMark; + this._marks[name] = Date.now(); + } } From 89b76f6a35bea5475b63e1f541659727f7fea300 Mon Sep 17 00:00:00 2001 From: Joyce Er Date: Fri, 15 Jul 2022 15:52:51 -0700 Subject: [PATCH 107/121] Do not require a `group` in contributed command --- .../contrib/editSessions/browser/editSessions.contribution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts b/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts index 34d89d716a288..9be6a5124f7af 100644 --- a/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts +++ b/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts @@ -113,7 +113,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo } const commands = new Map((extension.description.contributes?.commands ?? []).map(c => [c.command, c])); for (const contribution of extension.value) { - if (!contribution.command || !contribution.group || !contribution.when) { + if (!contribution.command || !contribution.when) { continue; } const fullCommand = commands.get(contribution.command); From 54ac7e08410ae29a2cb4d44347b0600f69aa19a0 Mon Sep 17 00:00:00 2001 From: Miguel Solorio Date: Fri, 15 Jul 2022 10:26:16 -0700 Subject: [PATCH 108/121] Update diff color changes --- src/vs/platform/theme/common/colorRegistry.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vs/platform/theme/common/colorRegistry.ts b/src/vs/platform/theme/common/colorRegistry.ts index 0be76bfc597a7..09e16d5c19653 100644 --- a/src/vs/platform/theme/common/colorRegistry.ts +++ b/src/vs/platform/theme/common/colorRegistry.ts @@ -401,14 +401,14 @@ export const editorLightBulbAutoFixForeground = registerColor('editorLightBulbAu /** * Diff Editor Colors */ -export const defaultInsertColor = new Color(new RGBA(53, 175, 34, 0.24)); -export const defaultRemoveColor = new Color(new RGBA(255, 0, 0, 0.2)); +export const defaultInsertColor = new Color(new RGBA(155, 185, 85, .2)); +export const defaultRemoveColor = new Color(new RGBA(255, 0, 0, .2)); -export const diffInserted = registerColor('diffEditor.insertedTextBackground', { dark: defaultInsertColor, light: defaultInsertColor, hcDark: null, hcLight: null }, nls.localize('diffEditorInserted', 'Background color for text that got inserted. The color must not be opaque so as not to hide underlying decorations.'), true); -export const diffRemoved = registerColor('diffEditor.removedTextBackground', { dark: defaultRemoveColor, light: defaultRemoveColor, hcDark: null, hcLight: null }, nls.localize('diffEditorRemoved', 'Background color for text that got removed. The color must not be opaque so as not to hide underlying decorations.'), true); +export const diffInserted = registerColor('diffEditor.insertedTextBackground', { dark: '#9ccc2c33', light: '#9ccc2c66', hcDark: null, hcLight: null }, nls.localize('diffEditorInserted', 'Background color for text that got inserted. The color must not be opaque so as not to hide underlying decorations.'), true); +export const diffRemoved = registerColor('diffEditor.removedTextBackground', { dark: '#ff000066', light: '#ff00004d', hcDark: null, hcLight: null }, nls.localize('diffEditorRemoved', 'Background color for text that got removed. The color must not be opaque so as not to hide underlying decorations.'), true); -export const diffInsertedLine = registerColor('diffEditor.insertedLineBackground', { dark: null, light: null, hcDark: null, hcLight: null }, nls.localize('diffEditorInsertedLines', 'Background color for lines that got inserted. The color must not be opaque so as not to hide underlying decorations.'), true); -export const diffRemovedLine = registerColor('diffEditor.removedLineBackground', { dark: null, light: null, hcDark: null, hcLight: null }, nls.localize('diffEditorRemovedLines', 'Background color for lines that got removed. The color must not be opaque so as not to hide underlying decorations.'), true); +export const diffInsertedLine = registerColor('diffEditor.insertedLineBackground', { dark: defaultInsertColor, light: defaultInsertColor, hcDark: null, hcLight: null }, nls.localize('diffEditorInsertedLines', 'Background color for lines that got inserted. The color must not be opaque so as not to hide underlying decorations.'), true); +export const diffRemovedLine = registerColor('diffEditor.removedLineBackground', { dark: defaultRemoveColor, light: defaultRemoveColor, hcDark: null, hcLight: null }, nls.localize('diffEditorRemovedLines', 'Background color for lines that got removed. The color must not be opaque so as not to hide underlying decorations.'), true); export const diffInsertedLineGutter = registerColor('diffEditorGutter.insertedLineBackground', { dark: null, light: null, hcDark: null, hcLight: null }, nls.localize('diffEditorInsertedLineGutter', 'Background color for the margin where lines got inserted.')); export const diffRemovedLineGutter = registerColor('diffEditorGutter.removedLineBackground', { dark: null, light: null, hcDark: null, hcLight: null }, nls.localize('diffEditorRemovedLineGutter', 'Background color for the margin where lines got removed.')); From 785d85a0bd6076f60899d25df2fe4c424ad42705 Mon Sep 17 00:00:00 2001 From: Johannes Date: Thu, 14 Jul 2022 09:29:15 +0200 Subject: [PATCH 109/121] add API proposal for `vscode.TabInputTextMerge` --- .../api/browser/mainThreadEditorTabs.ts | 11 +++++++ .../workbench/api/common/extHost.api.impl.ts | 1 + .../workbench/api/common/extHost.protocol.ts | 11 ++++++- .../workbench/api/common/extHostEditorTabs.ts | 8 +++-- src/vs/workbench/api/common/extHostTypes.ts | 4 +++ .../test/browser/extHostEditorTabs.test.ts | 33 ++++++++++++++++++- .../common/extensionsApiProposals.ts | 1 + .../vscode.proposed.tabInputTextMerge.d.ts | 25 ++++++++++++++ 8 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts diff --git a/src/vs/workbench/api/browser/mainThreadEditorTabs.ts b/src/vs/workbench/api/browser/mainThreadEditorTabs.ts index c410ad77dc085..3b9b4dec1fe9e 100644 --- a/src/vs/workbench/api/browser/mainThreadEditorTabs.ts +++ b/src/vs/workbench/api/browser/mainThreadEditorTabs.ts @@ -23,6 +23,7 @@ import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEdit import { isEqual } from 'vs/base/common/resources'; import { isGroupEditorMoveEvent } from 'vs/workbench/common/editor/editorGroupModel'; import { InteractiveEditorInput } from 'vs/workbench/contrib/interactive/browser/interactiveEditorInput'; +import { MergeEditorInput } from 'vs/workbench/contrib/mergeEditor/browser/mergeEditorInput'; interface TabInfo { tab: IEditorTabDto; @@ -91,6 +92,16 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape { private _editorInputToDto(editor: EditorInput): AnyInputDto { + if (editor instanceof MergeEditorInput) { + return { + kind: TabInputKind.TextMergeInput, + base: editor.base, + input1: editor.input1.uri, + input2: editor.input2.uri, + result: editor.resource + }; + } + if (editor instanceof AbstractTextResourceEditorInput) { return { kind: TabInputKind.TextInput, diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 46325230f3c96..2be02ab479744 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -1342,6 +1342,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I InputBoxValidationSeverity: extHostTypes.InputBoxValidationSeverity, TabInputText: extHostTypes.TextTabInput, TabInputTextDiff: extHostTypes.TextDiffTabInput, + TabInputTextMerge: extHostTypes.TextMergeTabInput, TabInputCustom: extHostTypes.CustomEditorTabInput, TabInputNotebook: extHostTypes.NotebookEditorTabInput, TabInputNotebookDiff: extHostTypes.NotebookDiffEditorTabInput, diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 8df19f84b7692..16f0fd0ac1393 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -620,6 +620,7 @@ export const enum TabInputKind { UnknownInput, TextInput, TextDiffInput, + TextMergeInput, NotebookInput, NotebookDiffInput, CustomEditorInput, @@ -650,6 +651,14 @@ export interface TextDiffInputDto { modified: UriComponents; } +export interface TextMergeInputDto { + kind: TabInputKind.TextMergeInput; + base: UriComponents; + input1: UriComponents; + input2: UriComponents; + result: UriComponents; +} + export interface NotebookInputDto { kind: TabInputKind.NotebookInput; notebookType: string; @@ -684,7 +693,7 @@ export interface TabInputDto { kind: TabInputKind.TerminalEditorInput; } -export type AnyInputDto = UnknownInputDto | TextInputDto | TextDiffInputDto | NotebookInputDto | NotebookDiffInputDto | CustomInputDto | WebviewInputDto | InteractiveEditorInputDto | TabInputDto; +export type AnyInputDto = UnknownInputDto | TextInputDto | TextDiffInputDto | TextMergeInputDto | NotebookInputDto | NotebookDiffInputDto | CustomInputDto | WebviewInputDto | InteractiveEditorInputDto | TabInputDto; export interface MainThreadEditorTabsShape extends IDisposable { // manage tabs: move, close, rearrange etc diff --git a/src/vs/workbench/api/common/extHostEditorTabs.ts b/src/vs/workbench/api/common/extHostEditorTabs.ts index 1df76fd88c748..3282c7cc74682 100644 --- a/src/vs/workbench/api/common/extHostEditorTabs.ts +++ b/src/vs/workbench/api/common/extHostEditorTabs.ts @@ -9,7 +9,7 @@ import { IEditorTabDto, IEditorTabGroupDto, IExtHostEditorTabsShape, MainContext import { URI } from 'vs/base/common/uri'; import { Emitter } from 'vs/base/common/event'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; -import { CustomEditorTabInput, InteractiveWindowInput, NotebookDiffEditorTabInput, NotebookEditorTabInput, TerminalEditorTabInput, TextDiffTabInput, TextTabInput, WebviewEditorTabInput } from 'vs/workbench/api/common/extHostTypes'; +import { CustomEditorTabInput, InteractiveWindowInput, NotebookDiffEditorTabInput, NotebookEditorTabInput, TerminalEditorTabInput, TextDiffTabInput, TextMergeTabInput, TextTabInput, WebviewEditorTabInput } from 'vs/workbench/api/common/extHostTypes'; import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService'; import { assertIsDefined } from 'vs/base/common/types'; import { diffSets } from 'vs/base/common/collections'; @@ -84,6 +84,8 @@ class ExtHostEditorTab { return new TextTabInput(URI.revive(this._dto.input.uri)); case TabInputKind.TextDiffInput: return new TextDiffTabInput(URI.revive(this._dto.input.original), URI.revive(this._dto.input.modified)); + case TabInputKind.TextMergeInput: + return new TextMergeTabInput(URI.revive(this._dto.input.base), URI.revive(this._dto.input.input1), URI.revive(this._dto.input.input2), URI.revive(this._dto.input.result)); case TabInputKind.CustomEditorInput: return new CustomEditorTabInput(URI.revive(this._dto.input.uri), this._dto.input.viewType); case TabInputKind.WebviewEditorInput: @@ -110,7 +112,7 @@ class ExtHostEditorTabGroup { private _activeTabId: string = ''; private _activeGroupIdGetter: () => number | undefined; - constructor(dto: IEditorTabGroupDto, proxy: MainThreadEditorTabsShape, activeGroupIdGetter: () => number | undefined) { + constructor(dto: IEditorTabGroupDto, activeGroupIdGetter: () => number | undefined) { this._dto = dto; this._activeGroupIdGetter = activeGroupIdGetter; // Construct all tabs from the given dto @@ -284,7 +286,7 @@ export class ExtHostEditorTabs implements IExtHostEditorTabs { this._extHostTabGroups = tabGroups.map(tabGroup => { - const group = new ExtHostEditorTabGroup(tabGroup, this._proxy, () => this._activeGroupId); + const group = new ExtHostEditorTabGroup(tabGroup, () => this._activeGroupId); if (diff.added.includes(group.groupId)) { opened.push(group.apiObject); } else { diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index e50faecd5959d..707a8cfe00c6a 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -3709,6 +3709,10 @@ export class TextDiffTabInput { constructor(readonly original: URI, readonly modified: URI) { } } +export class TextMergeTabInput { + constructor(readonly base: URI, readonly input1: URI, readonly input2: URI, readonly result: URI) { } +} + export class CustomEditorTabInput { constructor(readonly uri: URI, readonly viewType: string) { } } diff --git a/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts b/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts index 4c2501f46922a..39bf2306faa84 100644 --- a/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts +++ b/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts @@ -10,7 +10,7 @@ import { mock } from 'vs/base/test/common/mock'; import { IEditorTabDto, IEditorTabGroupDto, MainThreadEditorTabsShape, TabInputKind, TabModelOperationKind, TextInputDto } from 'vs/workbench/api/common/extHost.protocol'; import { ExtHostEditorTabs } from 'vs/workbench/api/common/extHostEditorTabs'; import { SingleProxyRPCProtocol } from 'vs/workbench/api/test/common/testRPCProtocol'; -import { TextTabInput } from 'vs/workbench/api/common/extHostTypes'; +import { TextMergeTabInput, TextTabInput } from 'vs/workbench/api/common/extHostTypes'; suite('ExtHostEditorTabs', function () { @@ -209,6 +209,37 @@ suite('ExtHostEditorTabs', function () { assert.strictEqual(extHostEditorTabs.tabGroups.activeTabGroup, first); }); + test('TextMergeTabInput surfaces in the UI', function () { + + const extHostEditorTabs = new ExtHostEditorTabs( + SingleProxyRPCProtocol(new class extends mock() { + // override/implement $moveTab or $closeTab + }) + ); + + const tab: IEditorTabDto = createTabDto({ + input: { + kind: TabInputKind.TextMergeInput, + base: URI.from({ scheme: 'test', path: 'base' }), + input1: URI.from({ scheme: 'test', path: 'input1' }), + input2: URI.from({ scheme: 'test', path: 'input2' }), + result: URI.from({ scheme: 'test', path: 'result' }), + } + }); + + extHostEditorTabs.$acceptEditorTabModel([{ + isActive: true, + viewColumn: 0, + groupId: 12, + tabs: [tab] + }]); + assert.strictEqual(extHostEditorTabs.tabGroups.all.length, 1); + const [first] = extHostEditorTabs.tabGroups.all; + assert.ok(first.activeTab); + assert.strictEqual(first.tabs.indexOf(first.activeTab), 0); + assert.ok(first.activeTab.input instanceof TextMergeTabInput); + }); + test('Ensure reference stability', function () { const extHostEditorTabs = new ExtHostEditorTabs( diff --git a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts index 012e90c93847a..ca5260d65af7d 100644 --- a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts +++ b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts @@ -52,6 +52,7 @@ export const allApiProposals = Object.freeze({ scmSelectedProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmSelectedProvider.d.ts', scmValidation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmValidation.d.ts', snippetWorkspaceEdit: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.snippetWorkspaceEdit.d.ts', + tabInputTextMerge: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts', taskPresentationGroup: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.taskPresentationGroup.d.ts', telemetry: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.telemetry.d.ts', terminalDataWriteEvent: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.terminalDataWriteEvent.d.ts', diff --git a/src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts b/src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts new file mode 100644 index 0000000000000..da95fd1d35bc6 --- /dev/null +++ b/src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts @@ -0,0 +1,25 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +// https://github.com/microsoft/vscode/issues/153213 + +declare module 'vscode' { + + export class TabInputTextMerge { + + readonly base: Uri; + readonly input1: Uri; + readonly input2: Uri; + readonly result: Uri; + + constructor(base: Uri, input1: Uri, input2: Uri, result: Uri); + } + + export interface Tab { + + readonly input: TabInputText | TabInputTextDiff | TabInputTextMerge | TabInputCustom | TabInputWebview | TabInputNotebook | TabInputNotebookDiff | TabInputTerminal | unknown; + + } +} From e5a5e6cf917e73f1908e5b1df59df1cb9e85288d Mon Sep 17 00:00:00 2001 From: Johannes Date: Thu, 14 Jul 2022 09:41:54 +0200 Subject: [PATCH 110/121] use `TabInputTextMerge` in git extensions For now only when checking for tabs, not yet for opening tabs --- extensions/git/package.json | 1 + extensions/git/src/commands.ts | 23 ++++++++++++++--------- extensions/git/tsconfig.json | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index 27811e8e93eb4..8a0a8cf7ed1e3 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -16,6 +16,7 @@ "scmActionButton", "scmSelectedProvider", "scmValidation", + "tabInputTextMerge", "timeline" ], "categories": [ diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 37c500f76054e..b428e24195ede 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -5,7 +5,7 @@ import * as os from 'os'; import * as path from 'path'; -import { Command, commands, Disposable, LineChange, MessageOptions, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider, InputBoxValidationSeverity, TabInputText } from 'vscode'; +import { Command, commands, Disposable, LineChange, MessageOptions, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider, InputBoxValidationSeverity, TabInputText, TabInputTextMerge } from 'vscode'; import TelemetryReporter from '@vscode/extension-telemetry'; import * as nls from 'vscode-nls'; import { uniqueNamesGenerator, adjectives, animals, colors, NumberDictionary } from '@joaomoreno/unique-names-generator'; @@ -1099,21 +1099,26 @@ export class CommandCenter { return; } + const { activeTab } = window.tabGroups.activeTabGroup; + if (!activeTab) { + return; + } + + // make sure to save the merged document const doc = workspace.textDocuments.find(doc => doc.uri.toString() === uri.toString()); if (!doc) { console.log(`FAILED to accept merge because uri ${uri.toString()} doesn't match a document`); return; } + if (doc.isDirty) { + await doc.save(); + } - await doc.save(); - - // TODO@jrieken there isn't a `TabInputTextMerge` instance yet, till now the merge editor - // uses the `TabInputText` for the out-resource and we use that to identify and CLOSE the tab - // see https://github.com/microsoft/vscode/issues/153213 - const { activeTab } = window.tabGroups.activeTabGroup; + // find the merge editor tabs for the resource in question and close them all let didCloseTab = false; - if (activeTab && activeTab?.input instanceof TabInputText && activeTab.input.uri.toString() === uri.toString()) { - didCloseTab = await window.tabGroups.close(activeTab, true); + const mergeEditorTabs = window.tabGroups.all.map(group => group.tabs.filter(tab => tab.input instanceof TabInputTextMerge && tab.input.result.toString() === uri.toString())).flat(); + if (mergeEditorTabs.includes(activeTab)) { + didCloseTab = await window.tabGroups.close(mergeEditorTabs, true); } // Only stage if the merge editor has been successfully closed. That means all conflicts have been diff --git a/extensions/git/tsconfig.json b/extensions/git/tsconfig.json index 13997275056b0..c62c25401f27e 100644 --- a/extensions/git/tsconfig.json +++ b/extensions/git/tsconfig.json @@ -14,7 +14,7 @@ "../../src/vscode-dts/vscode.proposed.scmActionButton.d.ts", "../../src/vscode-dts/vscode.proposed.scmSelectedProvider.d.ts", "../../src/vscode-dts/vscode.proposed.scmValidation.d.ts", - "../../src/vscode-dts/vscode.proposed.tabs.d.ts", + "../../src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts", "../../src/vscode-dts/vscode.proposed.timeline.d.ts", "../types/lib.textEncoder.d.ts" ] From de91416cd70ec4fea7d4376237b421dc30ffafe4 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Fri, 15 Jul 2022 23:52:19 +0200 Subject: [PATCH 111/121] ButtonWithDescripiton - Remove tabIndex from the label and description elements (#155317) Remove tabIndex from the label and description elements --- src/vs/base/browser/ui/button/button.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/vs/base/browser/ui/button/button.ts b/src/vs/base/browser/ui/button/button.ts index 2b48b94c938e2..920160b9a1593 100644 --- a/src/vs/base/browser/ui/button/button.ts +++ b/src/vs/base/browser/ui/button/button.ts @@ -341,12 +341,10 @@ export class ButtonWithDescription extends Button implements IButtonWithDescript this._labelElement = document.createElement('div'); this._labelElement.classList.add('monaco-button-label'); - this._labelElement.tabIndex = -1; this._element.appendChild(this._labelElement); this._descriptionElement = document.createElement('div'); this._descriptionElement.classList.add('monaco-button-description'); - this._descriptionElement.tabIndex = -1; this._element.appendChild(this._descriptionElement); } From 4dd03ae9a4d7bbe203df454b53515054bc6e3bdc Mon Sep 17 00:00:00 2001 From: SteVen Batten <6561887+sbatten@users.noreply.github.com> Date: Fri, 15 Jul 2022 18:06:33 -0700 Subject: [PATCH 112/121] add focus title bar command (#155347) fixes #149739 --- .../browser/parts/titlebar/titlebarPart.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index a3f2972bd4bc6..7caacace4a2ec 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -36,6 +36,7 @@ import { WindowTitle } from 'vs/workbench/browser/parts/titlebar/windowTitle'; import { CommandCenterControl } from 'vs/workbench/browser/parts/titlebar/commandCenterControl'; import { IHoverDelegate } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate'; import { IHoverService } from 'vs/workbench/services/hover/browser/hover'; +import { CATEGORIES } from 'vs/workbench/common/actions'; export class TitlebarPart extends Part implements ITitleService { @@ -328,6 +329,27 @@ export class TitlebarPart extends Part implements ITitleService { this.updateStyles(); + const that = this; + registerAction2(class FocusTitleBar extends Action2 { + + constructor() { + super({ + id: `workbench.action.focusTitleBar`, + title: { value: localize('focusTitleBar', "Focus Title Bar"), original: 'Focus Title Bar' }, + category: CATEGORIES.View, + f1: true, + }); + } + + run(accessor: ServicesAccessor, ...args: any[]): void { + if (that.customMenubar) { + that.customMenubar.toggleFocus(); + } else { + (that.element.querySelector('[tabindex]:not([tabindex="-1"])') as HTMLElement).focus(); + } + } + }); + return this.element; } From 4c1642906516310fb38b81efc7c2fae8520867c7 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Fri, 15 Jul 2022 18:15:43 -0700 Subject: [PATCH 113/121] check if values are true not just undefined (#155348) --- .../workbench/contrib/tasks/browser/abstractTaskService.ts | 7 ++++--- .../workbench/contrib/tasks/browser/task.contribution.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index 4bfc497f05a59..d32b3e5602a9c 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -293,7 +293,9 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer })); this._taskRunningState = TASK_RUNNING_STATE.bindTo(_contextKeyService); this._onDidStateChange = this._register(new Emitter()); - this._registerCommands(); + this._registerCommands().then(() => { + TaskCommandsRegistered.bindTo(this._contextKeyService).set(true); + }); this._configurationResolverService.contributeVariable('defaultBuildTask', async (): Promise => { let tasks = await this._getTasksForGroup(TaskGroup.Build); if (tasks.length > 0) { @@ -491,7 +493,6 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer this._openTaskFile(resource, TaskSourceKind.WorkspaceFile); } }); - TaskCommandsRegistered.bindTo(this._contextKeyService).set(true); } private get workspaceFolders(): IWorkspaceFolder[] { @@ -2173,7 +2174,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } private get _jsonTasksSupported(): boolean { - return !!ShellExecutionSupportedContext.getValue(this._contextKeyService) && !!ProcessExecutionSupportedContext.getValue(this._contextKeyService); + return ShellExecutionSupportedContext.getValue(this._contextKeyService) === true && ProcessExecutionSupportedContext.getValue(this._contextKeyService) === true && !Platform.isWeb; } private _computeWorkspaceFolderTasks(workspaceFolder: IWorkspaceFolder, runSource: TaskRunSource = TaskRunSource.User): Promise { diff --git a/src/vs/workbench/contrib/tasks/browser/task.contribution.ts b/src/vs/workbench/contrib/tasks/browser/task.contribution.ts index 3b7aa6162afba..a2cc1a8efaf8c 100644 --- a/src/vs/workbench/contrib/tasks/browser/task.contribution.ts +++ b/src/vs/workbench/contrib/tasks/browser/task.contribution.ts @@ -40,7 +40,7 @@ import { TaskDefinitionRegistry } from 'vs/workbench/contrib/tasks/common/taskDe import { TerminalMenuBarGroup } from 'vs/workbench/contrib/terminal/browser/terminalMenus'; import { isString } from 'vs/base/common/types'; -const SHOW_TASKS_COMMANDS_CONTEXT = ContextKeyExpr.or(ShellExecutionSupportedContext, ProcessExecutionSupportedContext); +const SHOW_TASKS_COMMANDS_CONTEXT = ContextKeyExpr.and(ShellExecutionSupportedContext, ProcessExecutionSupportedContext, TaskCommandsRegistered); const workbenchRegistry = Registry.as(WorkbenchExtensions.Workbench); workbenchRegistry.registerWorkbenchContribution(RunAutomaticTasks, LifecyclePhase.Eventually); From f29f12f0855d40dfa03e17f4eeb3609202936a41 Mon Sep 17 00:00:00 2001 From: Robo Date: Mon, 18 Jul 2022 13:32:11 +0900 Subject: [PATCH 114/121] chore: update electron@18.3.5 (#155452) From 32c436d844a5686f581d9860121e9d21bf89ab73 Mon Sep 17 00:00:00 2001 From: Tomer Chachamu Date: Mon, 18 Jul 2022 05:32:38 +0100 Subject: [PATCH 115/121] Update breadcrumbs when workspace folders update (#154616) --- src/vs/workbench/browser/labels.ts | 21 ++++++++++++++++++- .../parts/editor/breadcrumbsControl.ts | 2 +- .../browser/parts/editor/breadcrumbsModel.ts | 8 ++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/browser/labels.ts b/src/vs/workbench/browser/labels.ts index 3e47d3df06a95..34679828f660d 100644 --- a/src/vs/workbench/browser/labels.ts +++ b/src/vs/workbench/browser/labels.ts @@ -114,6 +114,7 @@ export class ResourceLabels extends Disposable { @IInstantiationService private readonly instantiationService: IInstantiationService, @IConfigurationService private readonly configurationService: IConfigurationService, @IModelService private readonly modelService: IModelService, + @IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService, @ILanguageService private readonly languageService: ILanguageService, @IDecorationsService private readonly decorationsService: IDecorationsService, @IThemeService private readonly themeService: IThemeService, @@ -153,6 +154,11 @@ export class ResourceLabels extends Disposable { this.widgets.forEach(widget => widget.notifyModelAdded(model)); })); + // notify when workspace folders changes + this._register(this.workspaceService.onDidChangeWorkspaceFolders(() => { + this.widgets.forEach(widget => widget.notifyWorkspaceFoldersChange()); + })); + // notify when file decoration changes this._register(this.decorationsService.onDidChangeDecorations(e => { let notifyDidChangeDecorations = false; @@ -250,13 +256,14 @@ export class ResourceLabel extends ResourceLabels { @IInstantiationService instantiationService: IInstantiationService, @IConfigurationService configurationService: IConfigurationService, @IModelService modelService: IModelService, + @IWorkspaceContextService workspaceService: IWorkspaceContextService, @ILanguageService languageService: ILanguageService, @IDecorationsService decorationsService: IDecorationsService, @IThemeService themeService: IThemeService, @ILabelService labelService: ILabelService, @ITextFileService textFileService: ITextFileService ) { - super(DEFAULT_LABELS_CONTAINER, instantiationService, configurationService, modelService, languageService, decorationsService, themeService, labelService, textFileService); + super(DEFAULT_LABELS_CONTAINER, instantiationService, configurationService, modelService, workspaceService, languageService, decorationsService, themeService, labelService, textFileService); this.label = this._register(this.create(container, options)); } @@ -279,6 +286,7 @@ class ResourceLabelWidget extends IconLabel { private computedIconClasses: string[] | undefined = undefined; private computedLanguageId: string | undefined = undefined; private computedPathLabel: string | undefined = undefined; + private computedWorkspaceFolderLabel: string | undefined = undefined; private needsRedraw: Redraw | undefined = undefined; private isHidden: boolean = false; @@ -374,6 +382,15 @@ class ResourceLabelWidget extends IconLabel { } } + notifyWorkspaceFoldersChange(): void { + if (typeof this.computedWorkspaceFolderLabel === 'string') { + const resource = toResource(this.label); + if (URI.isUri(resource) && this.label?.name === this.computedWorkspaceFolderLabel) { + this.setFile(resource, this.options); + } + } + } + setFile(resource: URI, options?: IFileLabelOptions): void { const hideLabel = options?.hideLabel; let name: string | undefined; @@ -382,6 +399,7 @@ class ResourceLabelWidget extends IconLabel { const workspaceFolder = this.contextService.getWorkspaceFolder(resource); if (workspaceFolder) { name = workspaceFolder.name; + this.computedWorkspaceFolderLabel = name; } } @@ -602,5 +620,6 @@ class ResourceLabelWidget extends IconLabel { this.computedLanguageId = undefined; this.computedIconClasses = undefined; this.computedPathLabel = undefined; + this.computedWorkspaceFolderLabel = undefined; } } diff --git a/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts b/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts index 57aa2f38d913c..15973ea64e20c 100644 --- a/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts +++ b/src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts @@ -280,10 +280,10 @@ export class BreadcrumbsControl { this._editorGroup.activeEditorPane ); - this.domNode.classList.toggle('relative-path', model.isRelative()); this.domNode.classList.toggle('backslash-path', this._labelService.getSeparator(uri.scheme, uri.authority) === '\\'); const updateBreadcrumbs = () => { + this.domNode.classList.toggle('relative-path', model.isRelative()); const showIcons = this._cfShowIcons.getValue(); const options: IBreadcrumbsControlOptions = { ...this._options, diff --git a/src/vs/workbench/browser/parts/editor/breadcrumbsModel.ts b/src/vs/workbench/browser/parts/editor/breadcrumbsModel.ts index d3d8b188c8393..e542f84cff404 100644 --- a/src/vs/workbench/browser/parts/editor/breadcrumbsModel.ts +++ b/src/vs/workbench/browser/parts/editor/breadcrumbsModel.ts @@ -37,7 +37,7 @@ export class OutlineElement2 { export class BreadcrumbsModel { private readonly _disposables = new DisposableStore(); - private readonly _fileInfo: FileInfo; + private _fileInfo: FileInfo; private readonly _cfgFilePath: BreadcrumbsConfig<'on' | 'off' | 'last'>; private readonly _cfgSymbolPath: BreadcrumbsConfig<'on' | 'off' | 'last'>; @@ -60,6 +60,7 @@ export class BreadcrumbsModel { this._disposables.add(this._cfgFilePath.onDidChange(_ => this._onDidUpdate.fire(this))); this._disposables.add(this._cfgSymbolPath.onDidChange(_ => this._onDidUpdate.fire(this))); + this._workspaceService.onDidChangeWorkspaceFolders(this._onDidChangeWorkspaceFolders, this, this._disposables); this._fileInfo = this._initFilePathInfo(resource); if (editor) { @@ -146,6 +147,11 @@ export class BreadcrumbsModel { return info; } + private _onDidChangeWorkspaceFolders() { + this._fileInfo = this._initFilePathInfo(this.resource); + this._onDidUpdate.fire(this); + } + private _bindToEditor(editor: IEditorPane): void { const newCts = new CancellationTokenSource(); this._currentOutline.clear(); From 427bcb1549880ab8ed9dee1d952e21dc28082b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Mon, 18 Jul 2022 10:03:48 +0200 Subject: [PATCH 116/121] Revert "check if values are true not just undefined (#155348)" (#155468) This reverts commit 78397428676e15782e253261358b0398c2a1149e. --- .../workbench/contrib/tasks/browser/abstractTaskService.ts | 7 +++---- .../workbench/contrib/tasks/browser/task.contribution.ts | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index d32b3e5602a9c..4bfc497f05a59 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -293,9 +293,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer })); this._taskRunningState = TASK_RUNNING_STATE.bindTo(_contextKeyService); this._onDidStateChange = this._register(new Emitter()); - this._registerCommands().then(() => { - TaskCommandsRegistered.bindTo(this._contextKeyService).set(true); - }); + this._registerCommands(); this._configurationResolverService.contributeVariable('defaultBuildTask', async (): Promise => { let tasks = await this._getTasksForGroup(TaskGroup.Build); if (tasks.length > 0) { @@ -493,6 +491,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer this._openTaskFile(resource, TaskSourceKind.WorkspaceFile); } }); + TaskCommandsRegistered.bindTo(this._contextKeyService).set(true); } private get workspaceFolders(): IWorkspaceFolder[] { @@ -2174,7 +2173,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } private get _jsonTasksSupported(): boolean { - return ShellExecutionSupportedContext.getValue(this._contextKeyService) === true && ProcessExecutionSupportedContext.getValue(this._contextKeyService) === true && !Platform.isWeb; + return !!ShellExecutionSupportedContext.getValue(this._contextKeyService) && !!ProcessExecutionSupportedContext.getValue(this._contextKeyService); } private _computeWorkspaceFolderTasks(workspaceFolder: IWorkspaceFolder, runSource: TaskRunSource = TaskRunSource.User): Promise { diff --git a/src/vs/workbench/contrib/tasks/browser/task.contribution.ts b/src/vs/workbench/contrib/tasks/browser/task.contribution.ts index a2cc1a8efaf8c..3b7aa6162afba 100644 --- a/src/vs/workbench/contrib/tasks/browser/task.contribution.ts +++ b/src/vs/workbench/contrib/tasks/browser/task.contribution.ts @@ -40,7 +40,7 @@ import { TaskDefinitionRegistry } from 'vs/workbench/contrib/tasks/common/taskDe import { TerminalMenuBarGroup } from 'vs/workbench/contrib/terminal/browser/terminalMenus'; import { isString } from 'vs/base/common/types'; -const SHOW_TASKS_COMMANDS_CONTEXT = ContextKeyExpr.and(ShellExecutionSupportedContext, ProcessExecutionSupportedContext, TaskCommandsRegistered); +const SHOW_TASKS_COMMANDS_CONTEXT = ContextKeyExpr.or(ShellExecutionSupportedContext, ProcessExecutionSupportedContext); const workbenchRegistry = Registry.as(WorkbenchExtensions.Workbench); workbenchRegistry.registerWorkbenchContribution(RunAutomaticTasks, LifecyclePhase.Eventually); From 4d46e56dffaa6e071bfb075f88c32a82466f74d8 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 18 Jul 2022 13:57:40 +0200 Subject: [PATCH 117/121] mention `editor.suggestOnTriggerCharacters` from the quick suggest doc, (#155467) https://github.com/microsoft/vscode/issues/155410 --- src/vs/editor/common/config/editorOptions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vs/editor/common/config/editorOptions.ts b/src/vs/editor/common/config/editorOptions.ts index 7292a7e132b25..31e39bf1cf419 100644 --- a/src/vs/editor/common/config/editorOptions.ts +++ b/src/vs/editor/common/config/editorOptions.ts @@ -2966,7 +2966,7 @@ class EditorQuickSuggestions extends BaseEditorOption Date: Mon, 18 Jul 2022 15:13:51 +0200 Subject: [PATCH 118/121] [themes] When opening a new window, product icons don't load immediately (#155485) [themes] When opening a new window, product icons don't load immediatel. Fixes #142236 --- src/vs/platform/theme/common/iconRegistry.ts | 23 ++++++++++++++ .../themes/browser/productIconThemeData.ts | 31 ++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/vs/platform/theme/common/iconRegistry.ts b/src/vs/platform/theme/common/iconRegistry.ts index 43926638d6b91..7db667666e1d2 100644 --- a/src/vs/platform/theme/common/iconRegistry.ts +++ b/src/vs/platform/theme/common/iconRegistry.ts @@ -7,6 +7,7 @@ import { RunOnceScheduler } from 'vs/base/common/async'; import { Codicon, CSSIcon } from 'vs/base/common/codicons'; import { Emitter, Event } from 'vs/base/common/event'; import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema'; +import { isString } from 'vs/base/common/types'; import { URI } from 'vs/base/common/uri'; import { localize } from 'vs/nls'; import { Extensions as JSONExtensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; @@ -62,6 +63,28 @@ export interface IconFontDefinition { readonly src: IconFontSource[]; } +export namespace IconFontDefinition { + export function toJSONObject(iconFont: IconFontDefinition): any { + return { + weight: iconFont.weight, + style: iconFont.style, + src: iconFont.src.map(s => ({ format: s.format, location: s.location.toString() })) + }; + } + export function fromJSONObject(json: any): IconFontDefinition | undefined { + const stringOrUndef = (s: any) => isString(s) ? s : undefined; + if (json && Array.isArray(json.src) && json.src.every((s: any) => isString(s.format) && isString(s.location))) { + return { + weight: stringOrUndef(json.weight), + style: stringOrUndef(json.style), + src: json.src.map((s: any) => ({ format: s.format, location: URI.parse(s.location) })) + }; + } + return undefined; + } +} + + export interface IconFontSource { readonly location: URI; readonly format: string; diff --git a/src/vs/workbench/services/themes/browser/productIconThemeData.ts b/src/vs/workbench/services/themes/browser/productIconThemeData.ts index 80a9e6d973bde..63ca74a35cdb9 100644 --- a/src/vs/workbench/services/themes/browser/productIconThemeData.ts +++ b/src/vs/workbench/services/themes/browser/productIconThemeData.ts @@ -13,7 +13,7 @@ import { getParseErrorMessage } from 'vs/base/common/jsonErrorMessages'; import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; import { DEFAULT_PRODUCT_ICON_THEME_SETTING_VALUE } from 'vs/workbench/services/themes/common/themeConfiguration'; import { fontIdRegex, fontWeightRegex, fontStyleRegex, fontFormatRegex } from 'vs/workbench/services/themes/common/productIconThemeSchema'; -import { isString } from 'vs/base/common/types'; +import { isObject, isString } from 'vs/base/common/types'; import { ILogService } from 'vs/platform/log/common/log'; import { IconDefinition, getIconRegistry, IconContribution, IconFontDefinition, IconFontSource } from 'vs/platform/theme/common/iconRegistry'; import { ThemeIcon } from 'vs/platform/theme/common/themeService'; @@ -132,6 +132,24 @@ export class ProductIconThemeData implements IWorkbenchProductIconTheme { break; } } + const { iconDefinitions, iconFontDefinitions } = data; + if (Array.isArray(iconDefinitions) && isObject(iconFontDefinitions)) { + const restoredIconDefinitions = new Map(); + for (const entry of iconDefinitions) { + const { id, fontCharacter, fontId } = entry; + if (isString(id) && isString(fontCharacter)) { + if (isString(fontId)) { + const iconFontDefinition = IconFontDefinition.fromJSONObject(iconFontDefinitions[fontId]); + if (iconFontDefinition) { + restoredIconDefinitions.set(id, { fontCharacter, font: { id: fontId, definition: iconFontDefinition } }); + } + } else { + restoredIconDefinitions.set(id, { fontCharacter }); + } + } + } + theme.iconThemeDocument = { iconDefinitions: restoredIconDefinitions }; + } return theme; } catch (e) { return undefined; @@ -139,6 +157,15 @@ export class ProductIconThemeData implements IWorkbenchProductIconTheme { } toStorage(storageService: IStorageService) { + const iconDefinitions = []; + const iconFontDefinitions: { [id: string]: IconFontDefinition } = {}; + for (const entry of this.iconThemeDocument.iconDefinitions.entries()) { + const font = entry[1].font; + iconDefinitions.push({ id: entry[0], fontCharacter: entry[1].fontCharacter, fontId: font?.id }); + if (font && iconFontDefinitions[font.id] === undefined) { + iconFontDefinitions[font.id] = IconFontDefinition.toJSONObject(font.definition); + } + } const data = JSON.stringify({ id: this.id, label: this.label, @@ -147,6 +174,8 @@ export class ProductIconThemeData implements IWorkbenchProductIconTheme { styleSheetContent: this.styleSheetContent, watch: this.watch, extensionData: ExtensionData.toJSONObject(this.extensionData), + iconDefinitions, + iconFontDefinitions }); storageService.store(ProductIconThemeData.STORAGE_KEY, data, StorageScope.PROFILE, StorageTarget.MACHINE); } From 0ffdd8012917c4ef00dbfa288de73a0d151e4182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Mon, 18 Jul 2022 16:07:29 +0200 Subject: [PATCH 119/121] h: type check attributes object (#155501) --- src/vs/base/browser/dom.ts | 65 ++++++++----------- .../mergeEditor/browser/view/editorGutter.ts | 2 +- 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts index 2e8651879ef77..4db47cd947aae 100644 --- a/src/vs/base/browser/dom.ts +++ b/src/vs/base/browser/dom.ts @@ -1734,18 +1734,27 @@ export function computeClippingRect(elementOrRect: HTMLElement | DOMRectReadOnly return { top, right, bottom, left }; } -interface DomNodeAttributes { - role?: string; - ariaHidden?: boolean; - style?: StyleAttributes; -} - -interface StyleAttributes { - height?: number | string; - width?: number | string; -} +type HTMLElementAttributeKeys = Partial<{ [K in keyof T]: T[K] extends Function ? never : T[K] extends object ? HTMLElementAttributeKeys : T[K] }>; +type ElementAttributes = HTMLElementAttributeKeys & Record; +type RemoveHTMLElement = T extends HTMLElement ? never : T; +type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; +type ArrayToObj = UnionToIntersection>; -// +type TagToElement = T extends `.${string}` + ? HTMLDivElement + : T extends `#${string}` + ? HTMLDivElement + : T extends `${infer TStart}#${string}` + ? TStart extends keyof HTMLElementTagNameMap + ? HTMLElementTagNameMap[TStart] + : HTMLElement + : T extends `${infer TStart}.${string}` + ? TStart extends keyof HTMLElementTagNameMap + ? HTMLElementTagNameMap[TStart] + : HTMLElement + : T extends keyof HTMLElementTagNameMap + ? HTMLElementTagNameMap[T] + : HTMLElement; /** * A helper function to create nested dom nodes. @@ -1762,22 +1771,25 @@ interface StyleAttributes { * private readonly editor = createEditor(this.htmlElements.editor); * ``` */ +export function h( + tag: TTag +): (Record<'root', TagToElement>) extends infer Y ? { [TKey in keyof Y]: Y[TKey] } : never; export function h( tag: TTag, - attributes: { $: TId } & DomNodeAttributes + attributes: { $: TId } & Partial>> ): Record>; -export function h(tag: TTag, attributes: DomNodeAttributes): Record<'root', TagToElement>; export function h)[]>( tag: TTag, children: T ): (ArrayToObj & Record<'root', TagToElement>) extends infer Y ? { [TKey in keyof Y]: Y[TKey] } : never; +export function h(tag: TTag, attributes: Partial>>): Record<'root', TagToElement>; export function h)[]>( tag: TTag, - attributes: { $: TId } & DomNodeAttributes, + attributes: { $: TId } & Partial>>, children: T ): (ArrayToObj & Record>) extends infer Y ? { [TKey in keyof Y]: Y[TKey] } : never; -export function h(tag: string, ...args: [] | [attributes: { $: string } & DomNodeAttributes | Record, children?: any[]] | [children: any[]]): Record { - let attributes: { $?: string } & DomNodeAttributes; +export function h(tag: string, ...args: [] | [attributes: { $: string } & Partial> | Record, children?: any[]] | [children: any[]]): Record { + let attributes: { $?: string } & Partial>; let children: (Record | HTMLElement)[] | undefined; if (Array.isArray(args[0])) { @@ -1845,24 +1857,3 @@ export function h(tag: string, ...args: [] | [attributes: { $: string } & DomNod function camelCaseToHyphenCase(str: string) { return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); } - -type RemoveHTMLElement = T extends HTMLElement ? never : T; - -type ArrayToObj = UnionToIntersection>; - - -type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; - -type HTMLElementsByTagName = { - div: HTMLDivElement; - span: HTMLSpanElement; - a: HTMLAnchorElement; -}; - -type TagToElement = T extends `${infer TStart}.${string}` - ? TStart extends keyof HTMLElementsByTagName - ? HTMLElementsByTagName[TStart] - : HTMLElement - : T extends keyof HTMLElementsByTagName - ? HTMLElementsByTagName[T] - : HTMLElement; diff --git a/src/vs/workbench/contrib/mergeEditor/browser/view/editorGutter.ts b/src/vs/workbench/contrib/mergeEditor/browser/view/editorGutter.ts index 7289cc6163737..6b7f4670cb0ca 100644 --- a/src/vs/workbench/contrib/mergeEditor/browser/view/editorGutter.ts +++ b/src/vs/workbench/contrib/mergeEditor/browser/view/editorGutter.ts @@ -31,7 +31,7 @@ export class EditorGutter extends D super(); this._domNode.className = 'gutter monaco-editor'; const scrollDecoration = this._domNode.appendChild( - h('div.scroll-decoration', { role: 'presentation', ariaHidden: true, style: { width: '100%' } }) + h('div.scroll-decoration', { role: 'presentation', ariaHidden: 'true', style: { width: '100%' } }) .root ); From 8505dcfb6826176d3a1cef1fe68fe6b7a6429c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Mon, 18 Jul 2022 16:25:05 +0200 Subject: [PATCH 120/121] Support find widget in lists/trees (#152481) * replace list type filter and tree type label controller with list type navigation and tree find. use proper FindInput widget * make sure vim doesn't break * polish outline use case * :lipstick: * remove unused import --- src/vs/base/browser/ui/findinput/findInput.ts | 48 +- src/vs/base/browser/ui/list/list.css | 77 +-- src/vs/base/browser/ui/list/listPaging.ts | 10 +- src/vs/base/browser/ui/list/listWidget.ts | 72 +-- src/vs/base/browser/ui/table/tableWidget.ts | 4 +- src/vs/base/browser/ui/toggle/toggle.ts | 1 + src/vs/base/browser/ui/tree/abstractTree.ts | 550 +++++++++--------- src/vs/base/browser/ui/tree/asyncDataTree.ts | 22 +- src/vs/base/browser/ui/tree/media/tree.css | 42 ++ src/vs/base/browser/ui/tree/tree.ts | 3 +- src/vs/platform/list/browser/listService.ts | 187 +++--- src/vs/platform/theme/common/colorRegistry.ts | 3 +- src/vs/platform/theme/common/styler.ts | 23 +- .../workbench/browser/actions/listCommands.ts | 54 +- .../comments/browser/commentsTreeViewer.ts | 9 +- .../contrib/debug/browser/debugHover.ts | 2 - .../debug/browser/loadedScriptsView.ts | 5 +- .../extensions/browser/extensionsViewer.ts | 6 +- .../contrib/list/browser/list.contribution.ts | 12 +- .../contrib/markers/browser/markersView.ts | 6 +- .../browser/diff/notebookTextDiffEditor.ts | 2 +- .../browser/diff/notebookTextDiffList.ts | 16 - .../notebook/browser/notebookEditorWidget.ts | 2 +- .../notebook/browser/view/notebookCellList.ts | 16 - .../test/browser/testNotebookEditor.ts | 1 - .../contrib/outline/browser/outlinePane.ts | 13 +- .../preferences/browser/settingsTree.ts | 6 +- .../contrib/preferences/browser/tocTree.ts | 7 +- .../testing/browser/testingExplorerView.ts | 1 - 29 files changed, 619 insertions(+), 581 deletions(-) diff --git a/src/vs/base/browser/ui/findinput/findInput.ts b/src/vs/base/browser/ui/findinput/findInput.ts index b9e218ce03b21..b637cf45667dc 100644 --- a/src/vs/base/browser/ui/findinput/findInput.ts +++ b/src/vs/base/browser/ui/findinput/findInput.ts @@ -6,7 +6,7 @@ import * as dom from 'vs/base/browser/dom'; import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { IMouseEvent } from 'vs/base/browser/mouseEvent'; -import { IToggleStyles } from 'vs/base/browser/ui/toggle/toggle'; +import { IToggleStyles, Toggle } from 'vs/base/browser/ui/toggle/toggle'; import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview'; import { CaseSensitiveToggle, RegexToggle, WholeWordsToggle } from 'vs/base/browser/ui/findinput/findInputToggles'; import { HistoryInputBox, IInputBoxStyles, IInputValidator, IMessage as InputBoxMessage } from 'vs/base/browser/ui/inputbox/inputBox'; @@ -31,6 +31,7 @@ export interface IFindInputOptions extends IFindInputStyles { readonly appendWholeWordsLabel?: string; readonly appendRegexLabel?: string; readonly history?: string[]; + readonly additionalToggles?: Toggle[]; readonly showHistoryHint?: () => boolean; } @@ -74,6 +75,7 @@ export class FindInput extends Widget { protected regex: RegexToggle; protected wholeWords: WholeWordsToggle; protected caseSensitive: CaseSensitiveToggle; + protected additionalToggles: Toggle[] = []; public domNode: HTMLElement; public inputBox: HistoryInputBox; @@ -209,10 +211,6 @@ export class FindInput extends Widget { this._onCaseSensitiveKeyDown.fire(e); })); - if (this._showOptionButtons) { - this.inputBox.paddingRight = this.caseSensitive.width() + this.wholeWords.width() + this.regex.width(); - } - // Arrow-Key support to navigate between options const indexes = [this.caseSensitive.domNode, this.wholeWords.domNode, this.regex.domNode]; this.onkeydown(this.domNode, (event: IKeyboardEvent) => { @@ -250,6 +248,34 @@ export class FindInput extends Widget { this.controls.appendChild(this.wholeWords.domNode); this.controls.appendChild(this.regex.domNode); + if (!this._showOptionButtons) { + this.caseSensitive.domNode.style.display = 'none'; + this.wholeWords.domNode.style.display = 'none'; + this.regex.domNode.style.display = 'none'; + } + + for (const toggle of options?.additionalToggles ?? []) { + this._register(toggle); + this.controls.appendChild(toggle.domNode); + + this._register(toggle.onChange(viaKeyboard => { + this._onDidOptionChange.fire(viaKeyboard); + if (!viaKeyboard && this.fixFocusOnOptionClickEnabled) { + this.inputBox.focus(); + } + })); + + this.additionalToggles.push(toggle); + } + + if (this.additionalToggles.length > 0) { + this.controls.style.display = 'block'; + } + + this.inputBox.paddingRight = + (this._showOptionButtons ? this.caseSensitive.width() + this.wholeWords.width() + this.regex.width() : 0) + + this.additionalToggles.reduce((r, t) => r + t.width(), 0); + this.domNode.appendChild(this.controls); parent?.appendChild(this.domNode); @@ -282,6 +308,10 @@ export class FindInput extends Widget { this.regex.enable(); this.wholeWords.enable(); this.caseSensitive.enable(); + + for (const toggle of this.additionalToggles) { + toggle.enable(); + } } public disable(): void { @@ -290,6 +320,10 @@ export class FindInput extends Widget { this.regex.disable(); this.wholeWords.disable(); this.caseSensitive.disable(); + + for (const toggle of this.additionalToggles) { + toggle.disable(); + } } public setFocusInputOnOptionClick(value: boolean): void { @@ -356,6 +390,10 @@ export class FindInput extends Widget { this.wholeWords.style(toggleStyles); this.caseSensitive.style(toggleStyles); + for (const toggle of this.additionalToggles) { + toggle.style(toggleStyles); + } + const inputBoxStyles: IInputBoxStyles = { inputBackground: this.inputBackground, inputForeground: this.inputForeground, diff --git a/src/vs/base/browser/ui/list/list.css b/src/vs/base/browser/ui/list/list.css index eaca3ae8bd891..84cda4cfae3b7 100644 --- a/src/vs/base/browser/ui/list/list.css +++ b/src/vs/base/browser/ui/list/list.css @@ -65,72 +65,7 @@ z-index: 1000; } -/* Type filter */ - -.monaco-list-type-filter { - display: flex; - align-items: center; - position: absolute; - border-radius: 2px; - padding: 0px 3px; - max-width: calc(100% - 10px); - text-overflow: ellipsis; - overflow: hidden; - text-align: right; - box-sizing: border-box; - cursor: all-scroll; - font-size: 13px; - line-height: 18px; - height: 20px; - z-index: 1; - top: 4px; -} - -.monaco-list-type-filter.dragging { - transition: top 0.2s, left 0.2s; -} - -.monaco-list-type-filter.ne { - right: 4px; -} - -.monaco-list-type-filter.nw { - left: 4px; -} - -.monaco-list-type-filter > .controls { - display: flex; - align-items: center; - box-sizing: border-box; - transition: width 0.2s; - width: 0; -} - -.monaco-list-type-filter.dragging > .controls, -.monaco-list-type-filter:hover > .controls { - width: 36px; -} - -.monaco-list-type-filter > .controls > * { - border: none; - box-sizing: border-box; - -webkit-appearance: none; - -moz-appearance: none; - background: none; - width: 16px; - height: 16px; - flex-shrink: 0; - margin: 0; - padding: 0; - display: flex; - align-items: center; - justify-content: center; - cursor: pointer; -} - -.monaco-list-type-filter > .controls > .filter { - margin-left: 4px; -} +/* Filter */ .monaco-list-type-filter-message { position: absolute; @@ -149,13 +84,3 @@ .monaco-list-type-filter-message:empty { display: none; } - -/* Electron */ - -.monaco-list-type-filter { - cursor: grab; -} - -.monaco-list-type-filter.dragging { - cursor: grabbing; -} diff --git a/src/vs/base/browser/ui/list/listPaging.ts b/src/vs/base/browser/ui/list/listPaging.ts index 43d4ad49e81e9..ba2b55040f524 100644 --- a/src/vs/base/browser/ui/list/listPaging.ts +++ b/src/vs/base/browser/ui/list/listPaging.ts @@ -12,7 +12,7 @@ import { ScrollbarVisibility } from 'vs/base/common/scrollable'; import { IThemable } from 'vs/base/common/styler'; import 'vs/css!./list'; import { IListContextMenuEvent, IListEvent, IListMouseEvent, IListRenderer, IListVirtualDelegate } from './list'; -import { IListAccessibilityProvider, IListOptions, IListOptionsUpdate, IListStyles, List } from './listWidget'; +import { IListAccessibilityProvider, IListOptions, IListOptionsUpdate, IListStyles, List, TypeNavigationMode } from './listWidget'; export interface IPagedRenderer extends IListRenderer { renderPlaceholder(index: number, templateData: TTemplateData): void; @@ -95,8 +95,8 @@ class PagedAccessibilityProvider implements IListAccessibilityProvider { - readonly enableKeyboardNavigation?: boolean; - readonly automaticKeyboardNavigation?: boolean; + readonly typeNavigationEnabled?: boolean; + readonly typeNavigationMode?: TypeNavigationMode; readonly ariaLabel?: string; readonly keyboardSupport?: boolean; readonly multipleSelectionSupport?: boolean; @@ -282,8 +282,8 @@ export class PagedList implements IThemable, IDisposable { this.list.layout(height, width); } - toggleKeyboardNavigation(): void { - this.list.toggleKeyboardNavigation(); + triggerTypeNavigation(): void { + this.list.triggerTypeNavigation(); } reveal(index: number, relativeTop?: number): void { diff --git a/src/vs/base/browser/ui/list/listWidget.ts b/src/vs/base/browser/ui/list/listWidget.ts index db0a0b718dc2b..7254351f697f5 100644 --- a/src/vs/base/browser/ui/list/listWidget.ts +++ b/src/vs/base/browser/ui/list/listWidget.ts @@ -9,6 +9,7 @@ import { DomEmitter, stopEvent } from 'vs/base/browser/event'; import { IKeyboardEvent, StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { Gesture } from 'vs/base/browser/touch'; import { alert } from 'vs/base/browser/ui/aria/aria'; +import { IFindInputStyles } from 'vs/base/browser/ui/findinput/findInput'; import { CombinedSpliceable } from 'vs/base/browser/ui/list/splice'; import { ScrollableElementChangeOptions } from 'vs/base/browser/ui/scrollbar/scrollableElementOptions'; import { binarySearch, firstOrDefault, range } from 'vs/base/common/arrays'; @@ -384,7 +385,12 @@ class KeyboardController implements IDisposable { } } -enum TypeLabelControllerState { +export enum TypeNavigationMode { + Automatic, + Trigger +} + +enum TypeNavigationControllerState { Idle, Typing } @@ -402,12 +408,12 @@ export const DefaultKeyboardNavigationDelegate = new class implements IKeyboardN } }; -class TypeLabelController implements IDisposable { +class TypeNavigationController implements IDisposable { private enabled = false; - private state: TypeLabelControllerState = TypeLabelControllerState.Idle; + private state: TypeNavigationControllerState = TypeNavigationControllerState.Idle; - private automaticKeyboardNavigation = true; + private mode = TypeNavigationMode.Automatic; private triggered = false; private previouslyFocused = -1; @@ -424,20 +430,16 @@ class TypeLabelController implements IDisposable { } updateOptions(options: IListOptions): void { - const enableKeyboardNavigation = typeof options.enableKeyboardNavigation === 'undefined' ? true : !!options.enableKeyboardNavigation; - - if (enableKeyboardNavigation) { + if (options.typeNavigationEnabled ?? true) { this.enable(); } else { this.disable(); } - if (typeof options.automaticKeyboardNavigation !== 'undefined') { - this.automaticKeyboardNavigation = options.automaticKeyboardNavigation; - } + this.mode = options.typeNavigationMode ?? TypeNavigationMode.Automatic; } - toggle(): void { + trigger(): void { this.triggered = !this.triggered; } @@ -448,10 +450,10 @@ class TypeLabelController implements IDisposable { const onChar = this.enabledDisposables.add(Event.chain(this.enabledDisposables.add(new DomEmitter(this.view.domNode, 'keydown')).event)) .filter(e => !isInputElement(e.target as HTMLElement)) - .filter(() => this.automaticKeyboardNavigation || this.triggered) + .filter(() => this.mode === TypeNavigationMode.Automatic || this.triggered) .map(event => new StandardKeyboardEvent(event)) .filter(e => this.delegate.mightProducePrintableCharacter(e)) - .forEach(e => e.preventDefault()) + .forEach(e => { e.preventDefault(); e.stopPropagation(); }) .map(event => event.browserEvent.key) .event; @@ -490,15 +492,15 @@ class TypeLabelController implements IDisposable { private onInput(word: string | null): void { if (!word) { - this.state = TypeLabelControllerState.Idle; + this.state = TypeNavigationControllerState.Idle; this.triggered = false; return; } const focus = this.list.getFocus(); const start = focus.length > 0 ? focus[0] : 0; - const delta = this.state === TypeLabelControllerState.Idle ? 1 : 0; - this.state = TypeLabelControllerState.Typing; + const delta = this.state === TypeNavigationControllerState.Idle ? 1 : 0; + this.state = TypeNavigationControllerState.Typing; for (let i = 0; i < this.list.length; i++) { const index = (start + i + delta) % this.list.length; @@ -895,22 +897,6 @@ export class DefaultStyleController implements IStyleController { `); } - if (styles.listFilterWidgetBackground) { - content.push(`.monaco-list-type-filter { background-color: ${styles.listFilterWidgetBackground} }`); - } - - if (styles.listFilterWidgetOutline) { - content.push(`.monaco-list-type-filter { border: 1px solid ${styles.listFilterWidgetOutline}; }`); - } - - if (styles.listFilterWidgetNoMatchesOutline) { - content.push(`.monaco-list-type-filter.no-matches { border: 1px solid ${styles.listFilterWidgetNoMatchesOutline}; }`); - } - - if (styles.listMatchesShadow) { - content.push(`.monaco-list-type-filter { box-shadow: 1px 1px 1px ${styles.listMatchesShadow}; }`); - } - if (styles.tableColumnsBorder) { content.push(` .monaco-table:hover > .monaco-split-view2, @@ -934,8 +920,8 @@ export class DefaultStyleController implements IStyleController { } export interface IListOptionsUpdate extends IListViewOptionsUpdate { - readonly enableKeyboardNavigation?: boolean; - readonly automaticKeyboardNavigation?: boolean; + readonly typeNavigationEnabled?: boolean; + readonly typeNavigationMode?: TypeNavigationMode; readonly multipleSelectionSupport?: boolean; } @@ -964,7 +950,7 @@ export interface IListOptions extends IListOptionsUpdate { readonly alwaysConsumeMouseWheel?: boolean; } -export interface IListStyles { +export interface IListStyles extends IFindInputStyles { listBackground?: Color; listFocusBackground?: Color; listFocusForeground?: Color; @@ -989,7 +975,7 @@ export interface IListStyles { listFilterWidgetBackground?: Color; listFilterWidgetOutline?: Color; listFilterWidgetNoMatchesOutline?: Color; - listMatchesShadow?: Color; + listFilterWidgetShadow?: Color; treeIndentGuidesStroke?: Color; tableColumnsBorder?: Color; tableOddRowsBackgroundColor?: Color; @@ -1247,7 +1233,7 @@ export class List implements ISpliceable, IThemable, IDisposable { protected view: ListView; private spliceable: ISpliceable; private styleController: IStyleController; - private typeLabelController?: TypeLabelController; + private typeNavigationController?: TypeNavigationController; private accessibilityProvider?: IListAccessibilityProvider; private keyboardController: KeyboardController | undefined; private mouseController: MouseController; @@ -1387,8 +1373,8 @@ export class List implements ISpliceable, IThemable, IDisposable { if (_options.keyboardNavigationLabelProvider) { const delegate = _options.keyboardNavigationDelegate || DefaultKeyboardNavigationDelegate; - this.typeLabelController = new TypeLabelController(this, this.view, _options.keyboardNavigationLabelProvider, delegate); - this.disposables.add(this.typeLabelController); + this.typeNavigationController = new TypeNavigationController(this, this.view, _options.keyboardNavigationLabelProvider, delegate); + this.disposables.add(this.typeNavigationController); } this.mouseController = this.createMouseController(_options); @@ -1413,7 +1399,7 @@ export class List implements ISpliceable, IThemable, IDisposable { updateOptions(optionsUpdate: IListOptionsUpdate = {}): void { this._options = { ...this._options, ...optionsUpdate }; - this.typeLabelController?.updateOptions(this._options); + this.typeNavigationController?.updateOptions(this._options); if (this._options.multipleSelectionController !== undefined) { if (this._options.multipleSelectionSupport) { @@ -1529,9 +1515,9 @@ export class List implements ISpliceable, IThemable, IDisposable { this.view.layout(height, width); } - toggleKeyboardNavigation(): void { - if (this.typeLabelController) { - this.typeLabelController.toggle(); + triggerTypeNavigation(): void { + if (this.typeNavigationController) { + this.typeNavigationController.trigger(); } } diff --git a/src/vs/base/browser/ui/table/tableWidget.ts b/src/vs/base/browser/ui/table/tableWidget.ts index 03f6f284785cb..7f1d056033515 100644 --- a/src/vs/base/browser/ui/table/tableWidget.ts +++ b/src/vs/base/browser/ui/table/tableWidget.ts @@ -265,8 +265,8 @@ export class Table implements ISpliceable, IThemable, IDisposable { this.list.layout(listHeight, width); } - toggleKeyboardNavigation(): void { - this.list.toggleKeyboardNavigation(); + triggerTypeNavigation(): void { + this.list.triggerTypeNavigation(); } style(styles: ITableStyles): void { diff --git a/src/vs/base/browser/ui/toggle/toggle.ts b/src/vs/base/browser/ui/toggle/toggle.ts index 8d2387dbc265d..8e7266a2d9471 100644 --- a/src/vs/base/browser/ui/toggle/toggle.ts +++ b/src/vs/base/browser/ui/toggle/toggle.ts @@ -148,6 +148,7 @@ export class Toggle extends Widget { this.checked = !this._checked; this._onChange.fire(true); keyboardEvent.preventDefault(); + keyboardEvent.stopPropagation(); return; } diff --git a/src/vs/base/browser/ui/tree/abstractTree.ts b/src/vs/base/browser/ui/tree/abstractTree.ts index 124d926541fef..ba4c6ec3af1f2 100644 --- a/src/vs/base/browser/ui/tree/abstractTree.ts +++ b/src/vs/base/browser/ui/tree/abstractTree.ts @@ -3,27 +3,34 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { DragAndDropData, IDragAndDropData, StaticDND } from 'vs/base/browser/dnd'; -import { $, addDisposableListener, append, clearNode, createStyleSheet, getDomNodePagePosition, hasParentWithClass } from 'vs/base/browser/dom'; +import { IDragAndDropData } from 'vs/base/browser/dnd'; +import { $, append, clearNode, createStyleSheet, h, hasParentWithClass } from 'vs/base/browser/dom'; import { DomEmitter } from 'vs/base/browser/event'; import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; -import { IIdentityProvider, IKeyboardNavigationDelegate, IKeyboardNavigationLabelProvider, IListContextMenuEvent, IListDragAndDrop, IListDragOverReaction, IListMouseEvent, IListRenderer, IListVirtualDelegate } from 'vs/base/browser/ui/list/list'; +import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar'; +import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview'; +import { FindInput, IFindInputStyles } from 'vs/base/browser/ui/findinput/findInput'; +import { IMessage, MessageType } from 'vs/base/browser/ui/inputbox/inputBox'; +import { IIdentityProvider, IKeyboardNavigationLabelProvider, IListContextMenuEvent, IListDragAndDrop, IListDragOverReaction, IListMouseEvent, IListRenderer, IListVirtualDelegate } from 'vs/base/browser/ui/list/list'; import { ElementsDragAndDropData } from 'vs/base/browser/ui/list/listView'; -import { DefaultKeyboardNavigationDelegate, IListOptions, IListStyles, isButton, isInputElement, isMonacoEditor, List, MouseController } from 'vs/base/browser/ui/list/listWidget'; +import { IListOptions, IListStyles, isButton, isInputElement, isMonacoEditor, List, MouseController, TypeNavigationMode } from 'vs/base/browser/ui/list/listWidget'; +import { Toggle } from 'vs/base/browser/ui/toggle/toggle'; import { getVisibleState, isFilterResult } from 'vs/base/browser/ui/tree/indexTreeModel'; import { ICollapseStateChangeEvent, ITreeContextMenuEvent, ITreeDragAndDrop, ITreeEvent, ITreeFilter, ITreeModel, ITreeModelSpliceEvent, ITreeMouseEvent, ITreeNavigator, ITreeNode, ITreeRenderer, TreeDragOverBubble, TreeError, TreeFilterResult, TreeMouseEventTarget, TreeVisibility } from 'vs/base/browser/ui/tree/tree'; +import { Action } from 'vs/base/common/actions'; import { distinct, equals, firstOrDefault, range } from 'vs/base/common/arrays'; -import { disposableTimeout } from 'vs/base/common/async'; +import { disposableTimeout, timeout } from 'vs/base/common/async'; import { Codicon } from 'vs/base/common/codicons'; import { SetMap } from 'vs/base/common/collections'; +import { Color } from 'vs/base/common/color'; import { Emitter, Event, EventBufferer, Relay } from 'vs/base/common/event'; import { fuzzyScore, FuzzyScore } from 'vs/base/common/filters'; import { KeyCode } from 'vs/base/common/keyCodes'; import { Disposable, DisposableStore, dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { clamp } from 'vs/base/common/numbers'; -import { isMacintosh } from 'vs/base/common/platform'; import { ScrollEvent } from 'vs/base/common/scrollable'; import { ISpliceable } from 'vs/base/common/sequence'; +import { isNumber } from 'vs/base/common/types'; import 'vs/css!./media/tree'; import { localize } from 'vs/nls'; @@ -194,8 +201,7 @@ function asListOptions(modelProvider: () => ITreeModel implements IListRenderer export type LabelFuzzyScore = { label: string; score: FuzzyScore }; -class TypeFilter implements ITreeFilter, IDisposable { +class FindFilter implements ITreeFilter, IDisposable { private _totalCount = 0; get totalCount(): number { return this._totalCount; } private _matchCount = 0; @@ -590,10 +596,6 @@ class TypeFilter implements ITreeFilter, IDi if (this._filter) { const result = this._filter.filter(element, parentVisibility); - if (this.tree.options.simpleKeyboardNavigation) { - return result; - } - let visibility: TreeVisibility; if (typeof result === 'boolean') { @@ -611,7 +613,7 @@ class TypeFilter implements ITreeFilter, IDi this._totalCount++; - if (this.tree.options.simpleKeyboardNavigation || !this._pattern) { + if (!this._pattern) { this._matchCount++; return { data: FuzzyScore.Default, visibility: true }; } @@ -634,7 +636,7 @@ class TypeFilter implements ITreeFilter, IDi } } - if (this.tree.options.filterOnType) { + if (this.tree.findMode === TreeFindMode.Filter) { return TreeVisibility.Recurse; } else { return { data: FuzzyScore.Default, visibility: true }; @@ -651,170 +653,259 @@ class TypeFilter implements ITreeFilter, IDi } } -class TypeFilterController implements IDisposable { +export interface ICaseSensitiveToggleOpts { + readonly isChecked: boolean; + readonly inputActiveOptionBorder?: Color; + readonly inputActiveOptionForeground?: Color; + readonly inputActiveOptionBackground?: Color; +} - private _enabled = false; - get enabled(): boolean { return this._enabled; } +export class ModeToggle extends Toggle { + constructor(opts?: ICaseSensitiveToggleOpts) { + super({ + icon: Codicon.filter, + title: localize('filter', "Filter"), + isChecked: opts?.isChecked ?? false, + inputActiveOptionBorder: opts?.inputActiveOptionBorder, + inputActiveOptionForeground: opts?.inputActiveOptionForeground, + inputActiveOptionBackground: opts?.inputActiveOptionBackground + }); + } +} - private _pattern = ''; - get pattern(): string { return this._pattern; } +export interface IFindWidgetStyles extends IFindInputStyles, IListStyles { } - private _filterOnType: boolean; - get filterOnType(): boolean { return this._filterOnType; } +export interface IFindWidgetOpts extends IFindWidgetStyles { } - private _empty: boolean = false; - get empty(): boolean { return this._empty; } +export enum TreeFindMode { + Highlight, + Filter +} - private readonly _onDidChangeEmptyState = new Emitter(); - readonly onDidChangeEmptyState: Event = Event.latch(this._onDidChangeEmptyState.event); +class FindWidget extends Disposable { - private positionClassName = 'ne'; - private domNode: HTMLElement; - private messageDomNode: HTMLElement; - private labelDomNode: HTMLElement; - private filterOnTypeDomNode: HTMLInputElement; - private clearDomNode: HTMLElement; - private keyboardNavigationEventFilter?: IKeyboardNavigationEventFilter; + private readonly elements = h('div.monaco-tree-type-filter', [ + h('div.monaco-tree-type-filter-grab.codicon.codicon-debug-gripper', { $: 'grab' }), + h('div.monaco-tree-type-filter-input', { $: 'findInput' }), + h('div.monaco-tree-type-filter-actionbar', { $: 'actionbar' }), + ]); - private automaticKeyboardNavigation = true; - private triggered = false; + set mode(mode: TreeFindMode) { + this.modeToggle.checked = mode === TreeFindMode.Filter; + this.findInput.inputBox.setPlaceHolder(mode === TreeFindMode.Filter ? localize('type to filter', "Type to filter") : localize('type to search', "Type to search")); + } - private readonly _onDidChangePattern = new Emitter(); - readonly onDidChangePattern = this._onDidChangePattern.event; + private readonly modeToggle: ModeToggle; + private readonly findInput: FindInput; + private readonly actionbar: ActionBar; + private width = 0; + private right = 4; - private readonly enabledDisposables = new DisposableStore(); - private readonly disposables = new DisposableStore(); + readonly _onDidDisable = new Emitter(); + readonly onDidDisable = this._onDidDisable.event; + readonly onDidChangeValue: Event; + readonly onDidChangeMode: Event; constructor( + container: HTMLElement, private tree: AbstractTree, - model: ITreeModel, - private view: List>, - private filter: TypeFilter, - private keyboardNavigationDelegate: IKeyboardNavigationDelegate + contextViewProvider: IContextViewProvider, + mode: TreeFindMode, + options?: IFindWidgetOpts ) { - this.domNode = $(`.monaco-list-type-filter.${this.positionClassName}`); - this.domNode.draggable = true; - this.disposables.add(addDisposableListener(this.domNode, 'dragstart', () => this.onDragStart())); + super(); - this.messageDomNode = append(view.getHTMLElement(), $(`.monaco-list-type-filter-message`)); + container.appendChild(this.elements.root); + this._register(toDisposable(() => container.removeChild(this.elements.root))); - this.labelDomNode = append(this.domNode, $('span.label')); - const controls = append(this.domNode, $('.controls')); + this.modeToggle = this._register(new ModeToggle({ ...options, isChecked: mode === TreeFindMode.Filter })); + this.onDidChangeMode = Event.map(this.modeToggle.onChange, () => this.modeToggle.checked ? TreeFindMode.Filter : TreeFindMode.Highlight, this._store); - this._filterOnType = !!tree.options.filterOnType; - this.filterOnTypeDomNode = append(controls, $('input.filter')); - this.filterOnTypeDomNode.type = 'checkbox'; - this.filterOnTypeDomNode.checked = this._filterOnType; - this.filterOnTypeDomNode.tabIndex = -1; - this.updateFilterOnTypeTitleAndIcon(); - this.disposables.add(addDisposableListener(this.filterOnTypeDomNode, 'input', () => this.onDidChangeFilterOnType())); + this.findInput = this._register(new FindInput(this.elements.findInput, contextViewProvider, false, { + label: localize('type to search', "Type to search"), + additionalToggles: [this.modeToggle] + })); - this.clearDomNode = append(controls, $('button.clear' + Codicon.treeFilterClear.cssSelector)); - this.clearDomNode.tabIndex = -1; - this.clearDomNode.title = localize('clear', "Clear"); + this.actionbar = this._register(new ActionBar(this.elements.actionbar)); + this.mode = mode; - this.keyboardNavigationEventFilter = tree.options.keyboardNavigationEventFilter; + const emitter = this._register(new DomEmitter(this.findInput.inputBox.inputElement, 'keydown')); + const onKeyDown = this._register(Event.chain(emitter.event)) + .map(e => new StandardKeyboardEvent(e)) + .event; - model.onDidSplice(this.onDidSpliceModel, this, this.disposables); - this.updateOptions(tree.options); + this._register(onKeyDown((e): any => { + switch (e.keyCode) { + case KeyCode.DownArrow: + e.preventDefault(); + e.stopPropagation(); + this.tree.domFocus(); + return; + } + })); + + const closeAction = this._register(new Action('close', localize('close', "Close"), 'codicon codicon-close', true, () => this.dispose())); + this.actionbar.push(closeAction, { icon: true, label: false }); + + const onGrabMouseDown = this._register(new DomEmitter(this.elements.grab, 'mousedown')); + + this._register(onGrabMouseDown.event(e => { + const disposables = new DisposableStore(); + const onWindowMouseMove = disposables.add(new DomEmitter(window, 'mousemove')); + const onWindowMouseUp = disposables.add(new DomEmitter(window, 'mouseup')); + + const startRight = this.right; + const startX = e.pageX; + this.elements.grab.classList.add('grabbing'); + + const update = (e: MouseEvent) => { + const deltaX = e.pageX - startX; + this.right = startRight - deltaX; + this.layout(); + }; + + disposables.add(onWindowMouseMove.event(update)); + disposables.add(onWindowMouseUp.event(e => { + update(e); + this.elements.grab.classList.remove('grabbing'); + disposables.dispose(); + })); + })); + + + this.onDidChangeValue = this.findInput.onDidChange; + this.style(options ?? {}); } - updateOptions(options: IAbstractTreeOptions): void { - if (options.simpleKeyboardNavigation) { - this.disable(); - } else { - this.enable(); - } + style(styles: IFindWidgetStyles): void { + this.findInput.style(styles); - if (typeof options.filterOnType !== 'undefined') { - this._filterOnType = !!options.filterOnType; - this.filterOnTypeDomNode.checked = this._filterOnType; - this.updateFilterOnTypeTitleAndIcon(); + if (styles.listFilterWidgetBackground) { + this.elements.root.style.backgroundColor = styles.listFilterWidgetBackground.toString(); } - if (typeof options.automaticKeyboardNavigation !== 'undefined') { - this.automaticKeyboardNavigation = options.automaticKeyboardNavigation; + if (styles.listFilterWidgetShadow) { + this.elements.root.style.boxShadow = `0 0 8px 2px ${styles.listFilterWidgetShadow}`; } + } - this.tree.refilter(); - this.render(); + focus() { + this.findInput.focus(); + } - if (!this.automaticKeyboardNavigation) { - this.onEventOrInput(''); - } + select() { + this.findInput.select(); } - toggle(): void { - this.triggered = !this.triggered; + layout(width: number = this.width): void { + this.width = width; + this.right = Math.min(Math.max(20, this.right), Math.max(20, width - 170)); + this.elements.root.style.right = `${this.right}px`; + } - if (!this.triggered) { - this.onEventOrInput(''); - } + showMessage(message: IMessage): void { + this.findInput.showMessage(message); } - private enable(): void { - if (this._enabled) { + clearMessage(): void { + this.findInput.clearMessage(); + } + + override async dispose(): Promise { + this._onDidDisable.fire(); + this.elements.root.classList.add('disabled'); + await timeout(300); + super.dispose(); + } +} + +class FindController implements IDisposable { + + private _pattern = ''; + get pattern(): string { return this._pattern; } + + private _mode: TreeFindMode; + get mode(): TreeFindMode { return this._mode; } + set mode(mode: TreeFindMode) { + if (mode === this._mode) { return; } - const onRawKeyDown = this.enabledDisposables.add(new DomEmitter(this.view.getHTMLElement(), 'keydown')); - const onKeyDown = Event.chain(onRawKeyDown.event) - .filter(e => !isInputElement(e.target as HTMLElement) || e.target === this.filterOnTypeDomNode) - .filter(e => e.key !== 'Dead' && !/^Media/.test(e.key)) - .map(e => new StandardKeyboardEvent(e)) - .filter(this.keyboardNavigationEventFilter || (() => true)) - .filter(() => this.automaticKeyboardNavigation || this.triggered) - .filter(e => (this.keyboardNavigationDelegate.mightProducePrintableCharacter(e) && !(e.keyCode === KeyCode.DownArrow || e.keyCode === KeyCode.UpArrow || e.keyCode === KeyCode.LeftArrow || e.keyCode === KeyCode.RightArrow)) || ((this.pattern.length > 0 || this.triggered) && ((e.keyCode === KeyCode.Escape || e.keyCode === KeyCode.Backspace) && !e.altKey && !e.ctrlKey && !e.metaKey) || (e.keyCode === KeyCode.Backspace && (isMacintosh ? (e.altKey && !e.metaKey) : e.ctrlKey) && !e.shiftKey))) - .forEach(e => { e.stopPropagation(); e.preventDefault(); }) - .event; - - const onClearClick = this.enabledDisposables.add(new DomEmitter(this.clearDomNode, 'click')); + this._mode = mode; - Event.chain(Event.any(onKeyDown, onClearClick.event)) - .event(this.onEventOrInput, this, this.enabledDisposables); + if (this.widget) { + this.widget.mode = this._mode; + } - this.filter.pattern = ''; this.tree.refilter(); this.render(); - this._enabled = true; - this.triggered = false; + this._onDidChangeMode.fire(mode); + } + + private widget: FindWidget | undefined; + private styles: IFindWidgetStyles | undefined; + private width = 0; + + private readonly _onDidChangeMode = new Emitter(); + readonly onDidChangeMode = this._onDidChangeMode.event; + + private readonly _onDidChangePattern = new Emitter(); + readonly onDidChangePattern = this._onDidChangePattern.event; + + private readonly _onDidChangeOpenState = new Emitter(); + readonly onDidChangeOpenState = this._onDidChangeOpenState.event; + + private enabledDisposables = new DisposableStore(); + private readonly disposables = new DisposableStore(); + + constructor( + private tree: AbstractTree, + model: ITreeModel, + private view: List>, + private filter: FindFilter, + private readonly contextViewProvider: IContextViewProvider + ) { + this._mode = tree.options.defaultFindMode ?? TreeFindMode.Highlight; + model.onDidSplice(this.onDidSpliceModel, this, this.disposables); } - private disable(): void { - if (!this._enabled) { + open(): void { + if (this.widget) { + this.widget.focus(); + this.widget.select(); return; } - this.domNode.remove(); - this.enabledDisposables.clear(); - this.tree.refilter(); - this.render(); - this._enabled = false; - this.triggered = false; + this.widget = new FindWidget(this.view.getHTMLElement(), this.tree, this.contextViewProvider, this._mode, this.styles); + this.enabledDisposables.add(this.widget); + + this.widget.onDidChangeValue(this.onDidChangeValue, this, this.enabledDisposables); + this.widget.onDidChangeMode(mode => this.mode = mode, undefined, this.enabledDisposables); + this.widget.onDidDisable(this.close, this, this.enabledDisposables); + + this.widget.layout(this.width); + this.widget.focus(); + + this._onDidChangeOpenState.fire(true); } - private onEventOrInput(e: MouseEvent | StandardKeyboardEvent | string): void { - if (typeof e === 'string') { - this.onInput(e); - } else if (e instanceof MouseEvent || e.keyCode === KeyCode.Escape || (e.keyCode === KeyCode.Backspace && (isMacintosh ? e.altKey : e.ctrlKey))) { - this.onInput(''); - } else if (e.keyCode === KeyCode.Backspace) { - this.onInput(this.pattern.length === 0 ? '' : this.pattern.substr(0, this.pattern.length - 1)); - } else { - this.onInput(this.pattern + e.browserEvent.key); + close(): void { + if (!this.widget) { + return; } - } - private onInput(pattern: string): void { - const container = this.view.getHTMLElement(); + this.widget = undefined; - if (pattern && !this.domNode.parentElement) { - container.append(this.domNode); - } else if (!pattern && this.domNode.parentElement) { - this.domNode.remove(); - this.tree.domFocus(); - } + this.enabledDisposables.dispose(); + this.enabledDisposables = new DisposableStore(); + this.onDidChangeValue(''); + this.tree.domFocus(); + + this._onDidChangeOpenState.fire(false); + } + + private onDidChangeValue(pattern: string): void { this._pattern = pattern; this._onDidChangePattern.fire(pattern); @@ -836,75 +927,10 @@ class TypeFilterController implements IDisposable { } this.render(); - - if (!pattern) { - this.triggered = false; - } - } - - private onDragStart(): void { - const container = this.view.getHTMLElement(); - const { left } = getDomNodePagePosition(container); - const containerWidth = container.clientWidth; - const midContainerWidth = containerWidth / 2; - const width = this.domNode.clientWidth; - const disposables = new DisposableStore(); - let positionClassName = this.positionClassName; - - const updatePosition = () => { - switch (positionClassName) { - case 'nw': - this.domNode.style.top = `4px`; - this.domNode.style.left = `4px`; - break; - case 'ne': - this.domNode.style.top = `4px`; - this.domNode.style.left = `${containerWidth - width - 6}px`; - break; - } - }; - - const onDragOver = (event: DragEvent) => { - event.preventDefault(); // needed so that the drop event fires (https://stackoverflow.com/questions/21339924/drop-event-not-firing-in-chrome) - - const x = event.clientX - left; - if (event.dataTransfer) { - event.dataTransfer.dropEffect = 'none'; - } - - if (x < midContainerWidth) { - positionClassName = 'nw'; - } else { - positionClassName = 'ne'; - } - - updatePosition(); - }; - - const onDragEnd = () => { - this.positionClassName = positionClassName; - this.domNode.className = `monaco-list-type-filter ${this.positionClassName}`; - this.domNode.style.top = ''; - this.domNode.style.left = ''; - - dispose(disposables); - }; - - updatePosition(); - this.domNode.classList.remove(positionClassName); - - this.domNode.classList.add('dragging'); - disposables.add(toDisposable(() => this.domNode.classList.remove('dragging'))); - - disposables.add(addDisposableListener(document, 'dragover', e => onDragOver(e))); - disposables.add(addDisposableListener(this.domNode, 'dragend', () => onDragEnd())); - - StaticDND.CurrentDragAndDropData = new DragAndDropData('vscode-ui'); - disposables.add(toDisposable(() => StaticDND.CurrentDragAndDropData = undefined)); } private onDidSpliceModel(): void { - if (!this._enabled || this.pattern.length === 0) { + if (!this.widget || this.pattern.length === 0) { return; } @@ -912,46 +938,18 @@ class TypeFilterController implements IDisposable { this.render(); } - private onDidChangeFilterOnType(): void { - this.tree.updateOptions({ filterOnType: this.filterOnTypeDomNode.checked }); - this.tree.refilter(); - this.tree.domFocus(); - this.render(); - this.updateFilterOnTypeTitleAndIcon(); - } - - private updateFilterOnTypeTitleAndIcon(): void { - if (this.filterOnType) { - this.filterOnTypeDomNode.classList.remove(...Codicon.treeFilterOnTypeOff.classNamesArray); - this.filterOnTypeDomNode.classList.add(...Codicon.treeFilterOnTypeOn.classNamesArray); - this.filterOnTypeDomNode.title = localize('disable filter on type', "Disable Filter on Type"); - } else { - this.filterOnTypeDomNode.classList.remove(...Codicon.treeFilterOnTypeOn.classNamesArray); - this.filterOnTypeDomNode.classList.add(...Codicon.treeFilterOnTypeOff.classNamesArray); - this.filterOnTypeDomNode.title = localize('enable filter on type', "Enable Filter on Type"); - } - } - private render(): void { const noMatches = this.filter.totalCount > 0 && this.filter.matchCount === 0; - if (this.pattern && this.tree.options.filterOnType && noMatches) { - this.messageDomNode.textContent = localize('empty', "No elements found"); - this._empty = true; + if (this.pattern && noMatches) { + this.widget?.showMessage({ type: MessageType.WARNING, content: localize('not found', "No elements found.") }); } else { - this.messageDomNode.innerText = ''; - this._empty = false; + this.widget?.clearMessage(); } - - this.domNode.classList.toggle('no-matches', noMatches); - this.domNode.title = localize('found', "Matched {0} out of {1} elements", this.filter.matchCount, this.filter.totalCount); - this.labelDomNode.textContent = this.pattern.length > 16 ? '…' + this.pattern.substr(this.pattern.length - 16) : this.pattern; - - this._onDidChangeEmptyState.fire(this._empty); } shouldAllowFocus(node: ITreeNode): boolean { - if (!this.enabled || !this.pattern || this.filterOnType) { + if (!this.widget || !this.pattern || this._mode === TreeFindMode.Filter) { return true; } @@ -962,16 +960,20 @@ class TypeFilterController implements IDisposable { return !FuzzyScore.isDefault(node.filterData as any as FuzzyScore); } - dispose() { - if (this._enabled) { - this.domNode.remove(); - this.enabledDisposables.dispose(); - this._enabled = false; - this.triggered = false; - } + style(styles: IFindWidgetStyles): void { + this.styles = styles; + this.widget?.style(styles); + } + + layout(width: number): void { + this.width = width; + this.widget?.layout(width); + } + dispose() { this._onDidChangePattern.dispose(); - dispose(this.disposables); + this.enabledDisposables.dispose(); + this.disposables.dispose(); } } @@ -982,6 +984,8 @@ function asTreeMouseEvent(event: IListMouseEvent>): ITreeMo target = TreeMouseEventTarget.Twistie; } else if (hasParentWithClass(event.browserEvent.target as HTMLElement, 'monaco-tl-contents', 'monaco-tl-row')) { target = TreeMouseEventTarget.Element; + } else if (hasParentWithClass(event.browserEvent.target as HTMLElement, 'monaco-tree-type-filter', 'monaco-list')) { + target = TreeMouseEventTarget.Filter; } return { @@ -1005,9 +1009,9 @@ export interface IKeyboardNavigationEventFilter { export interface IAbstractTreeOptionsUpdate extends ITreeRendererOptions { readonly multipleSelectionSupport?: boolean; - readonly automaticKeyboardNavigation?: boolean; - readonly simpleKeyboardNavigation?: boolean; - readonly filterOnType?: boolean; + readonly typeNavigationEnabled?: boolean; + readonly typeNavigationMode?: TypeNavigationMode; + readonly defaultFindMode?: TreeFindMode; readonly smoothScrolling?: boolean; readonly horizontalScrolling?: boolean; readonly mouseWheelScrollSensitivity?: number; @@ -1017,6 +1021,7 @@ export interface IAbstractTreeOptionsUpdate extends ITreeRendererOptions { } export interface IAbstractTreeOptions extends IAbstractTreeOptionsUpdate, IListOptions { + readonly contextViewProvider?: IContextViewProvider; readonly collapseByDefault?: boolean; // defaults to false readonly filter?: ITreeFilter; readonly dnd?: ITreeDragAndDrop; @@ -1318,7 +1323,8 @@ export abstract class AbstractTree implements IDisposable private selection: Trait; private anchor: Trait; private eventBufferer = new EventBufferer(); - private typeFilterController?: TypeFilterController; + private findController?: FindController; + readonly onDidChangeFindOpenState: Event = Event.None; private focusNavigationFilter: ((node: ITreeNode) => boolean) | undefined; private styleElement: HTMLStyleElement; protected readonly disposables = new DisposableStore(); @@ -1329,7 +1335,7 @@ export abstract class AbstractTree implements IDisposable get onDidChangeSelection(): Event> { return this.eventBufferer.wrapEvent(this.selection.onDidChange); } get onMouseClick(): Event> { return Event.map(this.view.onMouseClick, asTreeMouseEvent); } - get onMouseDblClick(): Event> { return Event.map(this.view.onMouseDblClick, asTreeMouseEvent); } + get onMouseDblClick(): Event> { return Event.filter(Event.map(this.view.onMouseDblClick, asTreeMouseEvent), e => e.target !== TreeMouseEventTarget.Filter); } get onContextMenu(): Event> { return Event.map(this.view.onContextMenu, asTreeContextMenuEvent); } get onTap(): Event> { return Event.map(this.view.onTap, asTreeMouseEvent); } get onPointer(): Event> { return Event.map(this.view.onPointer, asTreeMouseEvent); } @@ -1348,8 +1354,11 @@ export abstract class AbstractTree implements IDisposable private readonly _onWillRefilter = new Emitter(); readonly onWillRefilter: Event = this._onWillRefilter.event; - get filterOnType(): boolean { return !!this._options.filterOnType; } - get onDidChangeTypeFilterPattern(): Event { return this.typeFilterController ? this.typeFilterController.onDidChangePattern : Event.None; } + get findMode(): TreeFindMode { return this.findController?.mode ?? TreeFindMode.Highlight; } + set findMode(findMode: TreeFindMode) { if (this.findController) { this.findController.mode = findMode; } } + readonly onDidChangeFindMode: Event; + + get onDidChangeFindPattern(): Event { return this.findController ? this.findController.onDidChangePattern : Event.None; } get expandOnDoubleClick(): boolean { return typeof this._options.expandOnDoubleClick === 'undefined' ? true : this._options.expandOnDoubleClick; } get expandOnlyOnTwistieClick(): boolean | ((e: T) => boolean) { return typeof this._options.expandOnlyOnTwistieClick === 'undefined' ? true : this._options.expandOnlyOnTwistieClick; } @@ -1376,10 +1385,10 @@ export abstract class AbstractTree implements IDisposable this.disposables.add(r); } - let filter: TypeFilter | undefined; + let filter: FindFilter | undefined; if (_options.keyboardNavigationLabelProvider) { - filter = new TypeFilter(this, _options.keyboardNavigationLabelProvider, _options.filter as any as ITreeFilter); + filter = new FindFilter(this, _options.keyboardNavigationLabelProvider, _options.filter as any as ITreeFilter); _options = { ..._options, filter: filter as ITreeFilter }; // TODO need typescript help here this.disposables.add(filter); } @@ -1432,11 +1441,14 @@ export abstract class AbstractTree implements IDisposable onKeyDown.filter(e => e.keyCode === KeyCode.Space).on(this.onSpace, this, this.disposables); } - if (_options.keyboardNavigationLabelProvider) { - const delegate = _options.keyboardNavigationDelegate || DefaultKeyboardNavigationDelegate; - this.typeFilterController = new TypeFilterController(this, this.model, this.view, filter!, delegate); - this.focusNavigationFilter = node => this.typeFilterController!.shouldAllowFocus(node); - this.disposables.add(this.typeFilterController!); + if (_options.keyboardNavigationLabelProvider && _options.contextViewProvider) { + this.findController = new FindController(this, this.model, this.view, filter!, _options.contextViewProvider); + this.focusNavigationFilter = node => this.findController!.shouldAllowFocus(node); + this.onDidChangeFindOpenState = this.findController.onDidChangeOpenState; + this.disposables.add(this.findController!); + this.onDidChangeFindMode = this.findController.onDidChangeMode; + } else { + this.onDidChangeFindMode = Event.None; } this.styleElement = createStyleSheet(this.view.getHTMLElement()); @@ -1450,13 +1462,7 @@ export abstract class AbstractTree implements IDisposable renderer.updateOptions(optionsUpdate); } - this.view.updateOptions({ - ...this._options, - enableKeyboardNavigation: this._options.simpleKeyboardNavigation, - }); - - this.typeFilterController?.updateOptions(this._options); - + this.view.updateOptions(this._options); this._onDidUpdateOptions.fire(this._options); this.getHTMLElement().classList.toggle('always', this._options.renderIndentGuides === RenderIndentGuides.Always); @@ -1483,21 +1489,11 @@ export abstract class AbstractTree implements IDisposable } get contentHeight(): number { - if (this.typeFilterController && this.typeFilterController.filterOnType && this.typeFilterController.empty) { - return 100; - } - return this.view.contentHeight; } get onDidChangeContentHeight(): Event { - let result = this.view.onDidChangeContentHeight; - - if (this.typeFilterController) { - result = Event.any(result, Event.map(this.typeFilterController.onDidChangeEmptyState, () => this.contentHeight)); - } - - return result; + return this.view.onDidChangeContentHeight; } get scrollTop(): number { @@ -1559,6 +1555,10 @@ export abstract class AbstractTree implements IDisposable layout(height?: number, width?: number): void { this.view.layout(height, width); + + if (isNumber(width)) { + this.findController?.layout(width); + } } style(styles: IListStyles): void { @@ -1571,6 +1571,8 @@ export abstract class AbstractTree implements IDisposable } this.styleElement.textContent = content.join('\n'); + + this.findController?.style(styles); this.view.style(styles); } @@ -1624,12 +1626,16 @@ export abstract class AbstractTree implements IDisposable return this.model.isCollapsed(location); } - toggleKeyboardNavigation(): void { - this.view.toggleKeyboardNavigation(); + triggerTypeNavigation(): void { + this.view.triggerTypeNavigation(); + } - if (this.typeFilterController) { - this.typeFilterController.toggle(); - } + openFind(): void { + this.findController?.open(); + } + + closeFind(): void { + this.findController?.close(); } refilter(): void { diff --git a/src/vs/base/browser/ui/tree/asyncDataTree.ts b/src/vs/base/browser/ui/tree/asyncDataTree.ts index 64b6abe79ce8f..48cc343fc1be3 100644 --- a/src/vs/base/browser/ui/tree/asyncDataTree.ts +++ b/src/vs/base/browser/ui/tree/asyncDataTree.ts @@ -7,7 +7,7 @@ import { IDragAndDropData } from 'vs/base/browser/dnd'; import { IIdentityProvider, IListDragAndDrop, IListDragOverReaction, IListVirtualDelegate } from 'vs/base/browser/ui/list/list'; import { ElementsDragAndDropData } from 'vs/base/browser/ui/list/listView'; import { IListStyles } from 'vs/base/browser/ui/list/listWidget'; -import { ComposedTreeDelegate, IAbstractTreeOptions, IAbstractTreeOptionsUpdate } from 'vs/base/browser/ui/tree/abstractTree'; +import { ComposedTreeDelegate, TreeFindMode as TreeFindMode, IAbstractTreeOptions, IAbstractTreeOptionsUpdate } from 'vs/base/browser/ui/tree/abstractTree'; import { ICompressedTreeElement, ICompressedTreeNode } from 'vs/base/browser/ui/tree/compressedObjectTreeModel'; import { getVisibleState, isFilterResult } from 'vs/base/browser/ui/tree/indexTreeModel'; import { CompressibleObjectTree, ICompressibleKeyboardNavigationLabelProvider, ICompressibleObjectTreeOptions, ICompressibleTreeRenderer, IObjectTreeOptions, IObjectTreeSetChildrenOptions, ObjectTree } from 'vs/base/browser/ui/tree/objectTree'; @@ -341,7 +341,12 @@ export class AsyncDataTree implements IDisposable get onDidUpdateOptions(): Event { return this.tree.onDidUpdateOptions; } - get filterOnType(): boolean { return this.tree.filterOnType; } + get onDidChangeFindOpenState(): Event { return this.tree.onDidChangeFindOpenState; } + + get findMode(): TreeFindMode { return this.tree.findMode; } + set findMode(mode: TreeFindMode) { this.tree.findMode = mode; } + readonly onDidChangeFindMode: Event; + get expandOnlyOnTwistieClick(): boolean | ((e: T) => boolean) { if (typeof this.tree.expandOnlyOnTwistieClick === 'boolean') { return this.tree.expandOnlyOnTwistieClick; @@ -367,6 +372,7 @@ export class AsyncDataTree implements IDisposable this.collapseByDefault = options.collapseByDefault; this.tree = this.createTree(user, container, delegate, renderers, options); + this.onDidChangeFindMode = this.tree.onDidChangeFindMode; this.root = createAsyncDataTreeNode({ element: undefined!, @@ -616,8 +622,16 @@ export class AsyncDataTree implements IDisposable return this.tree.isCollapsed(this.getDataNode(element)); } - toggleKeyboardNavigation(): void { - this.tree.toggleKeyboardNavigation(); + triggerTypeNavigation(): void { + this.tree.triggerTypeNavigation(); + } + + openFind(): void { + this.tree.openFind(); + } + + closeFind(): void { + this.tree.closeFind(); } refilter(): void { diff --git a/src/vs/base/browser/ui/tree/media/tree.css b/src/vs/base/browser/ui/tree/media/tree.css index 22f0d23bf60f0..f44e796a572cf 100644 --- a/src/vs/base/browser/ui/tree/media/tree.css +++ b/src/vs/base/browser/ui/tree/media/tree.css @@ -67,3 +67,45 @@ /* Use steps to throttle FPS to reduce CPU usage */ animation: codicon-spin 1.25s steps(30) infinite; } + +.monaco-tree-type-filter { + position: absolute; + top: 0; + display: flex; + padding: 3px; + transition: top 0.3s; + width: 160px; + z-index: 100; +} + +.monaco-tree-type-filter.disabled { + top: -40px; +} + +.monaco-tree-type-filter-grab { + display: flex !important; + align-items: center; + justify-content: center; + cursor: grab; +} + +.monaco-tree-type-filter-grab.grabbing { + cursor: grabbing; +} + +.monaco-tree-type-filter-input { + flex: 1; +} + +.monaco-tree-type-filter-input .monaco-inputbox > .ibwrapper > .input, +.monaco-tree-type-filter-input .monaco-inputbox > .ibwrapper > .mirror { + padding: 2px; +} + +.monaco-tree-type-filter-actionbar { + margin-left: 4px; +} + +.monaco-tree-type-filter-actionbar .monaco-action-bar .action-label { + padding: 2px; +} diff --git a/src/vs/base/browser/ui/tree/tree.ts b/src/vs/base/browser/ui/tree/tree.ts index 0166e4cd3b6d5..f29091c104a9d 100644 --- a/src/vs/base/browser/ui/tree/tree.ts +++ b/src/vs/base/browser/ui/tree/tree.ts @@ -141,7 +141,8 @@ export interface ITreeEvent { export enum TreeMouseEventTarget { Unknown, Twistie, - Element + Element, + Filter } export interface ITreeMouseEvent { diff --git a/src/vs/platform/list/browser/listService.ts b/src/vs/platform/list/browser/listService.ts index 2447e50aafe05..eca74c211c794 100644 --- a/src/vs/platform/list/browser/listService.ts +++ b/src/vs/platform/list/browser/listService.ts @@ -4,12 +4,13 @@ *--------------------------------------------------------------------------------------------*/ import { createStyleSheet } from 'vs/base/browser/dom'; +import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview'; import { IListMouseEvent, IListRenderer, IListTouchEvent, IListVirtualDelegate } from 'vs/base/browser/ui/list/list'; import { IPagedListOptions, IPagedRenderer, PagedList } from 'vs/base/browser/ui/list/listPaging'; -import { DefaultStyleController, IListAccessibilityProvider, IListOptions, IListOptionsUpdate, IMultipleSelectionController, isSelectionRangeChangeEvent, isSelectionSingleChangeEvent, List } from 'vs/base/browser/ui/list/listWidget'; +import { DefaultStyleController, IListAccessibilityProvider, IListOptions, IListOptionsUpdate, IMultipleSelectionController, isSelectionRangeChangeEvent, isSelectionSingleChangeEvent, List, TypeNavigationMode } from 'vs/base/browser/ui/list/listWidget'; import { ITableColumn, ITableRenderer, ITableVirtualDelegate } from 'vs/base/browser/ui/table/table'; import { ITableOptions, ITableOptionsUpdate, Table } from 'vs/base/browser/ui/table/tableWidget'; -import { IAbstractTreeOptions, IAbstractTreeOptionsUpdate, IKeyboardNavigationEventFilter, RenderIndentGuides } from 'vs/base/browser/ui/tree/abstractTree'; +import { TreeFindMode, IAbstractTreeOptions, IAbstractTreeOptionsUpdate, IKeyboardNavigationEventFilter, RenderIndentGuides } from 'vs/base/browser/ui/tree/abstractTree'; import { AsyncDataTree, CompressibleAsyncDataTree, IAsyncDataTreeOptions, IAsyncDataTreeOptionsUpdate, ICompressibleAsyncDataTreeOptions, ICompressibleAsyncDataTreeOptionsUpdate, ITreeCompressionDelegate } from 'vs/base/browser/ui/tree/asyncDataTree'; import { DataTree, IDataTreeOptions } from 'vs/base/browser/ui/tree/dataTree'; import { CompressibleObjectTree, ICompressibleObjectTreeOptions, ICompressibleObjectTreeOptionsUpdate, ICompressibleTreeRenderer, IObjectTreeOptions, ObjectTree } from 'vs/base/browser/ui/tree/objectTree'; @@ -17,13 +18,13 @@ import { IAsyncDataSource, IDataSource, ITreeEvent, ITreeRenderer } from 'vs/bas import { Emitter, Event } from 'vs/base/common/event'; import { combinedDisposable, Disposable, DisposableStore, dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { localize } from 'vs/nls'; -import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry'; import { ContextKeyExpr, IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys'; +import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; import { IEditorOptions } from 'vs/platform/editor/common/editor'; -import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; +import { createDecorator, IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { Registry } from 'vs/platform/registry/common/platform'; import { attachListStyler, computeStyles, defaultListStyles, IColorMapping } from 'vs/platform/theme/common/styler'; @@ -112,7 +113,7 @@ export class ListService implements IListService { } } -const RawWorkbenchListFocusContextKey = new RawContextKey('listFocus', true); +export const RawWorkbenchListFocusContextKey = new RawContextKey('listFocus', true); export const WorkbenchListSupportsMultiSelectContextKey = new RawContextKey('listSupportsMultiselect', true); export const WorkbenchListFocusContextKey = ContextKeyExpr.and(RawWorkbenchListFocusContextKey, ContextKeyExpr.not(InputFocusedContextKey)); export const WorkbenchListHasSelectionOrFocus = new RawContextKey('listHasSelectionOrFocus', false); @@ -123,7 +124,13 @@ export const WorkbenchTreeElementCanCollapse = new RawContextKey('treeE export const WorkbenchTreeElementHasParent = new RawContextKey('treeElementHasParent', false); export const WorkbenchTreeElementCanExpand = new RawContextKey('treeElementCanExpand', false); export const WorkbenchTreeElementHasChild = new RawContextKey('treeElementHasChild', false); -export const WorkbenchListAutomaticKeyboardNavigationKey = 'listAutomaticKeyboardNavigation'; +export const WorkbenchTreeFindOpen = new RawContextKey('treeFindOpen', false); +const WorkbenchListTypeNavigationModeKey = 'listTypeNavigationMode'; + +/** + * @deprecated in favor of WorkbenchListTypeNavigationModeKey + */ +const WorkbenchListAutomaticKeyboardNavigationLegacyKey = 'listAutomaticKeyboardNavigation'; function createScopedContextKeyService(contextKeyService: IContextKeyService, widget: ListWidget): IContextKeyService { const result = contextKeyService.createScoped(widget.getHTMLElement()); @@ -134,8 +141,9 @@ function createScopedContextKeyService(contextKeyService: IContextKeyService, wi const multiSelectModifierSettingKey = 'workbench.list.multiSelectModifier'; const openModeSettingKey = 'workbench.list.openMode'; const horizontalScrollingKey = 'workbench.list.horizontalScrolling'; +const defaultFindModeSettingKey = 'workbench.list.defaultFindMode'; +/** @deprecated in favor of workbench.list.defaultFindMode */ const keyboardNavigationSettingKey = 'workbench.list.keyboardNavigation'; -const automaticKeyboardNavigationSettingKey = 'workbench.list.automaticKeyboardNavigation'; const treeIndentKey = 'workbench.tree.indent'; const treeRenderIndentGuidesKey = 'workbench.tree.renderIndentGuides'; const listSmoothScrolling = 'workbench.list.smoothScrolling'; @@ -840,17 +848,16 @@ export class WorkbenchObjectTree, TFilterData = void> delegate: IListVirtualDelegate, renderers: ITreeRenderer[], options: IWorkbenchObjectTreeOptions, + @IInstantiationService instantiationService: IInstantiationService, @IContextKeyService contextKeyService: IContextKeyService, @IListService listService: IListService, @IThemeService themeService: IThemeService, - @IConfigurationService configurationService: IConfigurationService, - @IKeybindingService keybindingService: IKeybindingService, - @IAccessibilityService accessibilityService: IAccessibilityService + @IConfigurationService configurationService: IConfigurationService ) { - const { options: treeOptions, getAutomaticKeyboardNavigation, disposable } = workbenchTreeDataPreamble>(container, options, contextKeyService, configurationService, keybindingService, accessibilityService); + const { options: treeOptions, getTypeNavigationMode, disposable } = instantiationService.invokeFunction(workbenchTreeDataPreamble, container, options as any); super(user, container, delegate, renderers, treeOptions); this.disposables.add(disposable); - this.internals = new WorkbenchTreeInternals(this, options, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService); + this.internals = new WorkbenchTreeInternals(this, options, getTypeNavigationMode, options.overrideStyles, contextKeyService, listService, themeService, configurationService); this.disposables.add(this.internals); } @@ -882,17 +889,16 @@ export class WorkbenchCompressibleObjectTree, TFilter delegate: IListVirtualDelegate, renderers: ICompressibleTreeRenderer[], options: IWorkbenchCompressibleObjectTreeOptions, + @IInstantiationService instantiationService: IInstantiationService, @IContextKeyService contextKeyService: IContextKeyService, @IListService listService: IListService, @IThemeService themeService: IThemeService, - @IConfigurationService configurationService: IConfigurationService, - @IKeybindingService keybindingService: IKeybindingService, - @IAccessibilityService accessibilityService: IAccessibilityService + @IConfigurationService configurationService: IConfigurationService ) { - const { options: treeOptions, getAutomaticKeyboardNavigation, disposable } = workbenchTreeDataPreamble>(container, options, contextKeyService, configurationService, keybindingService, accessibilityService); + const { options: treeOptions, getTypeNavigationMode, disposable } = instantiationService.invokeFunction(workbenchTreeDataPreamble, container, options as any); super(user, container, delegate, renderers, treeOptions); this.disposables.add(disposable); - this.internals = new WorkbenchTreeInternals(this, options, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService); + this.internals = new WorkbenchTreeInternals(this, options, getTypeNavigationMode, options.overrideStyles, contextKeyService, listService, themeService, configurationService); this.disposables.add(this.internals); } @@ -930,17 +936,16 @@ export class WorkbenchDataTree extends DataTree[], dataSource: IDataSource, options: IWorkbenchDataTreeOptions, + @IInstantiationService instantiationService: IInstantiationService, @IContextKeyService contextKeyService: IContextKeyService, @IListService listService: IListService, @IThemeService themeService: IThemeService, - @IConfigurationService configurationService: IConfigurationService, - @IKeybindingService keybindingService: IKeybindingService, - @IAccessibilityService accessibilityService: IAccessibilityService + @IConfigurationService configurationService: IConfigurationService ) { - const { options: treeOptions, getAutomaticKeyboardNavigation, disposable } = workbenchTreeDataPreamble>(container, options, contextKeyService, configurationService, keybindingService, accessibilityService); + const { options: treeOptions, getTypeNavigationMode, disposable } = instantiationService.invokeFunction(workbenchTreeDataPreamble, container, options as any); super(user, container, delegate, renderers, dataSource, treeOptions); this.disposables.add(disposable); - this.internals = new WorkbenchTreeInternals(this, options, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService); + this.internals = new WorkbenchTreeInternals(this, options, getTypeNavigationMode, options.overrideStyles, contextKeyService, listService, themeService, configurationService); this.disposables.add(this.internals); } @@ -978,17 +983,16 @@ export class WorkbenchAsyncDataTree extends Async renderers: ITreeRenderer[], dataSource: IAsyncDataSource, options: IWorkbenchAsyncDataTreeOptions, + @IInstantiationService instantiationService: IInstantiationService, @IContextKeyService contextKeyService: IContextKeyService, @IListService listService: IListService, @IThemeService themeService: IThemeService, - @IConfigurationService configurationService: IConfigurationService, - @IKeybindingService keybindingService: IKeybindingService, - @IAccessibilityService accessibilityService: IAccessibilityService + @IConfigurationService configurationService: IConfigurationService ) { - const { options: treeOptions, getAutomaticKeyboardNavigation, disposable } = workbenchTreeDataPreamble>(container, options, contextKeyService, configurationService, keybindingService, accessibilityService); + const { options: treeOptions, getTypeNavigationMode, disposable } = instantiationService.invokeFunction(workbenchTreeDataPreamble, container, options as any); super(user, container, delegate, renderers, dataSource, treeOptions); this.disposables.add(disposable); - this.internals = new WorkbenchTreeInternals(this, options, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService); + this.internals = new WorkbenchTreeInternals(this, options, getTypeNavigationMode, options.overrideStyles, contextKeyService, listService, themeService, configurationService); this.disposables.add(this.internals); } @@ -1024,17 +1028,16 @@ export class WorkbenchCompressibleAsyncDataTree e renderers: ICompressibleTreeRenderer[], dataSource: IAsyncDataSource, options: IWorkbenchCompressibleAsyncDataTreeOptions, + @IInstantiationService instantiationService: IInstantiationService, @IContextKeyService contextKeyService: IContextKeyService, @IListService listService: IListService, @IThemeService themeService: IThemeService, - @IConfigurationService configurationService: IConfigurationService, - @IKeybindingService keybindingService: IKeybindingService, - @IAccessibilityService accessibilityService: IAccessibilityService + @IConfigurationService configurationService: IConfigurationService ) { - const { options: treeOptions, getAutomaticKeyboardNavigation, disposable } = workbenchTreeDataPreamble>(container, options, contextKeyService, configurationService, keybindingService, accessibilityService); + const { options: treeOptions, getTypeNavigationMode, disposable } = instantiationService.invokeFunction(workbenchTreeDataPreamble, container, options as any); super(user, container, virtualDelegate, compressionDelegate, renderers, dataSource, treeOptions); this.disposables.add(disposable); - this.internals = new WorkbenchTreeInternals(this, options, getAutomaticKeyboardNavigation, options.overrideStyles, contextKeyService, listService, themeService, configurationService, accessibilityService); + this.internals = new WorkbenchTreeInternals(this, options, getTypeNavigationMode, options.overrideStyles, contextKeyService, listService, themeService, configurationService); this.disposables.add(this.internals); } @@ -1044,33 +1047,62 @@ export class WorkbenchCompressibleAsyncDataTree e } } +function getDefaultTreeFindMode(configurationService: IConfigurationService) { + const value = configurationService.getValue<'highlight' | 'filter'>(defaultFindModeSettingKey); + + if (value === 'highlight') { + return TreeFindMode.Highlight; + } else if (value === 'filter') { + return TreeFindMode.Filter; + } + + const deprecatedValue = configurationService.getValue<'simple' | 'highlight' | 'filter'>(keyboardNavigationSettingKey); + + if (deprecatedValue === 'simple' || deprecatedValue === 'highlight') { + return TreeFindMode.Highlight; + } else if (deprecatedValue === 'filter') { + return TreeFindMode.Filter; + } + + return undefined; +} + function workbenchTreeDataPreamble | IAsyncDataTreeOptions>( + accessor: ServicesAccessor, container: HTMLElement, options: TOptions, - contextKeyService: IContextKeyService, - configurationService: IConfigurationService, - keybindingService: IKeybindingService, - accessibilityService: IAccessibilityService, -): { options: TOptions; getAutomaticKeyboardNavigation: () => boolean | undefined; disposable: IDisposable } { - const getAutomaticKeyboardNavigation = () => { - // give priority to the context key value to disable this completely - let automaticKeyboardNavigation = Boolean(contextKeyService.getContextKeyValue(WorkbenchListAutomaticKeyboardNavigationKey)); - - if (automaticKeyboardNavigation) { - automaticKeyboardNavigation = Boolean(configurationService.getValue(automaticKeyboardNavigationSettingKey)); +): { options: TOptions; getTypeNavigationMode: () => TypeNavigationMode | undefined; disposable: IDisposable } { + const configurationService = accessor.get(IConfigurationService); + const keybindingService = accessor.get(IKeybindingService); + const contextViewService = accessor.get(IContextViewService); + const contextKeyService = accessor.get(IContextKeyService); + + const getTypeNavigationMode = () => { + // give priority to the context key value to specify a value + const modeString = contextKeyService.getContextKeyValue<'automatic' | 'trigger'>(WorkbenchListTypeNavigationModeKey); + + if (modeString === 'automatic') { + return TypeNavigationMode.Automatic; + } else if (modeString === 'trigger') { + return TypeNavigationMode.Trigger; + } + + // also check the deprecated context key to set the mode to 'trigger' + const modeBoolean = contextKeyService.getContextKeyValue(WorkbenchListAutomaticKeyboardNavigationLegacyKey); + + if (modeBoolean === false) { + return TypeNavigationMode.Trigger; } - return automaticKeyboardNavigation; + return undefined; }; - const accessibilityOn = accessibilityService.isScreenReaderOptimized(); - const keyboardNavigation = options.simpleKeyboardNavigation || accessibilityOn ? 'simple' : configurationService.getValue(keyboardNavigationSettingKey); const horizontalScrolling = options.horizontalScrolling !== undefined ? options.horizontalScrolling : Boolean(configurationService.getValue(horizontalScrollingKey)); const [workbenchListOptions, disposable] = toWorkbenchListOptions(options, configurationService, keybindingService); const additionalScrollHeight = options.additionalScrollHeight; return { - getAutomaticKeyboardNavigation, + getTypeNavigationMode, disposable, options: { // ...options, // TODO@Joao why is this not splatted here? @@ -1079,14 +1111,13 @@ function workbenchTreeDataPreamble(treeRenderIndentGuidesKey), smoothScrolling: Boolean(configurationService.getValue(listSmoothScrolling)), - automaticKeyboardNavigation: getAutomaticKeyboardNavigation(), - simpleKeyboardNavigation: keyboardNavigation === 'simple', - filterOnType: keyboardNavigation === 'filter', + defaultFindMode: getDefaultTreeFindMode(configurationService), horizontalScrolling, keyboardNavigationEventFilter: createKeyboardNavigationEventFilter(container, keybindingService), additionalScrollHeight, hideTwistiesOfChildlessElements: options.hideTwistiesOfChildlessElements, - expandOnlyOnTwistieClick: options.expandOnlyOnTwistieClick ?? (configurationService.getValue<'singleClick' | 'doubleClick'>(treeExpandMode) === 'doubleClick') + expandOnlyOnTwistieClick: options.expandOnlyOnTwistieClick ?? (configurationService.getValue<'singleClick' | 'doubleClick'>(treeExpandMode) === 'doubleClick'), + contextViewProvider: contextViewService as IContextViewProvider } as TOptions }; } @@ -1106,6 +1137,7 @@ class WorkbenchTreeInternals { private treeElementHasParent: IContextKey; private treeElementCanExpand: IContextKey; private treeElementHasChild: IContextKey; + private treeFindOpen: IContextKey; private _useAltAsMultipleSelectionModifier: boolean; private disposables: IDisposable[] = []; private styler: IDisposable | undefined; @@ -1116,13 +1148,12 @@ class WorkbenchTreeInternals { constructor( private tree: WorkbenchObjectTree | WorkbenchCompressibleObjectTree | WorkbenchDataTree | WorkbenchAsyncDataTree | WorkbenchCompressibleAsyncDataTree, options: IWorkbenchObjectTreeOptions | IWorkbenchCompressibleObjectTreeOptions | IWorkbenchDataTreeOptions | IWorkbenchAsyncDataTreeOptions | IWorkbenchCompressibleAsyncDataTreeOptions, - getAutomaticKeyboardNavigation: () => boolean | undefined, + getTypeNavigationMode: () => TypeNavigationMode | undefined, overrideStyles: IColorMapping | undefined, @IContextKeyService contextKeyService: IContextKeyService, @IListService listService: IListService, @IThemeService private themeService: IThemeService, - @IConfigurationService configurationService: IConfigurationService, - @IAccessibilityService accessibilityService: IAccessibilityService, + @IConfigurationService configurationService: IConfigurationService ) { this.contextKeyService = createScopedContextKeyService(contextKeyService, tree); @@ -1140,20 +1171,10 @@ class WorkbenchTreeInternals { this.treeElementHasParent = WorkbenchTreeElementHasParent.bindTo(this.contextKeyService); this.treeElementCanExpand = WorkbenchTreeElementCanExpand.bindTo(this.contextKeyService); this.treeElementHasChild = WorkbenchTreeElementHasChild.bindTo(this.contextKeyService); + this.treeFindOpen = WorkbenchTreeFindOpen.bindTo(this.contextKeyService); this._useAltAsMultipleSelectionModifier = useAltAsMultipleSelectionModifier(configurationService); - const interestingContextKeys = new Set(); - interestingContextKeys.add(WorkbenchListAutomaticKeyboardNavigationKey); - const updateKeyboardNavigation = () => { - const accessibilityOn = accessibilityService.isScreenReaderOptimized(); - const keyboardNavigation = accessibilityOn ? 'simple' : configurationService.getValue(keyboardNavigationSettingKey); - tree.updateOptions({ - simpleKeyboardNavigation: keyboardNavigation === 'simple', - filterOnType: keyboardNavigation === 'filter' - }); - }; - this.updateStyleOverrides(overrideStyles); const updateCollapseContextKeys = () => { @@ -1170,6 +1191,10 @@ class WorkbenchTreeInternals { this.treeElementHasChild.set(!!tree.getFirstElementChild(focus)); }; + const interestingContextKeys = new Set(); + interestingContextKeys.add(WorkbenchListTypeNavigationModeKey); + interestingContextKeys.add(WorkbenchListAutomaticKeyboardNavigationLegacyKey); + this.disposables.push( this.contextKeyService, (listService as ListService).register(tree), @@ -1192,6 +1217,7 @@ class WorkbenchTreeInternals { }), tree.onDidChangeCollapseState(updateCollapseContextKeys), tree.onDidChangeModel(updateCollapseContextKeys), + tree.onDidChangeFindOpenState(enabled => this.treeFindOpen.set(enabled)), configurationService.onDidChangeConfiguration(e => { let newOptions: IAbstractTreeOptionsUpdate = {}; if (e.affectsConfiguration(multiSelectModifierSettingKey)) { @@ -1209,11 +1235,8 @@ class WorkbenchTreeInternals { const smoothScrolling = Boolean(configurationService.getValue(listSmoothScrolling)); newOptions = { ...newOptions, smoothScrolling }; } - if (e.affectsConfiguration(keyboardNavigationSettingKey)) { - updateKeyboardNavigation(); - } - if (e.affectsConfiguration(automaticKeyboardNavigationSettingKey)) { - newOptions = { ...newOptions, automaticKeyboardNavigation: getAutomaticKeyboardNavigation() }; + if (e.affectsConfiguration(defaultFindModeSettingKey) || e.affectsConfiguration(keyboardNavigationSettingKey)) { + tree.updateOptions({ defaultFindMode: getDefaultTreeFindMode(configurationService) }); } if (e.affectsConfiguration(horizontalScrollingKey) && options.horizontalScrolling === undefined) { const horizontalScrolling = Boolean(configurationService.getValue(horizontalScrollingKey)); @@ -1236,10 +1259,9 @@ class WorkbenchTreeInternals { }), this.contextKeyService.onDidChangeContext(e => { if (e.affectsSome(interestingContextKeys)) { - tree.updateOptions({ automaticKeyboardNavigation: getAutomaticKeyboardNavigation() }); + tree.updateOptions({ typeNavigationMode: getTypeNavigationMode() }); } - }), - accessibilityService.onDidChangeScreenReaderOptimized(() => updateKeyboardNavigation()) + }) ); this.navigator = new TreeResourceNavigator(tree, { configurationService, ...options }); @@ -1334,6 +1356,16 @@ configurationRegistry.registerConfiguration({ default: 5, description: localize('Fast Scroll Sensitivity', "Scrolling speed multiplier when pressing `Alt`.") }, + [defaultFindModeSettingKey]: { + type: 'string', + enum: ['highlight', 'filter'], + enumDescriptions: [ + localize('defaultFindModeSettingKey.highlight', "Highlight elements when searching. Further up and down navigation will traverse only the highlighted elements."), + localize('defaultFindModeSettingKey.filter', "Filter elements when searching.") + ], + default: 'highlight', + description: localize('defaultFindModeSettingKey', "Controls the default find mode for lists and trees in the workbench.") + }, [keyboardNavigationSettingKey]: { type: 'string', enum: ['simple', 'highlight', 'filter'], @@ -1343,12 +1375,9 @@ configurationRegistry.registerConfiguration({ localize('keyboardNavigationSettingKey.filter', "Filter keyboard navigation will filter out and hide all the elements which do not match the keyboard input.") ], default: 'highlight', - description: localize('keyboardNavigationSettingKey', "Controls the keyboard navigation style for lists and trees in the workbench. Can be simple, highlight and filter.") - }, - [automaticKeyboardNavigationSettingKey]: { - type: 'boolean', - default: true, - markdownDescription: localize('automatic keyboard navigation setting', "Controls whether keyboard navigation in lists and trees is automatically triggered simply by typing. If set to `false`, keyboard navigation is only triggered when executing the `list.toggleKeyboardNavigation` command, for which you can assign a keyboard shortcut.") + description: localize('keyboardNavigationSettingKey', "Controls the keyboard navigation style for lists and trees in the workbench. Can be simple, highlight and filter."), + deprecated: true, + deprecationMessage: localize('keyboardNavigationSettingKeyDeprecated', "Please use 'workbench.list.defaultFindMode' instead.") }, [treeExpandMode]: { type: 'string', diff --git a/src/vs/platform/theme/common/colorRegistry.ts b/src/vs/platform/theme/common/colorRegistry.ts index 2d169de15502f..b26f20b529de6 100644 --- a/src/vs/platform/theme/common/colorRegistry.ts +++ b/src/vs/platform/theme/common/colorRegistry.ts @@ -445,9 +445,10 @@ export const listFocusHighlightForeground = registerColor('list.focusHighlightFo export const listInvalidItemForeground = registerColor('list.invalidItemForeground', { dark: '#B89500', light: '#B89500', hcDark: '#B89500', hcLight: '#B5200D' }, nls.localize('invalidItemForeground', 'List/Tree foreground color for invalid items, for example an unresolved root in explorer.')); export const listErrorForeground = registerColor('list.errorForeground', { dark: '#F88070', light: '#B01011', hcDark: null, hcLight: null }, nls.localize('listErrorForeground', 'Foreground color of list items containing errors.')); export const listWarningForeground = registerColor('list.warningForeground', { dark: '#CCA700', light: '#855F00', hcDark: null, hcLight: null }, nls.localize('listWarningForeground', 'Foreground color of list items containing warnings.')); -export const listFilterWidgetBackground = registerColor('listFilterWidget.background', { light: '#efc1ad', dark: '#653723', hcDark: Color.black, hcLight: Color.white }, nls.localize('listFilterWidgetBackground', 'Background color of the type filter widget in lists and trees.')); +export const listFilterWidgetBackground = registerColor('listFilterWidget.background', { light: darken(editorWidgetBackground, 0), dark: lighten(editorWidgetBackground, 0), hcDark: editorWidgetBackground, hcLight: editorWidgetBackground }, nls.localize('listFilterWidgetBackground', 'Background color of the type filter widget in lists and trees.')); export const listFilterWidgetOutline = registerColor('listFilterWidget.outline', { dark: Color.transparent, light: Color.transparent, hcDark: '#f38518', hcLight: '#007ACC' }, nls.localize('listFilterWidgetOutline', 'Outline color of the type filter widget in lists and trees.')); export const listFilterWidgetNoMatchesOutline = registerColor('listFilterWidget.noMatchesOutline', { dark: '#BE1100', light: '#BE1100', hcDark: contrastBorder, hcLight: contrastBorder }, nls.localize('listFilterWidgetNoMatchesOutline', 'Outline color of the type filter widget in lists and trees, when there are no matches.')); +export const listFilterWidgetShadow = registerColor('listFilterWidget.shadow', { dark: widgetShadow, light: widgetShadow, hcDark: widgetShadow, hcLight: widgetShadow }, nls.localize('listFilterWidgetShadow', 'Shadown color of the type filter widget in lists and trees.')); export const listFilterMatchHighlight = registerColor('list.filterMatchBackground', { dark: editorFindMatchHighlight, light: editorFindMatchHighlight, hcDark: null, hcLight: null }, nls.localize('listFilterMatchHighlight', 'Background color of the filtered match.')); export const listFilterMatchHighlightBorder = registerColor('list.filterMatchBorder', { dark: editorFindMatchHighlightBorder, light: editorFindMatchHighlightBorder, hcDark: contrastBorder, hcLight: activeContrastBorder }, nls.localize('listFilterMatchHighlightBorder', 'Border color of the filtered match.')); export const treeIndentGuidesStroke = registerColor('tree.indentGuidesStroke', { dark: '#585858', light: '#a9a9a9', hcDark: '#a9a9a9', hcLight: '#a5a5a5' }, nls.localize('treeIndentGuidesStroke', "Tree stroke color for the indentation guides.")); diff --git a/src/vs/platform/theme/common/styler.ts b/src/vs/platform/theme/common/styler.ts index 8a073beaee685..ea7724499c92a 100644 --- a/src/vs/platform/theme/common/styler.ts +++ b/src/vs/platform/theme/common/styler.ts @@ -6,7 +6,7 @@ import { Color } from 'vs/base/common/color'; import { IDisposable } from 'vs/base/common/lifecycle'; import { IThemable, styleFn } from 'vs/base/common/styler'; -import { activeContrastBorder, badgeBackground, badgeForeground, breadcrumbsActiveSelectionForeground, breadcrumbsBackground, breadcrumbsFocusForeground, breadcrumbsForeground, buttonBackground, buttonBorder, buttonForeground, buttonHoverBackground, buttonSecondaryBackground, buttonSecondaryForeground, buttonSecondaryHoverBackground, ColorIdentifier, ColorTransform, ColorValue, contrastBorder, editorWidgetBackground, editorWidgetBorder, editorWidgetForeground, focusBorder, inputActiveOptionBackground, inputActiveOptionBorder, inputActiveOptionForeground, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationInfoForeground, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationWarningForeground, keybindingLabelBackground, keybindingLabelBorder, keybindingLabelBottomBorder, keybindingLabelForeground, listActiveSelectionBackground, listActiveSelectionForeground, listActiveSelectionIconForeground, listDropBackground, listFilterWidgetBackground, listFilterWidgetNoMatchesOutline, listFilterWidgetOutline, listFocusBackground, listFocusForeground, listFocusOutline, listHoverBackground, listHoverForeground, listInactiveFocusBackground, listInactiveFocusOutline, listInactiveSelectionBackground, listInactiveSelectionForeground, listInactiveSelectionIconForeground, menuBackground, menuBorder, menuForeground, menuSelectionBackground, menuSelectionBorder, menuSelectionForeground, menuSeparatorBackground, pickerGroupForeground, problemsErrorIconForeground, problemsInfoIconForeground, problemsWarningIconForeground, progressBarBackground, quickInputListFocusBackground, quickInputListFocusForeground, quickInputListFocusIconForeground, resolveColorValue, scrollbarShadow, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, selectBackground, selectBorder, selectForeground, selectListBackground, checkboxBackground, checkboxBorder, checkboxForeground, tableColumnsBorder, tableOddRowsBackgroundColor, textLinkForeground, treeIndentGuidesStroke, widgetShadow, listFocusAndSelectionOutline, buttonSeparator } from 'vs/platform/theme/common/colorRegistry'; +import { activeContrastBorder, badgeBackground, badgeForeground, breadcrumbsActiveSelectionForeground, breadcrumbsBackground, breadcrumbsFocusForeground, breadcrumbsForeground, buttonBackground, buttonBorder, buttonForeground, buttonHoverBackground, buttonSecondaryBackground, buttonSecondaryForeground, buttonSecondaryHoverBackground, ColorIdentifier, ColorTransform, ColorValue, contrastBorder, editorWidgetBackground, editorWidgetBorder, editorWidgetForeground, focusBorder, inputActiveOptionBackground, inputActiveOptionBorder, inputActiveOptionForeground, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationInfoForeground, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationWarningForeground, keybindingLabelBackground, keybindingLabelBorder, keybindingLabelBottomBorder, keybindingLabelForeground, listActiveSelectionBackground, listActiveSelectionForeground, listActiveSelectionIconForeground, listDropBackground, listFilterWidgetBackground, listFilterWidgetNoMatchesOutline, listFilterWidgetOutline, listFocusBackground, listFocusForeground, listFocusOutline, listHoverBackground, listHoverForeground, listInactiveFocusBackground, listInactiveFocusOutline, listInactiveSelectionBackground, listInactiveSelectionForeground, listInactiveSelectionIconForeground, menuBackground, menuBorder, menuForeground, menuSelectionBackground, menuSelectionBorder, menuSelectionForeground, menuSeparatorBackground, pickerGroupForeground, problemsErrorIconForeground, problemsInfoIconForeground, problemsWarningIconForeground, progressBarBackground, quickInputListFocusBackground, quickInputListFocusForeground, quickInputListFocusIconForeground, resolveColorValue, scrollbarShadow, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, selectBackground, selectBorder, selectForeground, selectListBackground, checkboxBackground, checkboxBorder, checkboxForeground, tableColumnsBorder, tableOddRowsBackgroundColor, textLinkForeground, treeIndentGuidesStroke, widgetShadow, listFocusAndSelectionOutline, listFilterWidgetShadow, buttonSeparator } from 'vs/platform/theme/common/colorRegistry'; import { isHighContrast } from 'vs/platform/theme/common/theme'; import { IColorTheme, IThemeService } from 'vs/platform/theme/common/themeService'; @@ -184,7 +184,7 @@ export interface IListStyleOverrides extends IStyleOverrides { listFilterWidgetBackground?: ColorIdentifier; listFilterWidgetOutline?: ColorIdentifier; listFilterWidgetNoMatchesOutline?: ColorIdentifier; - listMatchesShadow?: ColorIdentifier; + listFilterWidgetShadow?: ColorIdentifier; treeIndentGuidesStroke?: ColorIdentifier; tableColumnsBorder?: ColorIdentifier; tableOddRowsBackgroundColor?: ColorIdentifier; @@ -217,10 +217,25 @@ export const defaultListStyles: IColorMapping = { listFilterWidgetBackground, listFilterWidgetOutline, listFilterWidgetNoMatchesOutline, - listMatchesShadow: widgetShadow, + listFilterWidgetShadow, treeIndentGuidesStroke, tableColumnsBorder, - tableOddRowsBackgroundColor + tableOddRowsBackgroundColor, + inputActiveOptionBorder, + inputActiveOptionForeground, + inputActiveOptionBackground, + inputBackground, + inputForeground, + inputBorder, + inputValidationInfoBackground, + inputValidationInfoForeground, + inputValidationInfoBorder, + inputValidationWarningBackground, + inputValidationWarningForeground, + inputValidationWarningBorder, + inputValidationErrorBackground, + inputValidationErrorForeground, + inputValidationErrorBorder, }; export interface IButtonStyleOverrides extends IStyleOverrides { diff --git a/src/vs/workbench/browser/actions/listCommands.ts b/src/vs/workbench/browser/actions/listCommands.ts index f6f0db4d32869..ee4848ce1aef4 100644 --- a/src/vs/workbench/browser/actions/listCommands.ts +++ b/src/vs/workbench/browser/actions/listCommands.ts @@ -7,7 +7,7 @@ import { KeyMod, KeyCode } from 'vs/base/common/keyCodes'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { List } from 'vs/base/browser/ui/list/listWidget'; -import { WorkbenchListFocusContextKey, IListService, WorkbenchListSupportsMultiSelectContextKey, ListWidget, WorkbenchListHasSelectionOrFocus, getSelectionKeyboardEvent, WorkbenchListWidget, WorkbenchListSelectionNavigation, WorkbenchTreeElementCanCollapse, WorkbenchTreeElementHasParent, WorkbenchTreeElementHasChild, WorkbenchTreeElementCanExpand } from 'vs/platform/list/browser/listService'; +import { WorkbenchListFocusContextKey, IListService, WorkbenchListSupportsMultiSelectContextKey, ListWidget, WorkbenchListHasSelectionOrFocus, getSelectionKeyboardEvent, WorkbenchListWidget, WorkbenchListSelectionNavigation, WorkbenchTreeElementCanCollapse, WorkbenchTreeElementHasParent, WorkbenchTreeElementHasChild, WorkbenchTreeElementCanExpand, RawWorkbenchListFocusContextKey, WorkbenchTreeFindOpen } from 'vs/platform/list/browser/listService'; import { PagedList } from 'vs/base/browser/ui/list/listPaging'; import { equals, range } from 'vs/base/common/arrays'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; @@ -17,6 +17,7 @@ import { DataTree } from 'vs/base/browser/ui/tree/dataTree'; import { ITreeNode } from 'vs/base/browser/ui/tree/tree'; import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { Table } from 'vs/base/browser/ui/table/tableWidget'; +import { AbstractTree, TreeFindMode } from 'vs/base/browser/ui/tree/abstractTree'; function ensureDOMFocus(widget: ListWidget | undefined): void { // it can happen that one of the commands is executed while @@ -607,27 +608,62 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ }); CommandsRegistry.registerCommand({ - id: 'list.toggleKeyboardNavigation', + id: 'list.triggerTypeNavigation', handler: (accessor) => { const widget = accessor.get(IListService).lastFocusedList; - widget?.toggleKeyboardNavigation(); + widget?.triggerTypeNavigation(); } }); CommandsRegistry.registerCommand({ - id: 'list.toggleFilterOnType', + id: 'list.toggleFindMode', handler: (accessor) => { - const focused = accessor.get(IListService).lastFocusedList; + const widget = accessor.get(IListService).lastFocusedList; + + if (widget instanceof AbstractTree || widget instanceof AsyncDataTree) { + const tree = widget; + tree.findMode = tree.findMode === TreeFindMode.Filter ? TreeFindMode.Highlight : TreeFindMode.Filter; + } + } +}); + +// Deprecated commands +CommandsRegistry.registerCommandAlias('list.toggleKeyboardNavigation', 'list.triggerTypeNavigation'); +CommandsRegistry.registerCommandAlias('list.toggleFilterOnType', 'list.toggleFindMode'); + +KeybindingsRegistry.registerCommandAndKeybindingRule({ + id: 'list.find', + weight: KeybindingWeight.WorkbenchContrib, + when: RawWorkbenchListFocusContextKey, + primary: KeyMod.CtrlCmd | KeyCode.KeyF, + secondary: [KeyCode.F3], + handler: (accessor) => { + const widget = accessor.get(IListService).lastFocusedList; // List - if (focused instanceof List || focused instanceof PagedList || focused instanceof Table) { + if (widget instanceof List || widget instanceof PagedList || widget instanceof Table) { // TODO@joao } // Tree - else if (focused instanceof ObjectTree || focused instanceof DataTree || focused instanceof AsyncDataTree) { - const tree = focused; - tree.updateOptions({ filterOnType: !tree.filterOnType }); + else if (widget instanceof AbstractTree || widget instanceof AsyncDataTree) { + const tree = widget; + tree.openFind(); + } + } +}); + +KeybindingsRegistry.registerCommandAndKeybindingRule({ + id: 'list.closeFind', + weight: KeybindingWeight.WorkbenchContrib, + when: ContextKeyExpr.and(RawWorkbenchListFocusContextKey, WorkbenchTreeFindOpen), + primary: KeyCode.Escape, + handler: (accessor) => { + const widget = accessor.get(IListService).lastFocusedList; + + if (widget instanceof AbstractTree || widget instanceof AsyncDataTree) { + const tree = widget; + tree.closeFind(); } } }); diff --git a/src/vs/workbench/contrib/comments/browser/commentsTreeViewer.ts b/src/vs/workbench/contrib/comments/browser/commentsTreeViewer.ts index 020ef7eb4d1e5..42ebc26458d16 100644 --- a/src/vs/workbench/contrib/comments/browser/commentsTreeViewer.ts +++ b/src/vs/workbench/contrib/comments/browser/commentsTreeViewer.ts @@ -13,8 +13,6 @@ import { IResourceLabel, ResourceLabels } from 'vs/workbench/browser/labels'; import { CommentNode, CommentsModel, ResourceWithCommentThreads } from 'vs/workbench/contrib/comments/common/commentModel'; import { IAsyncDataSource, ITreeNode } from 'vs/base/browser/ui/tree/tree'; import { IListVirtualDelegate, IListRenderer } from 'vs/base/browser/ui/list/list'; -import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; -import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { WorkbenchAsyncDataTree, IListService, IWorkbenchAsyncDataTreeOptions } from 'vs/platform/list/browser/listService'; @@ -266,8 +264,6 @@ export class CommentsList extends WorkbenchAsyncDataTree { @IThemeService themeService: IThemeService, @IInstantiationService instantiationService: IInstantiationService, @IConfigurationService configurationService: IConfigurationService, - @IKeybindingService keybindingService: IKeybindingService, - @IAccessibilityService accessibilityService: IAccessibilityService ) { const delegate = new CommentsModelVirualDelegate(); const dataSource = new CommentsAsyncDataSource(); @@ -311,12 +307,11 @@ export class CommentsList extends WorkbenchAsyncDataTree { }, overrideStyles: options.overrideStyles }, + instantiationService, contextKeyService, listService, themeService, - configurationService, - keybindingService, - accessibilityService + configurationService ); } } diff --git a/src/vs/workbench/contrib/debug/browser/debugHover.ts b/src/vs/workbench/contrib/debug/browser/debugHover.ts index 21d65a90cb30b..6308c2b6c5b39 100644 --- a/src/vs/workbench/contrib/debug/browser/debugHover.ts +++ b/src/vs/workbench/contrib/debug/browser/debugHover.ts @@ -116,8 +116,6 @@ export class DebugHoverWidget implements IContentWidget { horizontalScrolling: true, useShadows: false, keyboardNavigationLabelProvider: { getKeyboardNavigationLabel: (e: IExpression) => e.name }, - filterOnType: false, - simpleKeyboardNavigation: true, overrideStyles: { listBackground: editorHoverBackground } diff --git a/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts b/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts index 1dc13b23fb775..5f9b197500147 100644 --- a/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts +++ b/src/vs/workbench/contrib/debug/browser/loadedScriptsView.ts @@ -39,6 +39,7 @@ import { IOpenerService } from 'vs/platform/opener/common/opener'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IPathService } from 'vs/workbench/services/path/common/pathService'; +import { TreeFindMode } from 'vs/base/browser/ui/tree/abstractTree'; const NEW_STYLE_COMPRESS = true; @@ -585,8 +586,8 @@ export class LoadedScriptsView extends ViewPane { // feature: expand all nodes when filtering (not when finding) let viewState: IViewState | undefined; - this._register(this.tree.onDidChangeTypeFilterPattern(pattern => { - if (!this.tree.options.filterOnType) { + this._register(this.tree.onDidChangeFindPattern(pattern => { + if (this.tree.findMode === TreeFindMode.Highlight) { return; } diff --git a/src/vs/workbench/contrib/extensions/browser/extensionsViewer.ts b/src/vs/workbench/contrib/extensions/browser/extensionsViewer.ts index e390f69494256..8ceb6a8e9eecb 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionsViewer.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionsViewer.ts @@ -14,10 +14,8 @@ import { IListService, WorkbenchAsyncDataTree } from 'vs/platform/list/browser/l import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IThemeService, registerThemingParticipant, IColorTheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService'; -import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; import { IAsyncDataSource, ITreeNode } from 'vs/base/browser/ui/tree/tree'; import { IListVirtualDelegate, IListRenderer } from 'vs/base/browser/ui/list/list'; -import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { CancellationToken } from 'vs/base/common/cancellation'; import { isNonEmptyArray } from 'vs/base/common/arrays'; import { IColorMapping } from 'vs/platform/theme/common/styler'; @@ -244,8 +242,6 @@ export class ExtensionsTree extends WorkbenchAsyncDataTree('listSupportsKeyboardNavigation', true); -export const WorkbenchListAutomaticKeyboardNavigation = new RawContextKey(WorkbenchListAutomaticKeyboardNavigationKey, true); - export class ListContext implements IWorkbenchContribution { constructor( @IContextKeyService contextKeyService: IContextKeyService ) { - WorkbenchListSupportsKeyboardNavigation.bindTo(contextKeyService); - WorkbenchListAutomaticKeyboardNavigation.bindTo(contextKeyService); + contextKeyService.createKey('listSupportsTypeNavigation', true); + + // @deprecated in favor of listSupportsTypeNavigation + contextKeyService.createKey('listSupportsKeyboardNavigation', true); } } diff --git a/src/vs/workbench/contrib/markers/browser/markersView.ts b/src/vs/workbench/contrib/markers/browser/markersView.ts index bf75c6804ca7f..1b322657c386a 100644 --- a/src/vs/workbench/contrib/markers/browser/markersView.ts +++ b/src/vs/workbench/contrib/markers/browser/markersView.ts @@ -40,7 +40,6 @@ import { IMarkerService, MarkerSeverity } from 'vs/platform/markers/common/marke import { withUndefinedAsNull } from 'vs/base/common/types'; import { MementoObject, Memento } from 'vs/workbench/common/memento'; import { IIdentityProvider, IListVirtualDelegate } from 'vs/base/browser/ui/list/list'; -import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; import { KeyCode } from 'vs/base/common/keyCodes'; import { editorLightBulbForeground, editorLightBulbAutoFixForeground } from 'vs/platform/theme/common/colorRegistry'; import { ViewPane, IViewPaneOptions } from 'vs/workbench/browser/parts/views/viewPane'; @@ -922,14 +921,13 @@ class MarkersTree extends WorkbenchObjectTree impleme delegate: IListVirtualDelegate, renderers: ITreeRenderer[], options: IWorkbenchObjectTreeOptions, + @IInstantiationService instantiationService: IInstantiationService, @IContextKeyService contextKeyService: IContextKeyService, @IListService listService: IListService, @IThemeService themeService: IThemeService, @IConfigurationService configurationService: IConfigurationService, - @IKeybindingService keybindingService: IKeybindingService, - @IAccessibilityService accessibilityService: IAccessibilityService ) { - super(user, container, delegate, renderers, options, contextKeyService, listService, themeService, configurationService, keybindingService, accessibilityService); + super(user, container, delegate, renderers, options, instantiationService, contextKeyService, listService, themeService, configurationService); this.visibilityContextKey = MarkersContextKeys.MarkersTreeVisibilityContextKey.bindTo(contextKeyService); } diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts index c0951594b1c6d..bfaa6a816605d 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts @@ -232,7 +232,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD keyboardSupport: false, mouseSupport: true, multipleSelectionSupport: false, - enableKeyboardNavigation: true, + typeNavigationEnabled: true, additionalScrollHeight: 0, // transformOptimization: (isMacintosh && isNative) || getTitleBarStyle(this.configurationService, this.environmentService) === 'native', styleController: (_suffix: string) => { return this._list!; }, diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffList.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffList.ts index 244f65f50ca7f..e98ae9b79f1fb 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffList.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffList.ts @@ -445,22 +445,6 @@ export class NotebookTextDiffList extends WorkbenchList { return this._list; }, diff --git a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts index b62e89274d020..ace2ec61b1baf 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts @@ -1393,22 +1393,6 @@ export class NotebookCellList extends WorkbenchList implements ID `); } - if (styles.listFilterWidgetBackground) { - content.push(`.monaco-list-type-filter { background-color: ${styles.listFilterWidgetBackground} }`); - } - - if (styles.listFilterWidgetOutline) { - content.push(`.monaco-list-type-filter { border: 1px solid ${styles.listFilterWidgetOutline}; }`); - } - - if (styles.listFilterWidgetNoMatchesOutline) { - content.push(`.monaco-list-type-filter.no-matches { border: 1px solid ${styles.listFilterWidgetNoMatchesOutline}; }`); - } - - if (styles.listMatchesShadow) { - content.push(`.monaco-list-type-filter { box-shadow: 1px 1px 1px ${styles.listMatchesShadow}; }`); - } - const newStyles = content.join('\n'); if (newStyles !== this.styleElement.textContent) { this.styleElement.textContent = newStyles; diff --git a/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts b/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts index 6b16b20461f1c..1d667408085a1 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts @@ -366,7 +366,6 @@ export function createNotebookCellList(instantiationService: TestInstantiationSe { supportDynamicHeights: true, multipleSelectionSupport: true, - enableKeyboardNavigation: true, focusNextPreviousDelegate: { onFocusNext: (applyFocusNext: () => void) => { applyFocusNext(); }, onFocusPrevious: (applyFocusPrevious: () => void) => { applyFocusPrevious(); }, diff --git a/src/vs/workbench/contrib/outline/browser/outlinePane.ts b/src/vs/workbench/contrib/outline/browser/outlinePane.ts index 8b8a7ab8180b6..d41777b2c546c 100644 --- a/src/vs/workbench/contrib/outline/browser/outlinePane.ts +++ b/src/vs/workbench/contrib/outline/browser/outlinePane.ts @@ -35,7 +35,7 @@ import { EditorResourceAccessor, IEditorPane } from 'vs/workbench/common/editor' import { CancellationTokenSource } from 'vs/base/common/cancellation'; import { Event } from 'vs/base/common/event'; import { ITreeSorter } from 'vs/base/browser/ui/tree/tree'; -import { AbstractTreeViewState, IAbstractTreeViewState } from 'vs/base/browser/ui/tree/abstractTree'; +import { AbstractTreeViewState, IAbstractTreeViewState, TreeFindMode } from 'vs/base/browser/ui/tree/abstractTree'; const _ctxFollowsCursor = new RawContextKey('outlineFollowsCursor', false); const _ctxFilterOnType = new RawContextKey('outlineFiltersOnType', false); @@ -259,7 +259,7 @@ export class OutlinePane extends ViewPane { expandOnlyOnTwistieClick: true, multipleSelectionSupport: false, hideTwistiesOfChildlessElements: true, - filterOnType: this._outlineViewState.filterOnType, + defaultFindMode: this._outlineViewState.filterOnType ? TreeFindMode.Filter : TreeFindMode.Highlight, overrideStyles: { listBackground: this.getBackgroundColor() } } ); @@ -286,6 +286,7 @@ export class OutlinePane extends ViewPane { }; updateTree(); this._editorControlDisposables.add(newOutline.onDidChange(updateTree)); + tree.findMode = this._outlineViewState.filterOnType ? TreeFindMode.Filter : TreeFindMode.Highlight; // feature: apply panel background to tree this._editorControlDisposables.add(this.viewDescriptorService.onDidChangeLocation(({ views }) => { @@ -295,7 +296,7 @@ export class OutlinePane extends ViewPane { })); // feature: filter on type - keep tree and menu in sync - this._editorControlDisposables.add(tree.onDidUpdateOptions(e => this._outlineViewState.filterOnType = Boolean(e.filterOnType))); + this._editorControlDisposables.add(tree.onDidChangeFindMode(mode => this._outlineViewState.filterOnType = mode === TreeFindMode.Filter)); // feature: reveal outline selection in editor // on change -> reveal/select defining range @@ -328,7 +329,7 @@ export class OutlinePane extends ViewPane { this._editorControlDisposables.add(this._outlineViewState.onDidChange((e: { followCursor?: boolean; sortBy?: boolean; filterOnType?: boolean }) => { this._outlineViewState.persist(this._storageService); if (e.filterOnType) { - tree.updateOptions({ filterOnType: this._outlineViewState.filterOnType }); + tree.findMode = this._outlineViewState.filterOnType ? TreeFindMode.Filter : TreeFindMode.Highlight; } if (e.followCursor) { revealActiveElement(); @@ -341,8 +342,8 @@ export class OutlinePane extends ViewPane { // feature: expand all nodes when filtering (not when finding) let viewState: AbstractTreeViewState | undefined; - this._editorControlDisposables.add(tree.onDidChangeTypeFilterPattern(pattern => { - if (!tree.options.filterOnType) { + this._editorControlDisposables.add(tree.onDidChangeFindPattern(pattern => { + if (tree.findMode === TreeFindMode.Highlight) { return; } if (!viewState && pattern) { diff --git a/src/vs/workbench/contrib/preferences/browser/settingsTree.ts b/src/vs/workbench/contrib/preferences/browser/settingsTree.ts index 16dd1bb7a51c6..39df9facda54c 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsTree.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsTree.ts @@ -54,7 +54,6 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema'; import { IList } from 'vs/base/browser/ui/tree/indexTreeModel'; import { IListService, WorkbenchObjectTree } from 'vs/platform/list/browser/listService'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; -import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; import { ILogService } from 'vs/platform/log/common/log'; import { settingsMoreActionIcon } from 'vs/workbench/contrib/preferences/browser/preferencesIcons'; import { IWorkbenchConfigurationService } from 'vs/workbench/services/configuration/common/configuration'; @@ -2334,8 +2333,6 @@ export class SettingsTree extends WorkbenchObjectTree { @IListService listService: IListService, @IThemeService themeService: IThemeService, @IConfigurationService configurationService: IConfigurationService, - @IKeybindingService keybindingService: IKeybindingService, - @IAccessibilityService accessibilityService: IAccessibilityService, @IInstantiationService instantiationService: IInstantiationService, @ILanguageService languageService: ILanguageService ) { @@ -2356,12 +2353,11 @@ export class SettingsTree extends WorkbenchObjectTree { smoothScrolling: configurationService.getValue('workbench.list.smoothScrolling'), multipleSelectionSupport: false, }, + instantiationService, contextKeyService, listService, themeService, configurationService, - keybindingService, - accessibilityService, ); this.disposables.add(registerThemingParticipant((theme: IColorTheme, collector: ICssStyleCollector) => { diff --git a/src/vs/workbench/contrib/preferences/browser/tocTree.ts b/src/vs/workbench/contrib/preferences/browser/tocTree.ts index 1451c190687c3..522b5e13b8002 100644 --- a/src/vs/workbench/contrib/preferences/browser/tocTree.ts +++ b/src/vs/workbench/contrib/preferences/browser/tocTree.ts @@ -9,11 +9,9 @@ import { DefaultStyleController, IListAccessibilityProvider } from 'vs/base/brow import { ITreeElement, ITreeNode, ITreeRenderer } from 'vs/base/browser/ui/tree/tree'; import { Iterable } from 'vs/base/common/iterator'; import { localize } from 'vs/nls'; -import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IListService, IWorkbenchObjectTreeOptions, WorkbenchObjectTree } from 'vs/platform/list/browser/listService'; import { editorBackground, focusBorder, foreground, transparent } from 'vs/platform/theme/common/colorRegistry'; import { attachStyler } from 'vs/platform/theme/common/styler'; @@ -203,8 +201,6 @@ export class TOCTree extends WorkbenchObjectTree { @IListService listService: IListService, @IThemeService themeService: IThemeService, @IConfigurationService configurationService: IConfigurationService, - @IKeybindingService keybindingService: IKeybindingService, - @IAccessibilityService accessibilityService: IAccessibilityService, @IInstantiationService instantiationService: IInstantiationService, ) { // test open mode @@ -231,12 +227,11 @@ export class TOCTree extends WorkbenchObjectTree { new TOCTreeDelegate(), [new TOCRenderer()], options, + instantiationService, contextKeyService, listService, themeService, configurationService, - keybindingService, - accessibilityService, ); this.disposables.add(attachStyler(themeService, { diff --git a/src/vs/workbench/contrib/testing/browser/testingExplorerView.ts b/src/vs/workbench/contrib/testing/browser/testingExplorerView.ts index 66ffbef2595cf..2281441286a78 100644 --- a/src/vs/workbench/contrib/testing/browser/testingExplorerView.ts +++ b/src/vs/workbench/contrib/testing/browser/testingExplorerView.ts @@ -485,7 +485,6 @@ export class TestingExplorerViewModel extends Disposable { instantiationService.createInstance(ErrorRenderer), ], { - simpleKeyboardNavigation: true, identityProvider: instantiationService.createInstance(IdentityProvider), hideTwistiesOfChildlessElements: false, sorter: instantiationService.createInstance(TreeSorter, this), From f9296c191e118f21f589a282705cab432b6c8388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Mon, 18 Jul 2022 16:44:01 +0200 Subject: [PATCH 121/121] Add telemetry comments (#155503) * add telemetry comments * update comments --- .../platform/update/electron-main/abstractUpdateService.ts | 3 ++- src/vs/platform/update/electron-main/updateService.darwin.ts | 3 ++- src/vs/workbench/api/common/extHostSCM.ts | 3 ++- src/vs/workbench/browser/parts/views/viewPane.ts | 5 +++-- .../services/extensions/browser/extensionUrlHandler.ts | 3 ++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/vs/platform/update/electron-main/abstractUpdateService.ts b/src/vs/platform/update/electron-main/abstractUpdateService.ts index 8d777b69a7e50..b451afc5eb2a5 100644 --- a/src/vs/platform/update/electron-main/abstractUpdateService.ts +++ b/src/vs/platform/update/electron-main/abstractUpdateService.ts @@ -20,7 +20,8 @@ export function createUpdateURL(platform: string, quality: string, productServic export type UpdateNotAvailableClassification = { owner: 'joaomoreno'; - explicit: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true }; + explicit: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'Whether the user has manually checked for updates, or this was an automatic check.' }; + comment: 'This is used to understand how often VS Code pings the update server for an update and there\'s none available.'; }; export abstract class AbstractUpdateService implements IUpdateService { diff --git a/src/vs/platform/update/electron-main/updateService.darwin.ts b/src/vs/platform/update/electron-main/updateService.darwin.ts index df08a4b796677..82802b4830fa1 100644 --- a/src/vs/platform/update/electron-main/updateService.darwin.ts +++ b/src/vs/platform/update/electron-main/updateService.darwin.ts @@ -93,7 +93,8 @@ export class DarwinUpdateService extends AbstractUpdateService { type UpdateDownloadedClassification = { owner: 'joaomoreno'; - version: { classification: 'SystemMetaData'; purpose: 'FeatureInsight' }; + version: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The version number of the new VS Code that has been downloaded.' }; + comment: 'This is used to know how often VS Code has successfully downloaded the update.'; }; this.telemetryService.publicLog2<{ version: String }, UpdateDownloadedClassification>('update:downloaded', { version: update.version }); diff --git a/src/vs/workbench/api/common/extHostSCM.ts b/src/vs/workbench/api/common/extHostSCM.ts index ee9ec8daf69ea..14f718832235d 100644 --- a/src/vs/workbench/api/common/extHostSCM.ts +++ b/src/vs/workbench/api/common/extHostSCM.ts @@ -745,7 +745,8 @@ export class ExtHostSCM implements ExtHostSCMShape { type TEvent = { extensionId: string }; type TMeta = { owner: 'joaomoreno'; - extensionId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight' }; + extensionId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The ID of the extension contributing to the Source Control API.' }; + comment: 'This is used to know what extensions contribute to the Source Control API.'; }; this._telemetry.$publicLog2('api/scm/createSourceControl', { extensionId: extension.identifier.value, diff --git a/src/vs/workbench/browser/parts/views/viewPane.ts b/src/vs/workbench/browser/parts/views/viewPane.ts index b8b9f5046ce13..22a0701865bdd 100644 --- a/src/vs/workbench/browser/parts/views/viewPane.ts +++ b/src/vs/workbench/browser/parts/views/viewPane.ts @@ -52,8 +52,9 @@ export interface IViewPaneOptions extends IPaneOptions { type WelcomeActionClassification = { owner: 'joaomoreno'; - viewId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight' }; - uri: { classification: 'SystemMetaData'; purpose: 'FeatureInsight' }; + viewId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The view ID in which the welcome view button was clicked.' }; + uri: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The URI of the command ran by the result of clicking the button.' }; + comment: 'This is used to know when users click on the welcome view buttons.'; }; const viewPaneContainerExpandedIcon = registerIcon('view-pane-container-expanded', Codicon.chevronDown, nls.localize('viewPaneContainerExpandedIcon', 'Icon for an expanded view pane container.')); diff --git a/src/vs/workbench/services/extensions/browser/extensionUrlHandler.ts b/src/vs/workbench/services/extensions/browser/extensionUrlHandler.ts index 41645b62f8464..fa54d7d9ecdee 100644 --- a/src/vs/workbench/services/extensions/browser/extensionUrlHandler.ts +++ b/src/vs/workbench/services/extensions/browser/extensionUrlHandler.ts @@ -83,7 +83,8 @@ export interface ExtensionUrlHandlerEvent { export interface ExtensionUrlHandlerClassification extends GDPRClassification { owner: 'joaomoreno'; - readonly extensionId: { classification: 'PublicNonPersonalData'; purpose: 'FeatureInsight' }; + readonly extensionId: { classification: 'PublicNonPersonalData'; purpose: 'FeatureInsight'; comment: 'The ID of the extension that should handle the URI' }; + comment: 'This is used to understand the drop funnel of extension URI handling by the OS & VS Code.'; } /**