@@ -4,38 +4,47 @@ import { TextEditor } from "atom"
4
4
import Convert from "../convert"
5
5
6
6
/** Public: Adapts the window/showDocument command to Atom's text editors or external programs. */
7
- export default class ShowDocumentAdapter {
8
- /**
9
- * Public: Attach to a {LanguageClientConnection} to recieve requests to show documents.
10
- */
11
- public static attach ( connection : LanguageClientConnection ) : void {
12
- connection . onShowDocument ( ShowDocumentAdapter . onShowDocument )
7
+ export class ShowDocumentAdapter {
8
+ /** {@inheritDoc attach } */
9
+ public attach ( arg : Parameters < typeof attach > [ 0 ] ) : ReturnType < typeof attach > {
10
+ attach ( arg )
13
11
}
12
+ /** {@inheritDoc onShowDocument } */
13
+ public onShowDocument ( ...args : Parameters < typeof onShowDocument > ) : ReturnType < typeof onShowDocument > {
14
+ return onShowDocument ( ...args )
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Public: Attach to a {LanguageClientConnection} to recieve requests to show documents.
20
+ */
21
+ export function attach ( connection : LanguageClientConnection ) : void {
22
+ connection . onShowDocument ( onShowDocument )
23
+ }
14
24
15
- /**
16
- * Public: Show a notification message with buttons using the Atom notifications API.
17
- *
18
- * @param params The {ShowDocumentParams} received from the language server
19
- * indicating the document to be displayed as well as other metadata.
20
- */
21
- public static async onShowDocument ( params : ShowDocumentParams ) : Promise < ShowDocumentResult > {
22
- if ( ! params . external ) {
23
- // open using atom.workspace
24
- const view = await atom . workspace . open ( params . uri , {
25
- activateItem : params . takeFocus ,
26
- activatePane : params . takeFocus ,
27
- pending : true ,
28
- initialLine : params . selection ?. start . line ?? 0 ,
29
- initialColumn : params . selection ?. start . character ?? 0 ,
30
- } )
31
- if ( view instanceof TextEditor && params . selection != null ) {
32
- view . selectToBufferPosition ( Convert . positionToPoint ( params . selection . end ) )
33
- }
34
- return { success : true }
35
- } else {
36
- // open using Electron
37
- shell . openExternal ( params . uri , { activate : params . takeFocus } )
38
- return { success : true }
25
+ /**
26
+ * Public: Show a notification message with buttons using the Atom notifications API.
27
+ *
28
+ * @param params The {ShowDocumentParams} received from the language server
29
+ * indicating the document to be displayed as well as other metadata.
30
+ */
31
+ export async function onShowDocument ( params : ShowDocumentParams ) : Promise < ShowDocumentResult > {
32
+ if ( ! params . external ) {
33
+ // open using atom.workspace
34
+ const view = await atom . workspace . open ( params . uri , {
35
+ activateItem : params . takeFocus ,
36
+ activatePane : params . takeFocus ,
37
+ pending : true ,
38
+ initialLine : params . selection ?. start . line ?? 0 ,
39
+ initialColumn : params . selection ?. start . character ?? 0 ,
40
+ } )
41
+ if ( view instanceof TextEditor && params . selection != null ) {
42
+ view . selectToBufferPosition ( Convert . positionToPoint ( params . selection . end ) )
39
43
}
44
+ return { success : true }
45
+ } else {
46
+ // open using Electron
47
+ shell . openExternal ( params . uri , { activate : params . takeFocus } )
48
+ return { success : true }
40
49
}
41
50
}
0 commit comments