Skip to content

Commit d792de9

Browse files
amiraliescristianoc
authored andcommitted
Extract get references to a separate function
1 parent 0019dc7 commit d792de9

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

server/src/server.ts

+3-21
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import * as chokidar from "chokidar";
1919
import { assert } from "console";
2020
import { fileURLToPath } from "url";
2121
import { ChildProcess } from "child_process";
22-
import { Location } from "vscode-languageserver";
23-
import { SymbolInformation, WorkspaceEdit } from "vscode-languageserver";
22+
import { WorkspaceEdit } from "vscode-languageserver";
2423
import { TextEdit } from "vscode-languageserver-types";
2524

2625
// https://microsoft.github.io/language-server-protocol/specification#initialize
@@ -392,16 +391,7 @@ function onMessage(msg: m.Message) {
392391
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename
393392
let params = msg.params as p.RenameParams;
394393
let filePath = fileURLToPath(params.textDocument.uri);
395-
let locations: Location[] | null = utils.runAnalysisAfterSanityCheck(
396-
filePath,
397-
[
398-
"references",
399-
filePath,
400-
params.position.line,
401-
params.position.character,
402-
]
403-
);
404-
394+
let locations: p.Location[] | null = utils.getReferencesForPosition(filePath, params.position);
405395
let result: WorkspaceEdit | null;
406396
if (locations === null) {
407397
result = null;
@@ -430,15 +420,7 @@ function onMessage(msg: m.Message) {
430420
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
431421
let params = msg.params as p.ReferenceParams;
432422
let filePath = fileURLToPath(params.textDocument.uri);
433-
let result: typeof p.ReferencesRequest.type = utils.runAnalysisAfterSanityCheck(
434-
filePath,
435-
[
436-
"references",
437-
filePath,
438-
params.position.line,
439-
params.position.character,
440-
]
441-
);
423+
let result: typeof p.ReferencesRequest.type = utils.getReferencesForPosition(filePath, params.position);
442424
let definitionResponse: m.ResponseMessage = {
443425
jsonrpc: c.jsonrpcVersion,
444426
id: msg.id,

server/src/utils.ts

+3
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ export let runAnalysisAfterSanityCheck = (
144144
return JSON.parse(stdout.toString());
145145
};
146146

147+
export let getReferencesForPosition = (filePath: p.DocumentUri, position: p.Position) =>
148+
runAnalysisAfterSanityCheck(filePath, ['references', filePath, position.line, position.character]);
149+
147150
export let replaceFileExtension = (filePath: string, ext: string): string => {
148151
let name = path.basename(filePath, path.extname(filePath));
149152
return path.format({ dir: path.dirname(filePath), name, ext })

0 commit comments

Comments
 (0)