typescript-language-server 0.11.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/README.md +160 -27
- package/lib/calls.d.ts +3 -3
- package/lib/calls.d.ts.map +1 -1
- package/lib/calls.js +143 -195
- package/lib/calls.js.map +1 -1
- package/lib/cli.js +9 -33
- package/lib/cli.js.map +1 -1
- package/lib/commands.d.ts +1 -0
- package/lib/commands.d.ts.map +1 -1
- package/lib/commands.js +4 -5
- package/lib/commands.js.map +1 -1
- package/lib/completion.d.ts +8 -11
- package/lib/completion.d.ts.map +1 -1
- package/lib/completion.js +121 -163
- package/lib/completion.js.map +1 -1
- package/lib/configuration-manager.d.ts +47 -0
- package/lib/configuration-manager.d.ts.map +1 -0
- package/lib/configuration-manager.js +105 -0
- package/lib/configuration-manager.js.map +1 -0
- package/lib/diagnostic-queue.d.ts +10 -9
- package/lib/diagnostic-queue.d.ts.map +1 -1
- package/lib/diagnostic-queue.js +13 -21
- package/lib/diagnostic-queue.js.map +1 -1
- package/lib/document-symbol.d.ts +2 -2
- package/lib/document-symbol.d.ts.map +1 -1
- package/lib/document-symbol.js +20 -25
- package/lib/document-symbol.js.map +1 -1
- package/lib/document.d.ts +1 -1
- package/lib/document.d.ts.map +1 -1
- package/lib/document.js +6 -34
- package/lib/document.js.map +1 -1
- package/lib/features/fix-all.d.ts +4 -4
- package/lib/features/fix-all.d.ts.map +1 -1
- package/lib/features/fix-all.js +104 -147
- package/lib/features/fix-all.js.map +1 -1
- package/lib/features/inlay-hints.d.ts +11 -0
- package/lib/features/inlay-hints.d.ts.map +1 -0
- package/lib/features/inlay-hints.js +70 -0
- package/lib/features/inlay-hints.js.map +1 -0
- package/lib/features/source-definition.d.ts +11 -0
- package/lib/features/source-definition.d.ts.map +1 -0
- package/lib/features/source-definition.js +50 -0
- package/lib/features/source-definition.js.map +1 -0
- package/lib/file-lsp-server.spec.js +26 -36
- package/lib/file-lsp-server.spec.js.map +1 -1
- package/lib/hover.d.ts +4 -3
- package/lib/hover.d.ts.map +1 -1
- package/lib/hover.js +53 -17
- package/lib/hover.js.map +1 -1
- package/lib/logger.d.ts +12 -4
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +37 -44
- package/lib/logger.js.map +1 -1
- package/lib/lsp-client.d.ts +13 -17
- package/lib/lsp-client.d.ts.map +1 -1
- package/lib/lsp-client.js +32 -91
- package/lib/lsp-client.js.map +1 -1
- package/lib/lsp-connection.d.ts +1 -1
- package/lib/lsp-connection.d.ts.map +1 -1
- package/lib/lsp-connection.js +13 -39
- package/lib/lsp-connection.js.map +1 -1
- package/lib/lsp-protocol.calls.proposed.d.ts +1 -1
- package/lib/lsp-protocol.calls.proposed.d.ts.map +1 -1
- package/lib/lsp-protocol.calls.proposed.js +7 -32
- package/lib/lsp-protocol.calls.proposed.js.map +1 -1
- package/lib/lsp-protocol.inlayHints.proposed.d.ts +2 -11
- package/lib/lsp-protocol.inlayHints.proposed.d.ts.map +1 -1
- package/lib/lsp-protocol.inlayHints.proposed.js +2 -28
- package/lib/lsp-protocol.inlayHints.proposed.js.map +1 -1
- package/lib/lsp-server.d.ts +27 -28
- package/lib/lsp-server.d.ts.map +1 -1
- package/lib/lsp-server.js +868 -926
- package/lib/lsp-server.js.map +1 -1
- package/lib/lsp-server.spec.js +956 -606
- package/lib/lsp-server.spec.js.map +1 -1
- package/lib/organize-imports.d.ts +3 -3
- package/lib/organize-imports.d.ts.map +1 -1
- package/lib/organize-imports.js +5 -32
- package/lib/organize-imports.js.map +1 -1
- package/lib/organize-imports.spec.js +17 -42
- package/lib/organize-imports.spec.js.map +1 -1
- package/lib/protocol-translation.d.ts +5 -10
- package/lib/protocol-translation.d.ts.map +1 -1
- package/lib/protocol-translation.js +39 -168
- package/lib/protocol-translation.js.map +1 -1
- package/lib/quickfix.d.ts +3 -3
- package/lib/quickfix.d.ts.map +1 -1
- package/lib/quickfix.js +7 -35
- package/lib/quickfix.js.map +1 -1
- package/lib/refactor.d.ts +2 -2
- package/lib/refactor.d.ts.map +1 -1
- package/lib/refactor.js +11 -36
- package/lib/refactor.js.map +1 -1
- package/lib/semantic-tokens.d.ts +1 -1
- package/lib/semantic-tokens.d.ts.map +1 -1
- package/lib/semantic-tokens.js +1 -5
- package/lib/semantic-tokens.js.map +1 -1
- package/lib/test-utils.d.ts +11 -5
- package/lib/test-utils.d.ts.map +1 -1
- package/lib/test-utils.js +137 -120
- package/lib/test-utils.js.map +1 -1
- package/lib/ts-protocol.d.ts +8 -20
- package/lib/ts-protocol.d.ts.map +1 -1
- package/lib/ts-protocol.js +4 -31
- package/lib/ts-protocol.js.map +1 -1
- package/lib/tsp-client.d.ts +46 -43
- package/lib/tsp-client.d.ts.map +1 -1
- package/lib/tsp-client.js +31 -52
- package/lib/tsp-client.js.map +1 -1
- package/lib/tsp-client.spec.js +48 -75
- package/lib/tsp-client.spec.js.map +1 -1
- package/lib/tsp-command-types.d.ts +1 -0
- package/lib/tsp-command-types.d.ts.map +1 -1
- package/lib/tsp-command-types.js +4 -8
- package/lib/tsp-command-types.js.map +1 -1
- package/lib/utils/SnippetString.js +1 -4
- package/lib/utils/SnippetString.js.map +1 -1
- package/lib/utils/api.d.ts +1 -0
- package/lib/utils/api.d.ts.map +1 -1
- package/lib/utils/api.js +3 -28
- package/lib/utils/api.js.map +1 -1
- package/lib/utils/configuration.d.ts +2 -2
- package/lib/utils/configuration.d.ts.map +1 -1
- package/lib/utils/configuration.js +1 -2
- package/lib/utils/errorCodes.js +11 -14
- package/lib/utils/errorCodes.js.map +1 -1
- package/lib/utils/fixNames.js +13 -16
- package/lib/utils/fixNames.js.map +1 -1
- package/lib/utils/modules-resolver.js +7 -34
- package/lib/utils/modules-resolver.js.map +1 -1
- package/lib/utils/modules-resolver.spec.d.ts +1 -1
- package/lib/utils/modules-resolver.spec.d.ts.map +1 -1
- package/lib/utils/modules-resolver.spec.js +11 -34
- package/lib/utils/modules-resolver.spec.js.map +1 -1
- package/lib/utils/typeConverters.d.ts +20 -2
- package/lib/utils/typeConverters.d.ts.map +1 -1
- package/lib/utils/typeConverters.js +105 -9
- package/lib/utils/typeConverters.js.map +1 -1
- package/lib/utils/types.js +2 -29
- package/lib/utils/types.js.map +1 -1
- package/lib/utils/versionProvider.d.ts +3 -3
- package/lib/utils/versionProvider.d.ts.map +1 -1
- package/lib/utils/versionProvider.js +52 -60
- package/lib/utils/versionProvider.js.map +1 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +3 -5
- package/lib/utils.js.map +1 -1
- package/package.json +38 -33
package/lib/features/fix-all.js
CHANGED
|
@@ -1,110 +1,76 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*---------------------------------------------------------------------------------------------
|
|
3
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
4
|
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
32
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
33
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
34
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
35
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.TypeScriptAutoFixProvider = void 0;
|
|
40
|
-
const lsp = __importStar(require("vscode-languageserver/node"));
|
|
41
|
-
const protocol_translation_1 = require("../protocol-translation");
|
|
42
|
-
const errorCodes = __importStar(require("../utils/errorCodes"));
|
|
43
|
-
const fixNames = __importStar(require("../utils/fixNames"));
|
|
44
|
-
const types_1 = require("../utils/types");
|
|
45
|
-
function buildIndividualFixes(fixes, client, file, documents, diagnostics) {
|
|
46
|
-
var _a;
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const edits = [];
|
|
49
|
-
for (const diagnostic of diagnostics) {
|
|
50
|
-
for (const { codes, fixName } of fixes) {
|
|
51
|
-
if (!codes.has(diagnostic.code)) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const args = Object.assign(Object.assign({}, (0, protocol_translation_1.toFileRangeRequestArgs)(file, diagnostic.range)), { errorCodes: [+diagnostic.code] });
|
|
55
|
-
const response = yield client.request("getCodeFixes" /* GetCodeFixes */, args);
|
|
56
|
-
if (response.type !== 'response') {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
const fix = (_a = response.body) === null || _a === void 0 ? void 0 : _a.find(fix => fix.fixName === fixName);
|
|
60
|
-
if (fix) {
|
|
61
|
-
edits.push(...fix.changes.map(change => (0, protocol_translation_1.toTextDocumentEdit)(change, documents)));
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
5
|
+
import * as lsp from 'vscode-languageserver';
|
|
6
|
+
import { toTextDocumentEdit } from '../protocol-translation.js';
|
|
7
|
+
import * as errorCodes from '../utils/errorCodes.js';
|
|
8
|
+
import * as fixNames from '../utils/fixNames.js';
|
|
9
|
+
import { CodeActionKind } from '../utils/types.js';
|
|
10
|
+
import { Range } from '../utils/typeConverters.js';
|
|
11
|
+
async function buildIndividualFixes(fixes, client, file, documents, diagnostics) {
|
|
12
|
+
const edits = [];
|
|
13
|
+
for (const diagnostic of diagnostics) {
|
|
14
|
+
for (const { codes, fixName } of fixes) {
|
|
15
|
+
if (!codes.has(diagnostic.code)) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const args = {
|
|
19
|
+
...Range.toFileRangeRequestArgs(file, diagnostic.range),
|
|
20
|
+
errorCodes: [+diagnostic.code],
|
|
21
|
+
};
|
|
22
|
+
const response = await client.request("getCodeFixes" /* CommandTypes.GetCodeFixes */, args);
|
|
23
|
+
if (response.type !== 'response') {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const fix = response.body?.find(fix => fix.fixName === fixName);
|
|
27
|
+
if (fix) {
|
|
28
|
+
edits.push(...fix.changes.map(change => toTextDocumentEdit(change, documents)));
|
|
29
|
+
break;
|
|
64
30
|
}
|
|
65
31
|
}
|
|
66
|
-
|
|
67
|
-
|
|
32
|
+
}
|
|
33
|
+
return edits;
|
|
68
34
|
}
|
|
69
|
-
function buildCombinedFix(fixes, client, file, documents, diagnostics) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
edits.push(...combinedResponse.body.changes.map(change => (0, protocol_translation_1.toTextDocumentEdit)(change, documents)));
|
|
35
|
+
async function buildCombinedFix(fixes, client, file, documents, diagnostics) {
|
|
36
|
+
const edits = [];
|
|
37
|
+
for (const diagnostic of diagnostics) {
|
|
38
|
+
for (const { codes, fixName } of fixes) {
|
|
39
|
+
if (!codes.has(diagnostic.code)) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const args = {
|
|
43
|
+
...Range.toFileRangeRequestArgs(file, diagnostic.range),
|
|
44
|
+
errorCodes: [+diagnostic.code],
|
|
45
|
+
};
|
|
46
|
+
const response = await client.request("getCodeFixes" /* CommandTypes.GetCodeFixes */, args);
|
|
47
|
+
if (response.type !== 'response' || !response.body?.length) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const fix = response.body?.find(fix => fix.fixName === fixName);
|
|
51
|
+
if (!fix) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (!fix.fixId) {
|
|
55
|
+
edits.push(...fix.changes.map(change => toTextDocumentEdit(change, documents)));
|
|
56
|
+
return edits;
|
|
57
|
+
}
|
|
58
|
+
const combinedArgs = {
|
|
59
|
+
scope: {
|
|
60
|
+
type: 'file',
|
|
61
|
+
args: { file },
|
|
62
|
+
},
|
|
63
|
+
fixId: fix.fixId,
|
|
64
|
+
};
|
|
65
|
+
const combinedResponse = await client.request("getCombinedCodeFix" /* CommandTypes.GetCombinedCodeFix */, combinedArgs);
|
|
66
|
+
if (combinedResponse.type !== 'response' || !combinedResponse.body) {
|
|
103
67
|
return edits;
|
|
104
68
|
}
|
|
69
|
+
edits.push(...combinedResponse.body.changes.map(change => toTextDocumentEdit(change, documents)));
|
|
70
|
+
return edits;
|
|
105
71
|
}
|
|
106
|
-
|
|
107
|
-
|
|
72
|
+
}
|
|
73
|
+
return edits;
|
|
108
74
|
}
|
|
109
75
|
// #region Source Actions
|
|
110
76
|
class SourceAction {
|
|
@@ -114,84 +80,75 @@ class SourceFixAll extends SourceAction {
|
|
|
114
80
|
super(...arguments);
|
|
115
81
|
this.title = 'Fix all';
|
|
116
82
|
}
|
|
117
|
-
build(client, file, documents, diagnostics) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return lsp.CodeAction.create(this.title, { documentChanges: edits }, SourceFixAll.kind.value);
|
|
131
|
-
});
|
|
83
|
+
async build(client, file, documents, diagnostics) {
|
|
84
|
+
const edits = [];
|
|
85
|
+
edits.push(...await buildIndividualFixes([
|
|
86
|
+
{ codes: errorCodes.incorrectlyImplementsInterface, fixName: fixNames.classIncorrectlyImplementsInterface },
|
|
87
|
+
{ codes: errorCodes.asyncOnlyAllowedInAsyncFunctions, fixName: fixNames.awaitInSyncFunction },
|
|
88
|
+
], client, file, documents, diagnostics));
|
|
89
|
+
edits.push(...await buildCombinedFix([
|
|
90
|
+
{ codes: errorCodes.unreachableCode, fixName: fixNames.unreachableCode },
|
|
91
|
+
], client, file, documents, diagnostics));
|
|
92
|
+
if (!edits.length) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
return lsp.CodeAction.create(this.title, { documentChanges: edits }, SourceFixAll.kind.value);
|
|
132
96
|
}
|
|
133
97
|
}
|
|
134
|
-
SourceFixAll.kind =
|
|
98
|
+
SourceFixAll.kind = CodeActionKind.SourceFixAllTs;
|
|
135
99
|
class SourceRemoveUnused extends SourceAction {
|
|
136
100
|
constructor() {
|
|
137
101
|
super(...arguments);
|
|
138
102
|
this.title = 'Remove all unused code';
|
|
139
103
|
}
|
|
140
|
-
build(client, file, documents, diagnostics) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return lsp.CodeAction.create(this.title, { documentChanges: edits }, SourceRemoveUnused.kind.value);
|
|
149
|
-
});
|
|
104
|
+
async build(client, file, documents, diagnostics) {
|
|
105
|
+
const edits = await buildCombinedFix([
|
|
106
|
+
{ codes: errorCodes.variableDeclaredButNeverUsed, fixName: fixNames.unusedIdentifier },
|
|
107
|
+
], client, file, documents, diagnostics);
|
|
108
|
+
if (!edits.length) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
return lsp.CodeAction.create(this.title, { documentChanges: edits }, SourceRemoveUnused.kind.value);
|
|
150
112
|
}
|
|
151
113
|
}
|
|
152
|
-
SourceRemoveUnused.kind =
|
|
114
|
+
SourceRemoveUnused.kind = CodeActionKind.SourceRemoveUnusedTs;
|
|
153
115
|
class SourceAddMissingImports extends SourceAction {
|
|
154
116
|
constructor() {
|
|
155
117
|
super(...arguments);
|
|
156
118
|
this.title = 'Add all missing imports';
|
|
157
119
|
}
|
|
158
|
-
build(client, file, documents, diagnostics) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return lsp.CodeAction.create(this.title, { documentChanges: edits }, SourceAddMissingImports.kind.value);
|
|
167
|
-
});
|
|
120
|
+
async build(client, file, documents, diagnostics) {
|
|
121
|
+
const edits = await buildCombinedFix([
|
|
122
|
+
{ codes: errorCodes.cannotFindName, fixName: fixNames.fixImport },
|
|
123
|
+
], client, file, documents, diagnostics);
|
|
124
|
+
if (!edits.length) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return lsp.CodeAction.create(this.title, { documentChanges: edits }, SourceAddMissingImports.kind.value);
|
|
168
128
|
}
|
|
169
129
|
}
|
|
170
|
-
SourceAddMissingImports.kind =
|
|
130
|
+
SourceAddMissingImports.kind = CodeActionKind.SourceAddMissingImportsTs;
|
|
171
131
|
//#endregion
|
|
172
|
-
class TypeScriptAutoFixProvider {
|
|
132
|
+
export class TypeScriptAutoFixProvider {
|
|
173
133
|
constructor(client) {
|
|
174
134
|
this.client = client;
|
|
175
135
|
}
|
|
176
136
|
static get kinds() {
|
|
177
137
|
return TypeScriptAutoFixProvider.kindProviders.map(provider => provider.kind);
|
|
178
138
|
}
|
|
179
|
-
provideCodeActions(kinds, file, diagnostics, documents) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
results.push((new provider).build(this.client, file, documents, diagnostics));
|
|
185
|
-
}
|
|
139
|
+
async provideCodeActions(kinds, file, diagnostics, documents) {
|
|
140
|
+
const results = [];
|
|
141
|
+
for (const provider of TypeScriptAutoFixProvider.kindProviders) {
|
|
142
|
+
if (kinds.some(kind => kind.contains(provider.kind))) {
|
|
143
|
+
results.push((new provider).build(this.client, file, documents, diagnostics));
|
|
186
144
|
}
|
|
187
|
-
|
|
188
|
-
|
|
145
|
+
}
|
|
146
|
+
return (await Promise.all(results)).flatMap(result => result || []);
|
|
189
147
|
}
|
|
190
148
|
}
|
|
191
|
-
exports.TypeScriptAutoFixProvider = TypeScriptAutoFixProvider;
|
|
192
149
|
TypeScriptAutoFixProvider.kindProviders = [
|
|
193
150
|
SourceFixAll,
|
|
194
151
|
SourceRemoveUnused,
|
|
195
|
-
SourceAddMissingImports
|
|
152
|
+
SourceAddMissingImports,
|
|
196
153
|
];
|
|
197
154
|
//# sourceMappingURL=fix-all.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix-all.js","sourceRoot":"","sources":["../../src/features/fix-all.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fix-all.js","sourceRoot":"","sources":["../../src/features/fix-all.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,KAAK,GAAG,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGhE,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAOnD,KAAK,UAAU,oBAAoB,CAC/B,KAAyB,EACzB,MAAiB,EACjB,IAAY,EACZ,SAAuB,EACvB,WAAsC;IAEtC,MAAM,KAAK,GAA2B,EAAE,C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yBAAyB;IAWlC,YAA6B,MAAiB;QAAjB,WAAM,GAAN,MAAM,CAAW;IAAG,CAAC;IAJ3C,MAAM,KAAK,KAAK;QACnB,OAAO,yBAAyB,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClF,CAAC;IAIM,KAAK,CAAC,kBAAkB,CAAC,KAAuB,EAAE,IAAY,EAAE,WAA6B,EAAE,SAAuB;QACzH,MAAM,OAAO,GAAqC,EAAE,CAAC;QACrD,KAAK,MAAM,QAAQ,IAAI,yBAAyB,CAAC,aAAa,EAAE;YAC5D,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE;gBAClD,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;aACjF;SACJ;QACD,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IACxE,CAAC;;AApBc,uCAAa,GAAG;IAC3B,YAAY;IACZ,kBAAkB;IAClB,uBAAuB;CAC1B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as lsp from 'vscode-languageserver';
|
|
2
|
+
import API from '../utils/api.js';
|
|
3
|
+
import type { ConfigurationManager } from '../configuration-manager.js';
|
|
4
|
+
import type { LspDocuments } from '../document.js';
|
|
5
|
+
import type { TspClient } from '../tsp-client.js';
|
|
6
|
+
import type { LspClient } from '../lsp-client.js';
|
|
7
|
+
export declare class TypeScriptInlayHintsProvider {
|
|
8
|
+
static readonly minVersion: API;
|
|
9
|
+
static provideInlayHints(uri: lsp.DocumentUri, range: lsp.Range, documents: LspDocuments, tspClient: TspClient, lspClient: LspClient, configurationManager: ConfigurationManager): Promise<lsp.InlayHint[]>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=inlay-hints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inlay-hints.d.ts","sourceRoot":"","sources":["../../src/features/inlay-hints.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,GAAG,MAAM,uBAAuB,CAAC;AAC7C,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKlD,qBAAa,4BAA4B;IACrC,gBAAuB,UAAU,MAAY;WAEzB,iBAAiB,CACjC,GAAG,EAAE,GAAG,CAAC,WAAW,EACpB,KAAK,EAAE,GAAG,CAAC,KAAK,EAChB,SAAS,EAAE,YAAY,EACvB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,EACpB,oBAAoB,EAAE,oBAAoB,GAC3C,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;CA4C9B"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2022 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*/
|
|
7
|
+
/*---------------------------------------------------------------------------------------------
|
|
8
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
9
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
10
|
+
*--------------------------------------------------------------------------------------------*/
|
|
11
|
+
import * as lsp from 'vscode-languageserver';
|
|
12
|
+
import API from '../utils/api.js';
|
|
13
|
+
import { Position } from '../utils/typeConverters.js';
|
|
14
|
+
import { uriToPath } from '../protocol-translation.js';
|
|
15
|
+
export class TypeScriptInlayHintsProvider {
|
|
16
|
+
static async provideInlayHints(uri, range, documents, tspClient, lspClient, configurationManager) {
|
|
17
|
+
if (tspClient.apiVersion.lt(TypeScriptInlayHintsProvider.minVersion)) {
|
|
18
|
+
lspClient.showErrorMessage('Inlay Hints request failed. Requires TypeScript 4.4+.');
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
const file = uriToPath(uri);
|
|
22
|
+
if (!file) {
|
|
23
|
+
lspClient.showErrorMessage('Inlay Hints request failed. No resource provided.');
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const document = documents.get(file);
|
|
27
|
+
if (!document) {
|
|
28
|
+
lspClient.showErrorMessage('Inlay Hints request failed. File not opened in the editor.');
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
if (!areInlayHintsEnabledForFile(configurationManager, file)) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
await configurationManager.configureGloballyFromDocument(file);
|
|
35
|
+
const start = document.offsetAt(range.start);
|
|
36
|
+
const length = document.offsetAt(range.end) - start;
|
|
37
|
+
const response = await tspClient.request("provideInlayHints" /* CommandTypes.ProvideInlayHints */, { file, start, length });
|
|
38
|
+
if (response.type !== 'response' || !response.success || !response.body) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
return response.body.map(hint => {
|
|
42
|
+
const inlayHint = lsp.InlayHint.create(Position.fromLocation(hint.position), hint.text, fromProtocolInlayHintKind(hint.kind));
|
|
43
|
+
hint.whitespaceBefore && (inlayHint.paddingLeft = true);
|
|
44
|
+
hint.whitespaceAfter && (inlayHint.paddingRight = true);
|
|
45
|
+
return inlayHint;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
TypeScriptInlayHintsProvider.minVersion = API.v440;
|
|
50
|
+
function areInlayHintsEnabledForFile(configurationManager, filename) {
|
|
51
|
+
const preferences = configurationManager.getPreferences(filename);
|
|
52
|
+
// Doesn't need to include `includeInlayVariableTypeHintsWhenTypeMatchesName` as it depends
|
|
53
|
+
// on `includeInlayVariableTypeHints` being enabled.
|
|
54
|
+
return preferences.includeInlayParameterNameHints === 'literals' ||
|
|
55
|
+
preferences.includeInlayParameterNameHints === 'all' ||
|
|
56
|
+
preferences.includeInlayEnumMemberValueHints ||
|
|
57
|
+
preferences.includeInlayFunctionLikeReturnTypeHints ||
|
|
58
|
+
preferences.includeInlayFunctionParameterTypeHints ||
|
|
59
|
+
preferences.includeInlayPropertyDeclarationTypeHints ||
|
|
60
|
+
preferences.includeInlayVariableTypeHints;
|
|
61
|
+
}
|
|
62
|
+
function fromProtocolInlayHintKind(kind) {
|
|
63
|
+
switch (kind) {
|
|
64
|
+
case 'Parameter': return lsp.InlayHintKind.Parameter;
|
|
65
|
+
case 'Type': return lsp.InlayHintKind.Type;
|
|
66
|
+
case 'Enum': return undefined;
|
|
67
|
+
default: return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=inlay-hints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inlay-hints.js","sourceRoot":"","sources":["../../src/features/inlay-hints.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH;;;gGAGgG;AAGhG,OAAO,KAAK,GAAG,MAAM,uBAAuB,CAAC;AAC7C,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAMlC,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,MAAM,OAAO,4BAA4B;IAG9B,MAAM,CAAC,KAAK,CAAC,iBAAiB,CACjC,GAAoB,EACpB,KA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
3
|
+
import type { LspDocuments } from '../document.js';
|
|
4
|
+
import type { TspClient } from '../tsp-client.js';
|
|
5
|
+
import type { LspClient } from '../lsp-client.js';
|
|
6
|
+
export declare class SourceDefinitionCommand {
|
|
7
|
+
static readonly id = "_typescript.goToSourceDefinition";
|
|
8
|
+
static readonly minVersion: API;
|
|
9
|
+
static execute(uri: lsp.DocumentUri | undefined, position: lsp.Position | undefined, documents: LspDocuments, tspClient: TspClient, lspClient: LspClient, reporter: lsp.WorkDoneProgressReporter): Promise<lsp.Location[] | void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=source-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-definition.d.ts","sourceRoot":"","sources":["../../src/features/source-definition.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,GAAG,MAAM,uBAAuB,CAAC;AAC7C,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAGlC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGlD,qBAAa,uBAAuB;IAChC,gBAAuB,EAAE,sCAAsC;IAC/D,gBAAuB,UAAU,MAAY;WAEzB,OAAO,CACvB,GAAG,EAAE,GAAG,CAAC,WAAW,GAAG,SAAS,EAChC,QAAQ,EAAE,GAAG,CAAC,QAAQ,GAAG,SAAS,EAClC,SAAS,EAAE,YAAY,EACvB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,GAAG,CAAC,wBAAwB,GACvC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC;CAsCpC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2022 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*/
|
|
7
|
+
/*---------------------------------------------------------------------------------------------
|
|
8
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
9
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
10
|
+
*--------------------------------------------------------------------------------------------*/
|
|
11
|
+
import API from '../utils/api.js';
|
|
12
|
+
import { Position } from '../utils/typeConverters.js';
|
|
13
|
+
import { toLocation, uriToPath } from '../protocol-translation.js';
|
|
14
|
+
export class SourceDefinitionCommand {
|
|
15
|
+
static async execute(uri, position, documents, tspClient, lspClient, reporter) {
|
|
16
|
+
if (tspClient.apiVersion.lt(SourceDefinitionCommand.minVersion)) {
|
|
17
|
+
lspClient.showErrorMessage('Go to Source Definition failed. Requires TypeScript 4.7+.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!position || typeof position.character !== 'number' || typeof position.line !== 'number') {
|
|
21
|
+
lspClient.showErrorMessage('Go to Source Definition failed. Invalid position.');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
let file;
|
|
25
|
+
if (!uri || typeof uri !== 'string' || !(file = uriToPath(uri))) {
|
|
26
|
+
lspClient.showErrorMessage('Go to Source Definition failed. No resource provided.');
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const document = documents.get(file);
|
|
30
|
+
if (!document) {
|
|
31
|
+
lspClient.showErrorMessage('Go to Source Definition failed. File not opened in the editor.');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const args = Position.toFileLocationRequestArgs(file, position);
|
|
35
|
+
return await lspClient.withProgress({
|
|
36
|
+
message: 'Finding source definitions…',
|
|
37
|
+
reporter,
|
|
38
|
+
}, async () => {
|
|
39
|
+
const response = await tspClient.request("findSourceDefinition" /* CommandTypes.FindSourceDefinition */, args);
|
|
40
|
+
if (response.type !== 'response' || !response.body) {
|
|
41
|
+
lspClient.showErrorMessage('No source definitions found.');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
return response.body.map(reference => toLocation(reference, documents));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
SourceDefinitionCommand.id = '_typescript.goToSourceDefinition';
|
|
49
|
+
SourceDefinitionCommand.minVersion = API.v470;
|
|
50
|
+
//# sourceMappingURL=source-definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-definition.js","sourceRoot":"","sources":["../../src/features/source-definition.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH;;;gGAGgG;AAGhG,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAMnE,MAAM,OAAO,uBAAuB;IAIzB,MAAM,CAAC,KAAK,CAAC,OAAO,CACvB,GAAgC,EAChC,QAAkC,EAClC,SAAuB,EACvB,SAAoB,EACpB,SAAoB,EACpB,QAAsC;QAEtC,IAAI,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,uBAAuB,CAAC,UAAU,CAAC,EAAE;YAC7D,SAAS,CAAC,gBAAgB,CAAC,2DAA2D,CAAC,CAAC;YACxF,OAAO;SACV;QAED,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,CAAC,SAAS,KAAK,QAAQ,IAAI,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE;YAC1F,SAAS,CAAC,gBAAgB,CAAC,mDAAmD,CAAC,CAAC;YAChF,OAAO;SACV;QAED,IAAI,IAAwB,CAAC;QAE7B,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE;YAC7D,SAAS,CAAC,gBAAgB,CAAC,uDAAuD,CAAC,CAAC;YACpF,OAAO;SACV;QAED,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAErC,IAAI,CAAC,QAAQ,EAAE;YACX,SAAS,CAAC,gBAAgB,CAAC,gEAAgE,CAAC,CAAC;YAC7F,OAAO;SACV;QAED,MAAM,IAAI,GAAG,QAAQ,CAAC,yBAAyB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAChE,OAAO,MAAM,SAAS,CAAC,YAAY,CAAwB;YACvD,OAAO,EAAE,6BAA6B;YACtC,QAAQ;SACX,EAAE,KAAK,IAAI,EAAE;YACV,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,OAAO,iEAAoC,IAAI,CAAC,CAAC;YAClF,IAAI,QAAQ,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;gBAChD,SAAS,CAAC,gBAAgB,CAAC,8BAA8B,CAAC,CAAC;gBAC3D,OAAO;aACV;YACD,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;QAC5E,CAAC,CAAC,CAAC;IACP,CAAC;;AA/CsB,0BAAE,GAAG,kCAAkC,CAAC;AACxC,kCAAU,GAAG,GAAG,CAAC,IAAI,CAAC"}
|
|
@@ -1,74 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* Copyright (C) 2017, 2018 TypeFox and others.
|
|
4
3
|
*
|
|
5
4
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
|
|
6
5
|
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
const chai_1 = __importDefault(require("chai"));
|
|
22
|
-
const test_utils_1 = require("./test-utils");
|
|
23
|
-
const assert = chai_1.default.assert;
|
|
7
|
+
import chai from 'chai';
|
|
8
|
+
import { uri, createServer, lastPosition, filePath, readContents, positionAfter } from './test-utils.js';
|
|
9
|
+
const assert = chai.assert;
|
|
24
10
|
let server;
|
|
25
|
-
before(() =>
|
|
26
|
-
server =
|
|
27
|
-
rootUri:
|
|
28
|
-
publishDiagnostics: () => { }
|
|
11
|
+
before(async () => {
|
|
12
|
+
server = await createServer({
|
|
13
|
+
rootUri: uri(),
|
|
14
|
+
publishDiagnostics: () => { },
|
|
29
15
|
});
|
|
30
|
-
})
|
|
16
|
+
});
|
|
31
17
|
beforeEach(() => {
|
|
32
18
|
server.closeAll();
|
|
33
19
|
});
|
|
20
|
+
after(() => {
|
|
21
|
+
server.closeAll();
|
|
22
|
+
server.shutdown();
|
|
23
|
+
});
|
|
34
24
|
describe('documentHighlight', () => {
|
|
35
|
-
it('simple test', () =>
|
|
25
|
+
it('simple test', async () => {
|
|
36
26
|
const doc = {
|
|
37
|
-
uri:
|
|
27
|
+
uri: uri('module2.ts'),
|
|
38
28
|
languageId: 'typescript',
|
|
39
29
|
version: 1,
|
|
40
|
-
text:
|
|
30
|
+
text: readContents(filePath('module2.ts')),
|
|
41
31
|
};
|
|
42
32
|
server.didOpenTextDocument({
|
|
43
|
-
textDocument: doc
|
|
33
|
+
textDocument: doc,
|
|
44
34
|
});
|
|
45
|
-
const result =
|
|
35
|
+
const result = await server.documentHighlight({
|
|
46
36
|
textDocument: doc,
|
|
47
|
-
position:
|
|
37
|
+
position: lastPosition(doc, 'doStuff'),
|
|
48
38
|
});
|
|
49
39
|
assert.equal(2, result.length, JSON.stringify(result, undefined, 2));
|
|
50
|
-
})
|
|
40
|
+
});
|
|
51
41
|
});
|
|
52
42
|
describe('completions', () => {
|
|
53
|
-
it('receives completion that auto-imports from another module', () =>
|
|
43
|
+
it('receives completion that auto-imports from another module', async () => {
|
|
54
44
|
const doc = {
|
|
55
|
-
uri:
|
|
45
|
+
uri: uri('completion.ts'),
|
|
56
46
|
languageId: 'typescript',
|
|
57
47
|
version: 1,
|
|
58
|
-
text:
|
|
48
|
+
text: readContents(filePath('completion.ts')),
|
|
59
49
|
};
|
|
60
50
|
server.didOpenTextDocument({ textDocument: doc });
|
|
61
|
-
const proposals =
|
|
51
|
+
const proposals = await server.completion({
|
|
62
52
|
textDocument: doc,
|
|
63
|
-
position:
|
|
53
|
+
position: positionAfter(doc, 'doStuff'),
|
|
64
54
|
});
|
|
65
55
|
assert.isNotNull(proposals);
|
|
66
56
|
const completion = proposals.items.find(item => item.label === 'doStuff');
|
|
67
57
|
assert.isDefined(completion);
|
|
68
|
-
const resolvedCompletion =
|
|
58
|
+
const resolvedCompletion = await server.completionResolve(completion);
|
|
69
59
|
assert.isDefined(resolvedCompletion.additionalTextEdits);
|
|
70
60
|
assert.isUndefined(resolvedCompletion.command);
|
|
71
61
|
server.didCloseTextDocument({ textDocument: doc });
|
|
72
|
-
})
|
|
62
|
+
});
|
|
73
63
|
});
|
|
74
64
|
//# sourceMappingURL=file-lsp-server.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-lsp-server.spec.js","sourceRoot":"","sources":["../src/file-lsp-server.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file-lsp-server.spec.js","sourceRoot":"","s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