Skip to content

Commit d27cd10

Browse files
committed
feat: Implement showTextDocument
1 parent de8ab4b commit d27cd10

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/services/WatchableConsoleWindow.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as monaco from 'monaco-editor'
12
import { MessageType, OutputChannel, Window, MessageActionItem, Emitter, Event, CancellationToken, CancellationTokenSource } from 'monaco-languageclient'
23
import swal from 'sweetalert'
34
import type * as vscode from 'vscode'
@@ -95,7 +96,7 @@ export default class WatchableConsoleWindow implements Window {
9596
return this.onDidChangeChannelsEmitter.event
9697
}
9798

98-
withProgress: typeof vscode.window.withProgress = async <R> (options: vscode.ProgressOptions, task: (progress: vscode.Progress<{ message?: string, increment?: number }>, token: CancellationToken) => PromiseLike<R>): Promise<R> => {
99+
withProgress: Window['withProgress'] = async <R> (options: vscode.ProgressOptions, task: (progress: vscode.Progress<{ message?: string, increment?: number }>, token: CancellationToken) => PromiseLike<R>): Promise<R> => {
99100
console.info('[LSP]', 'Starting task with progress:', options.location, options.title)
100101
try {
101102
return await task({
@@ -107,4 +108,23 @@ export default class WatchableConsoleWindow implements Window {
107108
console.info('[LSP]', 'Task completed:', options.title)
108109
}
109110
}
111+
112+
showTextDocument: Window['showTextDocument'] = async (document, options) => {
113+
const codeEditorService = monaco.extra.StandaloneServices.get(monaco.extra.ICodeEditorService)
114+
codeEditorService.getActiveCodeEditor()
115+
await codeEditorService.openCodeEditor({
116+
resource: document,
117+
options: {
118+
selection: options?.selection != null
119+
? {
120+
startLineNumber: options.selection.start.line,
121+
startColumn: options.selection.start.character,
122+
endLineNumber: options.selection.end.line,
123+
endColumn: options.selection.end.character
124+
}
125+
: undefined,
126+
selectionSource: monaco.extra.TextEditorSelectionSource.PROGRAMMATIC
127+
}
128+
}, null)
129+
}
110130
}

0 commit comments

Comments
 (0)