From a7191852ea44055652b8c7ff84a2ecf63d5d5a55 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 5 Apr 2024 16:03:20 -0700 Subject: [PATCH] Enable links to locations within comment editors Makes sure that if you write a comment such as: ``` [ref] [ref]: http://example.com ``` Clicking on `ref` navigates to the definition instead of opening the comment contents in a new editor --- .../browser/commentsInputContentProvider.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/comments/browser/commentsInputContentProvider.ts b/src/vs/workbench/contrib/comments/browser/commentsInputContentProvider.ts index 200fd659b8790..7e7ee8ad821e4 100644 --- a/src/vs/workbench/contrib/comments/browser/commentsInputContentProvider.ts +++ b/src/vs/workbench/contrib/comments/browser/commentsInputContentProvider.ts @@ -6,11 +6,16 @@ import { Disposable } from 'vs/base/common/lifecycle'; import { Schemas } from 'vs/base/common/network'; import { URI } from 'vs/base/common/uri'; -import { IEditorContribution } from 'vs/editor/common/editorCommon'; +import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; +import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; +import { IEditorContribution, ScrollType } from 'vs/editor/common/editorCommon'; import { ILanguageService } from 'vs/editor/common/languages/language'; import { ITextModel } from 'vs/editor/common/model'; import { IModelService } from 'vs/editor/common/services/model'; import { ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService'; +import { ITextResourceEditorInput } from 'vs/platform/editor/common/editor'; +import { applyTextEditorOptions } from 'vs/workbench/common/editor/editorOptions'; +import { SimpleCommentEditor } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor'; export class CommentsInputContentProvider extends Disposable implements ITextModelContentProvider, IEditorContribution { @@ -18,11 +23,27 @@ export class CommentsInputContentProvider extends Disposable implements ITextMod constructor( @ITextModelService textModelService: ITextModelService, + @ICodeEditorService codeEditorService: ICodeEditorService, @IModelService private readonly _modelService: IModelService, @ILanguageService private readonly _languageService: ILanguageService, ) { super(); this._register(textModelService.registerTextModelContentProvider(Schemas.commentsInput, this)); + + this._register(codeEditorService.registerCodeEditorOpenHandler(async (input: ITextResourceEditorInput, editor: ICodeEditor | null, _sideBySide?: boolean): Promise => { + if (!(editor instanceof SimpleCommentEditor)) { + return null; + } + + if (editor.getModel()?.uri.toString() !== input.resource.toString()) { + return null; + } + + if (input.options) { + applyTextEditorOptions(input.options, editor, ScrollType.Immediate); + } + return editor; + })); } async provideTextContent(resource: URI): Promise {