Skip to content

Commit 0ccc8c6

Browse files
authored
Enable links to locations within comment editors (microsoft#209692)
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
1 parent 2a5d88d commit 0ccc8c6

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/vs/workbench/contrib/comments/browser/commentsInputContentProvider.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,44 @@
66
import { Disposable } from 'vs/base/common/lifecycle';
77
import { Schemas } from 'vs/base/common/network';
88
import { URI } from 'vs/base/common/uri';
9-
import { IEditorContribution } from 'vs/editor/common/editorCommon';
9+
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
10+
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
11+
import { IEditorContribution, ScrollType } from 'vs/editor/common/editorCommon';
1012
import { ILanguageService } from 'vs/editor/common/languages/language';
1113
import { ITextModel } from 'vs/editor/common/model';
1214
import { IModelService } from 'vs/editor/common/services/model';
1315
import { ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService';
16+
import { ITextResourceEditorInput } from 'vs/platform/editor/common/editor';
17+
import { applyTextEditorOptions } from 'vs/workbench/common/editor/editorOptions';
18+
import { SimpleCommentEditor } from 'vs/workbench/contrib/comments/browser/simpleCommentEditor';
1419

1520
export class CommentsInputContentProvider extends Disposable implements ITextModelContentProvider, IEditorContribution {
1621

1722
public static readonly ID = 'comments.input.contentProvider';
1823

1924
constructor(
2025
@ITextModelService textModelService: ITextModelService,
26+
@ICodeEditorService codeEditorService: ICodeEditorService,
2127
@IModelService private readonly _modelService: IModelService,
2228
@ILanguageService private readonly _languageService: ILanguageService,
2329
) {
2430
super();
2531
this._register(textModelService.registerTextModelContentProvider(Schemas.commentsInput, this));
32+
33+
this._register(codeEditorService.registerCodeEditorOpenHandler(async (input: ITextResourceEditorInput, editor: ICodeEditor | null, _sideBySide?: boolean): Promise<ICodeEditor | null> => {
34+
if (!(editor instanceof SimpleCommentEditor)) {
35+
return null;
36+
}
37+
38+
if (editor.getModel()?.uri.toString() !== input.resource.toString()) {
39+
return null;
40+
}
41+
42+
if (input.options) {
43+
applyTextEditorOptions(input.options, editor, ScrollType.Immediate);
44+
}
45+
return editor;
46+
}));
2647
}
2748

2849
async provideTextContent(resource: URI): Promise<ITextModel | null> {

0 commit comments

Comments
 (0)