Skip to content

Commit 6e8770c

Browse files
committed
fix: try-catch showDocument
1 parent 43e195d commit 6e8770c

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

lib/adapters/show-document-adapter.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,26 @@ export function attach(connection: LanguageClientConnection): void {
3131
* {@inheritDoc ShowDocumentParams}
3232
*/
3333
export async function showDocument(params: ShowDocumentParams): Promise<ShowDocumentResult> {
34-
if (!params.external) {
35-
// open using atom.workspace
36-
const view = await atom.workspace.open(params.uri, {
37-
activateItem: params.takeFocus,
38-
activatePane: params.takeFocus,
39-
pending: true,
40-
initialLine: params.selection?.start.line ?? 0,
41-
initialColumn: params.selection?.start.character ?? 0,
42-
})
43-
if (view instanceof TextEditor && params.selection !== undefined) {
44-
view.selectToBufferPosition(Convert.positionToPoint(params.selection.end))
34+
try {
35+
if (!params.external) {
36+
// open using atom.workspace
37+
const view = await atom.workspace.open(params.uri, {
38+
activateItem: params.takeFocus,
39+
activatePane: params.takeFocus,
40+
pending: true,
41+
initialLine: params.selection?.start.line ?? 0,
42+
initialColumn: params.selection?.start.character ?? 0,
43+
})
44+
if (view instanceof TextEditor && params.selection !== undefined) {
45+
view.selectToBufferPosition(Convert.positionToPoint(params.selection.end))
46+
}
47+
} else {
48+
// open using Electron
49+
shell.openExternal(params.uri, { activate: params.takeFocus })
4550
}
4651
return { success: true }
47-
} else {
48-
// open using Electron
49-
shell.openExternal(params.uri, { activate: params.takeFocus })
50-
return { success: true }
52+
} catch (e) {
53+
atom.notifications.addError(e)
54+
return { success: false }
5155
}
5256
}

0 commit comments

Comments
 (0)