1
1
import { fileURLToPath } from "url" ;
2
2
import { RequestMessage } from "vscode-languageserver" ;
3
- import { CompletionItem , Hover , Location } from "vscode-languageserver-protocol" ;
3
+ import {
4
+ CompletionItem ,
5
+ Hover ,
6
+ Location ,
7
+ } from "vscode-languageserver-protocol" ;
4
8
import * as utils from "./utils" ;
5
- import * as path from "path" ;
6
9
import { execFileSync } from "child_process" ;
7
10
import fs from "fs" ;
8
-
9
- let binariesFolder = path . join (
10
- path . dirname ( __dirname ) ,
11
- "analysis_binaries"
12
- )
13
-
14
- // For local development and CI tests
15
- let currentPlatformBinaryPath = path . join (
16
- binariesFolder ,
17
- "current-platform.exe"
18
- ) ;
19
- // Platform-specific production binaries manually downloaded from CI
20
- let productionBinaryPath = path . join (
21
- binariesFolder ,
22
- process . platform + ".exe"
23
- ) ;
11
+ import {
12
+ analysisCurrentPlatformBinaryPath ,
13
+ analysisProductionBinaryPath ,
14
+ } from "./constants" ;
24
15
25
16
let findBinary = ( ) => {
26
- if ( fs . existsSync ( currentPlatformBinaryPath ) ) {
27
- return currentPlatformBinaryPath
28
- } else if ( fs . existsSync ( productionBinaryPath ) ) {
29
- return productionBinaryPath
17
+ if ( fs . existsSync ( analysisCurrentPlatformBinaryPath ) ) {
18
+ return analysisCurrentPlatformBinaryPath ;
19
+ } else if ( fs . existsSync ( analysisProductionBinaryPath ) ) {
20
+ return analysisProductionBinaryPath ;
30
21
} else {
31
- return null
22
+ return null ;
32
23
}
33
- }
34
-
35
- // export let binaryExists = fs.existsSync(binaryPath);
36
-
37
- // let findExecutable = (uri: string) => {
38
- // let filePath = fileURLToPath(uri);
39
- // let projectRootPath = utils.findProjectRootOfFile(filePath);
40
- // if (projectRootPath == null || !binaryExists) {
41
- // return null;
42
- // } else {
43
- // return {
44
- // binaryPath: binaryPath,
45
- // filePath: filePath,
46
- // cwd: projectRootPath,
47
- // };
48
- // }
49
- // };
50
-
51
- // type dumpCommandResult = {
52
- // hover?: string;
53
- // definition?: { uri?: string; range: any };
54
- // };
55
- // export function runDumpCommand(msg: RequestMessage): dumpCommandResult | null {
56
- // let executable = findExecutable(msg.params.textDocument.uri);
57
- // if (executable == null) {
58
- // return null;
59
- // }
60
-
61
- // let command =
62
- // executable.filePath +
63
- // ":" +
64
- // msg.params.position.line +
65
- // ":" +
66
- // msg.params.position.character;
67
-
68
- // try {
69
- // let stdout = execFileSync(executable.binaryPath, ["dump", command], {
70
- // cwd: executable.cwd,
71
- // });
72
- // let parsed = JSON.parse(stdout.toString());
73
- // if (parsed && parsed[0]) {
74
- // return parsed[0];
75
- // } else {
76
- // return null;
77
- // }
78
- // } catch (error) {
79
- // // TODO: @cristianoc any exception possible?
80
- // return null;
81
- // }
82
- // }
24
+ } ;
83
25
84
26
export function runCompletionCommand (
85
27
msg : RequestMessage ,
86
28
code : string
87
29
) : CompletionItem [ ] | null {
88
- let filePath = fileURLToPath ( msg . params . textDocument . uri )
30
+ let filePath = fileURLToPath ( msg . params . textDocument . uri ) ;
89
31
let projectRootPath = utils . findProjectRootOfFile ( filePath ) ;
90
32
let binaryPath = findBinary ( ) ;
91
33
if ( binaryPath == null || projectRootPath == null ) {
@@ -97,7 +39,13 @@ export function runCompletionCommand(
97
39
try {
98
40
let stdout = execFileSync (
99
41
binaryPath ,
100
- [ "complete" , filePath , msg . params . position . line , msg . params . position . character , tmpname ] ,
42
+ [
43
+ "complete" ,
44
+ filePath ,
45
+ msg . params . position . line ,
46
+ msg . params . position . character ,
47
+ tmpname ,
48
+ ] ,
101
49
{ cwd : projectRootPath }
102
50
) ;
103
51
return JSON . parse ( stdout . toString ( ) ) ;
@@ -109,10 +57,8 @@ export function runCompletionCommand(
109
57
}
110
58
}
111
59
112
- export function runHoverCommand (
113
- msg : RequestMessage ,
114
- ) : Hover | null {
115
- let filePath = fileURLToPath ( msg . params . textDocument . uri )
60
+ export function runHoverCommand ( msg : RequestMessage ) : Hover | null {
61
+ let filePath = fileURLToPath ( msg . params . textDocument . uri ) ;
116
62
let projectRootPath = utils . findProjectRootOfFile ( filePath ) ;
117
63
let binaryPath = findBinary ( ) ;
118
64
if ( binaryPath == null || projectRootPath == null ) {
@@ -122,7 +68,12 @@ export function runHoverCommand(
122
68
try {
123
69
let stdout = execFileSync (
124
70
binaryPath ,
125
- [ "hover" , filePath , msg . params . position . line , msg . params . position . character ] ,
71
+ [
72
+ "hover" ,
73
+ filePath ,
74
+ msg . params . position . line ,
75
+ msg . params . position . character ,
76
+ ] ,
126
77
{ cwd : projectRootPath }
127
78
) ;
128
79
return JSON . parse ( stdout . toString ( ) ) ;
@@ -132,10 +83,8 @@ export function runHoverCommand(
132
83
}
133
84
}
134
85
135
- export function runDefinitionCommand (
136
- msg : RequestMessage ,
137
- ) : Location | null {
138
- let filePath = fileURLToPath ( msg . params . textDocument . uri )
86
+ export function runDefinitionCommand ( msg : RequestMessage ) : Location | null {
87
+ let filePath = fileURLToPath ( msg . params . textDocument . uri ) ;
139
88
let projectRootPath = utils . findProjectRootOfFile ( filePath ) ;
140
89
let binaryPath = findBinary ( ) ;
141
90
if ( binaryPath == null || projectRootPath == null ) {
@@ -145,7 +94,12 @@ export function runDefinitionCommand(
145
94
try {
146
95
let stdout = execFileSync (
147
96
binaryPath ,
148
- [ "definition" , filePath , msg . params . position . line , msg . params . position . character ] ,
97
+ [
98
+ "definition" ,
99
+ filePath ,
100
+ msg . params . position . line ,
101
+ msg . params . position . character ,
102
+ ] ,
149
103
{ cwd : projectRootPath }
150
104
) ;
151
105
return JSON . parse ( stdout . toString ( ) ) ;
0 commit comments