Skip to content

Commit 38441c9

Browse files
committed
fix: use free functions instead of static methods
1 parent fabf882 commit 38441c9

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

lib/adapters/show-document-adapter.ts

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,47 @@ import { TextEditor } from "atom"
44
import Convert from "../convert"
55

66
/** 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)
1311
}
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+
}
1424

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))
3943
}
44+
return { success: true }
45+
} else {
46+
// open using Electron
47+
shell.openExternal(params.uri, { activate: params.takeFocus })
48+
return { success: true }
4049
}
4150
}

lib/auto-languageclient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import NotificationsAdapter from "./adapters/notifications-adapter"
2121
import OutlineViewAdapter from "./adapters/outline-view-adapter"
2222
import RenameAdapter from "./adapters/rename-adapter"
2323
import SignatureHelpAdapter from "./adapters/signature-help-adapter"
24-
import ShowDocumentAdapter from "./adapters/show-document-adapter"
24+
import * as ShowDocumentAdapter from "./adapters/show-document-adapter"
2525
import * as Utils from "./utils"
2626
import { Socket } from "net"
2727
import { LanguageClientConnection } from "./languageclient"

0 commit comments

Comments
 (0)