volar-service-typescript 0.0.2 → 0.0.4
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/out/configs/getFormatCodeSettings.d.ts +2 -2
- package/out/index.d.ts +9 -9
- package/out/index.js +14 -25
- package/out/services/callHierarchy.d.ts +1 -1
- package/out/services/callHierarchy.js +1 -2
- package/out/services/codeAction.d.ts +1 -1
- package/out/services/codeAction.js +36 -15
- package/out/services/codeActionResolve.d.ts +2 -2
- package/out/services/completions/basic.d.ts +1 -1
- package/out/services/completions/basic.js +56 -29
- package/out/services/completions/directiveComment.d.ts +1 -1
- package/out/services/completions/directiveComment.js +13 -5
- package/out/services/completions/jsDoc.d.ts +1 -1
- package/out/services/completions/jsDoc.js +7 -8
- package/out/services/completions/resolve.d.ts +2 -2
- package/out/services/completions/resolve.js +3 -4
- package/out/services/definition.d.ts +1 -1
- package/out/services/diagnostics.d.ts +1 -1
- package/out/services/diagnostics.js +7 -31
- package/out/services/documentHighlight.d.ts +1 -1
- package/out/services/documentHighlight.js +1 -25
- package/out/services/documentSymbol.d.ts +1 -1
- package/out/services/documentSymbol.js +30 -19
- package/out/services/fileReferences.d.ts +1 -1
- package/out/services/foldingRanges.d.ts +1 -1
- package/out/services/foldingRanges.js +10 -28
- package/out/services/formatting.d.ts +1 -1
- package/out/services/hover.d.ts +1 -1
- package/out/services/hover.js +5 -3
- package/out/services/inlayHints.d.ts +1 -1
- package/out/services/inlayHints.js +7 -27
- package/out/services/prepareRename.d.ts +4 -2
- package/out/services/prepareRename.js +1 -25
- package/out/services/references.d.ts +1 -1
- package/out/services/rename.d.ts +1 -1
- package/out/services/rename.js +16 -35
- package/out/services/selectionRanges.d.ts +1 -1
- package/out/services/selectionRanges.js +4 -25
- package/out/services/semanticTokens.d.ts +1 -1
- package/out/services/signatureHelp.d.ts +1 -1
- package/out/services/signatureHelp.js +3 -27
- package/out/services/tsconfig.d.ts +1 -1
- package/out/services/tsconfig.js +13 -7
- package/out/services/workspaceSymbol.d.ts +1 -1
- package/out/services/workspaceSymbol.js +22 -16
- package/out/shared.d.ts +1 -1
- package/out/types.d.ts +1 -1
- package/out/utils/transforms.d.ts +1 -1
- package/out/utils/transforms.js +41 -34
- package/out/utils/typeConverters.d.ts +1 -1
- package/out/utils/typeConverters.js +23 -27
- package/package.json +4 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SharedContext } from '../types';
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
-
import
|
|
3
|
+
import type { FormattingOptions } from '@volar/language-service';
|
|
4
4
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
5
|
-
export declare function getFormatCodeSettings(ctx: SharedContext, document: TextDocument, options?:
|
|
5
|
+
export declare function getFormatCodeSettings(ctx: SharedContext, document: TextDocument, options?: FormattingOptions): Promise<ts.FormatCodeSettings>;
|
package/out/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Service } from '@volar/language-service';
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
|
-
export
|
|
5
|
-
typescript:
|
|
6
|
-
sourceFile:
|
|
7
|
-
languageService:
|
|
8
|
-
languageServiceHost:
|
|
9
|
-
textDocument:
|
|
10
|
-
}
|
|
11
|
-
declare const _default: () => Service
|
|
4
|
+
export interface Provide {
|
|
5
|
+
'typescript/typescript': () => typeof import('typescript/lib/tsserverlibrary');
|
|
6
|
+
'typescript/sourceFile': (document: TextDocument) => ts.SourceFile | undefined;
|
|
7
|
+
'typescript/languageService': (document?: TextDocument) => ts.LanguageService | undefined;
|
|
8
|
+
'typescript/languageServiceHost': (document?: TextDocument) => ts.LanguageServiceHost | undefined;
|
|
9
|
+
'typescript/textDocument': (uri: string) => TextDocument | undefined;
|
|
10
|
+
}
|
|
11
|
+
declare const _default: () => Service<Provide>;
|
|
12
12
|
export default _default;
|
package/out/index.js
CHANGED
|
@@ -23,10 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.injectionKeys = void 0;
|
|
27
|
-
const language_service_1 = require("@volar/language-service");
|
|
28
26
|
const semver = __importStar(require("semver"));
|
|
29
|
-
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
30
27
|
const shared_1 = require("./shared");
|
|
31
28
|
const _callHierarchy = __importStar(require("./services/callHierarchy"));
|
|
32
29
|
const codeActions = __importStar(require("./services/codeAction"));
|
|
@@ -55,13 +52,7 @@ const signatureHelp = __importStar(require("./services/signatureHelp"));
|
|
|
55
52
|
const typeDefinitions = __importStar(require("./services/typeDefinition"));
|
|
56
53
|
const workspaceSymbols = __importStar(require("./services/workspaceSymbol"));
|
|
57
54
|
const tsconfig = __importStar(require("./services/tsconfig"));
|
|
58
|
-
|
|
59
|
-
typescript: 'typescript/typescript',
|
|
60
|
-
sourceFile: 'typescript/sourceFile',
|
|
61
|
-
languageService: 'typescript/languageService',
|
|
62
|
-
languageServiceHost: 'typescript/languageServiceHost',
|
|
63
|
-
textDocument: 'typescript/textDocument',
|
|
64
|
-
};
|
|
55
|
+
;
|
|
65
56
|
exports.default = () => (contextOrNull, modules) => {
|
|
66
57
|
const jsDocTriggerCharacter = '*';
|
|
67
58
|
const directiveCommentTriggerCharacter = '@';
|
|
@@ -151,8 +142,8 @@ exports.default = () => (contextOrNull, modules) => {
|
|
|
151
142
|
const getFoldingRanges = foldingRanges.register(syntacticCtx);
|
|
152
143
|
return {
|
|
153
144
|
provide: {
|
|
154
|
-
|
|
155
|
-
|
|
145
|
+
'typescript/typescript': () => ts,
|
|
146
|
+
'typescript/sourceFile': document => {
|
|
156
147
|
if ((0, shared_1.isTsDocument)(document)) {
|
|
157
148
|
const sourceFile = getSemanticServiceSourceFile(document.uri);
|
|
158
149
|
if (sourceFile) {
|
|
@@ -161,24 +152,22 @@ exports.default = () => (contextOrNull, modules) => {
|
|
|
161
152
|
prepareSyntacticService(document);
|
|
162
153
|
return syntacticCtx.typescript.languageService.getProgram()?.getSourceFile(syntacticHostCtx.fileName);
|
|
163
154
|
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (sourceFile) {
|
|
155
|
+
},
|
|
156
|
+
'typescript/languageService': document => {
|
|
157
|
+
if (!document || getSemanticServiceSourceFile(document.uri)) {
|
|
168
158
|
return semanticCtx.typescript.languageService;
|
|
169
159
|
}
|
|
170
160
|
prepareSyntacticService(document);
|
|
171
161
|
return syntacticCtx.typescript.languageService;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (sourceFile) {
|
|
162
|
+
},
|
|
163
|
+
'typescript/languageServiceHost': document => {
|
|
164
|
+
if (!document || getSemanticServiceSourceFile(document.uri)) {
|
|
176
165
|
return semanticCtx.typescript.languageServiceHost;
|
|
177
166
|
}
|
|
178
167
|
prepareSyntacticService(document);
|
|
179
168
|
return syntacticCtx.typescript.languageServiceHost;
|
|
180
|
-
}
|
|
181
|
-
|
|
169
|
+
},
|
|
170
|
+
'typescript/textDocument': semanticCtx.getTextDocument,
|
|
182
171
|
},
|
|
183
172
|
...triggerCharacters,
|
|
184
173
|
triggerCharacters: [
|
|
@@ -206,7 +195,7 @@ exports.default = () => (contextOrNull, modules) => {
|
|
|
206
195
|
isIncomplete: false,
|
|
207
196
|
items: [],
|
|
208
197
|
};
|
|
209
|
-
if (!context || context.triggerKind !==
|
|
198
|
+
if (!context || context.triggerKind !== 2 || (context.triggerCharacter && basicTriggerCharacters.includes(context.triggerCharacter))) {
|
|
210
199
|
const completeOptions = {
|
|
211
200
|
triggerCharacter: context?.triggerCharacter,
|
|
212
201
|
triggerKind: context?.triggerKind,
|
|
@@ -216,13 +205,13 @@ exports.default = () => (contextOrNull, modules) => {
|
|
|
216
205
|
result = basicResult;
|
|
217
206
|
}
|
|
218
207
|
}
|
|
219
|
-
if (!context || context.triggerKind !==
|
|
208
|
+
if (!context || context.triggerKind !== 2 || context.triggerCharacter === jsDocTriggerCharacter) {
|
|
220
209
|
const jsdocResult = await doJsDocComplete(document.uri, position);
|
|
221
210
|
if (jsdocResult) {
|
|
222
211
|
result.items.push(jsdocResult);
|
|
223
212
|
}
|
|
224
213
|
}
|
|
225
|
-
if (!context || context.triggerKind !==
|
|
214
|
+
if (!context || context.triggerKind !== 2 || context.triggerCharacter === directiveCommentTriggerCharacter) {
|
|
226
215
|
const directiveCommentResult = await doDirectiveCommentComplete(document.uri, position);
|
|
227
216
|
if (directiveCommentResult) {
|
|
228
217
|
result.items = result.items.concat(directiveCommentResult);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as vscode from '
|
|
1
|
+
import type * as vscode from '@volar/language-service';
|
|
2
2
|
import { SharedContext } from '../types';
|
|
3
3
|
export declare function register(ctx: SharedContext): {
|
|
4
4
|
doPrepare: (uri: string, position: vscode.Position) => vscode.CallHierarchyItem[];
|
|
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.register = void 0;
|
|
27
|
-
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
28
27
|
const PConst = __importStar(require("../protocol.const"));
|
|
29
28
|
const modifiers_1 = require("../utils/modifiers");
|
|
30
29
|
const typeConverters = __importStar(require("../utils/typeConverters"));
|
|
@@ -97,7 +96,7 @@ function register(ctx) {
|
|
|
97
96
|
};
|
|
98
97
|
const kindModifiers = item.kindModifiers ? (0, modifiers_1.parseKindModifier)(item.kindModifiers) : undefined;
|
|
99
98
|
if (kindModifiers?.has(PConst.KindModifiers.deprecated)) {
|
|
100
|
-
result.tags = [
|
|
99
|
+
result.tags = [1];
|
|
101
100
|
}
|
|
102
101
|
return result;
|
|
103
102
|
}
|
|
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.register = void 0;
|
|
27
|
-
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
28
27
|
const rename_1 = require("./rename");
|
|
29
28
|
const fixNames = __importStar(require("../utils/fixNames"));
|
|
30
29
|
const getFormatCodeSettings_1 = require("../configs/getFormatCodeSettings");
|
|
@@ -50,18 +49,18 @@ function register(ctx) {
|
|
|
50
49
|
const start = document.offsetAt(range.start);
|
|
51
50
|
const end = document.offsetAt(range.end);
|
|
52
51
|
let result = [];
|
|
53
|
-
const onlyQuickFix = matchOnlyKind(`${
|
|
52
|
+
const onlyQuickFix = matchOnlyKind(`${'quickfix'}.ts`);
|
|
54
53
|
if (!context.only || onlyQuickFix) {
|
|
55
54
|
for (const error of context.diagnostics) {
|
|
56
55
|
const codeFixes = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getCodeFixesAtPosition(fileName, document.offsetAt(error.range.start), document.offsetAt(error.range.end), [Number(error.code)], formatOptions, preferences)) ?? [];
|
|
57
56
|
for (const codeFix of codeFixes) {
|
|
58
|
-
result = result.concat(transformCodeFix(codeFix, [error], onlyQuickFix ??
|
|
57
|
+
result = result.concat(transformCodeFix(codeFix, [error], onlyQuickFix ?? ''));
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
if (context.only) {
|
|
63
62
|
for (const only of context.only) {
|
|
64
|
-
if (only.split('.')[0] ===
|
|
63
|
+
if (only.split('.')[0] === 'refactor') {
|
|
65
64
|
const refactors = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getApplicableRefactors(fileName, { pos: start, end: end }, preferences, undefined, only)) ?? [];
|
|
66
65
|
for (const refactor of refactors) {
|
|
67
66
|
result = result.concat(transformRefactor(refactor));
|
|
@@ -75,9 +74,12 @@ function register(ctx) {
|
|
|
75
74
|
result = result.concat(transformRefactor(refactor));
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
|
-
const onlySourceOrganizeImports = matchOnlyKind(`${
|
|
77
|
+
const onlySourceOrganizeImports = matchOnlyKind(`${'source.organizeImports'}.ts`);
|
|
79
78
|
if (onlySourceOrganizeImports) {
|
|
80
|
-
const action =
|
|
79
|
+
const action = {
|
|
80
|
+
title: 'Organize Imports',
|
|
81
|
+
kind: onlySourceOrganizeImports,
|
|
82
|
+
};
|
|
81
83
|
const data = {
|
|
82
84
|
type: 'organizeImports',
|
|
83
85
|
uri,
|
|
@@ -91,9 +93,12 @@ function register(ctx) {
|
|
|
91
93
|
}
|
|
92
94
|
result.push(action);
|
|
93
95
|
}
|
|
94
|
-
const onlySourceFixAll = matchOnlyKind(`${
|
|
96
|
+
const onlySourceFixAll = matchOnlyKind(`${'source.fixAll'}.ts`);
|
|
95
97
|
if (onlySourceFixAll) {
|
|
96
|
-
const action =
|
|
98
|
+
const action = {
|
|
99
|
+
title: 'Fix All',
|
|
100
|
+
kind: onlySourceFixAll,
|
|
101
|
+
};
|
|
97
102
|
const data = {
|
|
98
103
|
uri,
|
|
99
104
|
type: 'fixAll',
|
|
@@ -112,9 +117,12 @@ function register(ctx) {
|
|
|
112
117
|
}
|
|
113
118
|
result.push(action);
|
|
114
119
|
}
|
|
115
|
-
const onlyRemoveUnused = matchOnlyKind(`${
|
|
120
|
+
const onlyRemoveUnused = matchOnlyKind(`${'source'}.removeUnused.ts`);
|
|
116
121
|
if (onlyRemoveUnused) {
|
|
117
|
-
const action =
|
|
122
|
+
const action = {
|
|
123
|
+
title: 'Remove all unused code',
|
|
124
|
+
kind: onlyRemoveUnused,
|
|
125
|
+
};
|
|
118
126
|
const data = {
|
|
119
127
|
uri,
|
|
120
128
|
type: 'fixAll',
|
|
@@ -137,9 +145,12 @@ function register(ctx) {
|
|
|
137
145
|
}
|
|
138
146
|
result.push(action);
|
|
139
147
|
}
|
|
140
|
-
const onlyAddMissingImports = matchOnlyKind(`${
|
|
148
|
+
const onlyAddMissingImports = matchOnlyKind(`${'source'}.addMissingImports.ts`);
|
|
141
149
|
if (onlyAddMissingImports) {
|
|
142
|
-
const action =
|
|
150
|
+
const action = {
|
|
151
|
+
title: 'Add all missing imports',
|
|
152
|
+
kind: onlyAddMissingImports,
|
|
153
|
+
};
|
|
143
154
|
const data = {
|
|
144
155
|
uri,
|
|
145
156
|
type: 'fixAll',
|
|
@@ -186,11 +197,18 @@ function register(ctx) {
|
|
|
186
197
|
function transformCodeFix(codeFix, diagnostics, kind) {
|
|
187
198
|
const edit = (0, rename_1.fileTextChangesToWorkspaceEdit)(codeFix.changes, ctx);
|
|
188
199
|
const codeActions = [];
|
|
189
|
-
const fix =
|
|
200
|
+
const fix = {
|
|
201
|
+
title: codeFix.description,
|
|
202
|
+
kind,
|
|
203
|
+
edit,
|
|
204
|
+
};
|
|
190
205
|
fix.diagnostics = diagnostics;
|
|
191
206
|
codeActions.push(fix);
|
|
192
207
|
if (codeFix.fixAllDescription && codeFix.fixId) {
|
|
193
|
-
const fixAll =
|
|
208
|
+
const fixAll = {
|
|
209
|
+
title: codeFix.fixAllDescription,
|
|
210
|
+
kind,
|
|
211
|
+
};
|
|
194
212
|
const data = {
|
|
195
213
|
uri,
|
|
196
214
|
type: 'fixAll',
|
|
@@ -211,7 +229,10 @@ function register(ctx) {
|
|
|
211
229
|
function transformRefactor(refactor) {
|
|
212
230
|
const codeActions = [];
|
|
213
231
|
for (const action of refactor.actions) {
|
|
214
|
-
const codeAction =
|
|
232
|
+
const codeAction = {
|
|
233
|
+
title: action.description,
|
|
234
|
+
kind: action.kind,
|
|
235
|
+
};
|
|
215
236
|
if (action.notApplicableReason) {
|
|
216
237
|
codeAction.disabled = { reason: action.notApplicableReason };
|
|
217
238
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
-
import * as vscode from '
|
|
3
|
-
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
+
import type * as vscode from '@volar/language-service';
|
|
3
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
import { SharedContext } from '../types';
|
|
5
5
|
import { Data, FixAllData, RefactorData } from './codeAction';
|
|
6
6
|
export declare function register(ctx: SharedContext): (codeAction: vscode.CodeAction) => Promise<vscode.CodeAction>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SharedContext } from '../../types';
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
-
import * as vscode from '
|
|
3
|
+
import type * as vscode from '@volar/language-service';
|
|
4
4
|
export interface Data {
|
|
5
5
|
uri: string;
|
|
6
6
|
fileName: string;
|
|
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.handleKindModifiers = exports.register = void 0;
|
|
27
27
|
const semver = __importStar(require("semver"));
|
|
28
|
-
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
29
28
|
const getUserPreferences_1 = require("../../configs/getUserPreferences");
|
|
30
29
|
const PConst = __importStar(require("../../protocol.const"));
|
|
31
30
|
const modifiers_1 = require("../../utils/modifiers");
|
|
@@ -47,7 +46,10 @@ function register(ctx) {
|
|
|
47
46
|
}));
|
|
48
47
|
if (completionContext === undefined)
|
|
49
48
|
return;
|
|
50
|
-
const wordRange = completionContext.optionalReplacementSpan ?
|
|
49
|
+
const wordRange = completionContext.optionalReplacementSpan ? {
|
|
50
|
+
start: document.positionAt(completionContext.optionalReplacementSpan.start),
|
|
51
|
+
end: document.positionAt(completionContext.optionalReplacementSpan.start + completionContext.optionalReplacementSpan.length),
|
|
52
|
+
} : undefined;
|
|
51
53
|
let line = document.getText({
|
|
52
54
|
start: { line: position.line, character: 0 },
|
|
53
55
|
end: { line: position.line + 1, character: 0 },
|
|
@@ -63,7 +65,7 @@ function register(ctx) {
|
|
|
63
65
|
items: entries,
|
|
64
66
|
};
|
|
65
67
|
function toVScodeItem(tsEntry, document) {
|
|
66
|
-
const item =
|
|
68
|
+
const item = { label: tsEntry.name };
|
|
67
69
|
item.kind = convertKind(tsEntry.kind);
|
|
68
70
|
if (tsEntry.source && tsEntry.hasAction) {
|
|
69
71
|
// De-prioritize auto-imports
|
|
@@ -90,7 +92,7 @@ function register(ctx) {
|
|
|
90
92
|
enableCallCompletions: true, // TODO: suggest.completeFunctionCalls
|
|
91
93
|
});
|
|
92
94
|
item.insertText = tsEntry.insertText;
|
|
93
|
-
item.insertTextFormat = isSnippet ?
|
|
95
|
+
item.insertTextFormat = isSnippet ? 2 : 1;
|
|
94
96
|
item.filterText = getFilterText(tsEntry, wordRange, line, tsEntry.insertText);
|
|
95
97
|
if (completionContext?.isMemberCompletion && dotAccessorContext && !isSnippet) {
|
|
96
98
|
item.filterText = dotAccessorContext.text + (item.insertText || item.label);
|
|
@@ -111,16 +113,23 @@ function register(ctx) {
|
|
|
111
113
|
handleKindModifiers(item, tsEntry);
|
|
112
114
|
if (!range && wordRange) {
|
|
113
115
|
range = {
|
|
114
|
-
inserting:
|
|
116
|
+
inserting: { start: wordRange.start, end: position },
|
|
115
117
|
replacing: wordRange,
|
|
116
118
|
};
|
|
117
119
|
}
|
|
118
120
|
if (range) {
|
|
119
|
-
if (
|
|
120
|
-
item.textEdit =
|
|
121
|
+
if ('start' in range) {
|
|
122
|
+
item.textEdit = {
|
|
123
|
+
range,
|
|
124
|
+
newText: item.insertText || item.label,
|
|
125
|
+
};
|
|
121
126
|
}
|
|
122
127
|
else {
|
|
123
|
-
item.textEdit =
|
|
128
|
+
item.textEdit = {
|
|
129
|
+
insert: range.inserting,
|
|
130
|
+
replace: range.replacing,
|
|
131
|
+
newText: item.insertText || item.label,
|
|
132
|
+
};
|
|
124
133
|
}
|
|
125
134
|
}
|
|
126
135
|
return {
|
|
@@ -147,7 +156,10 @@ function register(ctx) {
|
|
|
147
156
|
if (isMemberCompletion) {
|
|
148
157
|
const dotMatch = line.slice(0, position.character).match(/\??\.\s*$/) || undefined;
|
|
149
158
|
if (dotMatch) {
|
|
150
|
-
const range =
|
|
159
|
+
const range = {
|
|
160
|
+
start: { line: position.line, character: position.character - dotMatch[0].length },
|
|
161
|
+
end: position,
|
|
162
|
+
};
|
|
151
163
|
const text = document.getText(range);
|
|
152
164
|
dotAccessorContext = { range, text };
|
|
153
165
|
}
|
|
@@ -160,10 +172,22 @@ function register(ctx) {
|
|
|
160
172
|
if (!tsEntry.replacementSpan) {
|
|
161
173
|
return;
|
|
162
174
|
}
|
|
163
|
-
let replaceRange =
|
|
175
|
+
let replaceRange = {
|
|
176
|
+
start: document.positionAt(tsEntry.replacementSpan.start),
|
|
177
|
+
end: document.positionAt(tsEntry.replacementSpan.start + tsEntry.replacementSpan.length),
|
|
178
|
+
};
|
|
164
179
|
// Make sure we only replace a single line at most
|
|
165
180
|
if (replaceRange.start.line !== replaceRange.end.line) {
|
|
166
|
-
replaceRange =
|
|
181
|
+
replaceRange = {
|
|
182
|
+
start: {
|
|
183
|
+
line: replaceRange.start.line,
|
|
184
|
+
character: replaceRange.start.character,
|
|
185
|
+
},
|
|
186
|
+
end: {
|
|
187
|
+
line: replaceRange.start.line,
|
|
188
|
+
character: document.positionAt(document.offsetAt({ line: replaceRange.start.line + 1, character: 0 }) - 1).character,
|
|
189
|
+
},
|
|
190
|
+
};
|
|
167
191
|
}
|
|
168
192
|
// If TS returns an explicit replacement range, we should use it for both types of completion
|
|
169
193
|
return {
|
|
@@ -208,48 +232,48 @@ function register(ctx) {
|
|
|
208
232
|
switch (kind) {
|
|
209
233
|
case PConst.Kind.primitiveType:
|
|
210
234
|
case PConst.Kind.keyword:
|
|
211
|
-
return
|
|
235
|
+
return 14;
|
|
212
236
|
case PConst.Kind.const:
|
|
213
237
|
case PConst.Kind.let:
|
|
214
238
|
case PConst.Kind.variable:
|
|
215
239
|
case PConst.Kind.localVariable:
|
|
216
240
|
case PConst.Kind.alias:
|
|
217
241
|
case PConst.Kind.parameter:
|
|
218
|
-
return
|
|
242
|
+
return 6;
|
|
219
243
|
case PConst.Kind.memberVariable:
|
|
220
244
|
case PConst.Kind.memberGetAccessor:
|
|
221
245
|
case PConst.Kind.memberSetAccessor:
|
|
222
|
-
return
|
|
246
|
+
return 5;
|
|
223
247
|
case PConst.Kind.function:
|
|
224
248
|
case PConst.Kind.localFunction:
|
|
225
|
-
return
|
|
249
|
+
return 3;
|
|
226
250
|
case PConst.Kind.method:
|
|
227
251
|
case PConst.Kind.constructSignature:
|
|
228
252
|
case PConst.Kind.callSignature:
|
|
229
253
|
case PConst.Kind.indexSignature:
|
|
230
|
-
return
|
|
254
|
+
return 2;
|
|
231
255
|
case PConst.Kind.enum:
|
|
232
|
-
return
|
|
256
|
+
return 13;
|
|
233
257
|
case PConst.Kind.enumMember:
|
|
234
|
-
return
|
|
258
|
+
return 20;
|
|
235
259
|
case PConst.Kind.module:
|
|
236
260
|
case PConst.Kind.externalModuleName:
|
|
237
|
-
return
|
|
261
|
+
return 9;
|
|
238
262
|
case PConst.Kind.class:
|
|
239
263
|
case PConst.Kind.type:
|
|
240
|
-
return
|
|
264
|
+
return 7;
|
|
241
265
|
case PConst.Kind.interface:
|
|
242
|
-
return
|
|
266
|
+
return 8;
|
|
243
267
|
case PConst.Kind.warning:
|
|
244
|
-
return
|
|
268
|
+
return 1;
|
|
245
269
|
case PConst.Kind.script:
|
|
246
|
-
return
|
|
270
|
+
return 17;
|
|
247
271
|
case PConst.Kind.directory:
|
|
248
|
-
return
|
|
272
|
+
return 19;
|
|
249
273
|
case PConst.Kind.string:
|
|
250
|
-
return
|
|
274
|
+
return 21;
|
|
251
275
|
default:
|
|
252
|
-
return
|
|
276
|
+
return 10;
|
|
253
277
|
}
|
|
254
278
|
}
|
|
255
279
|
function getCommitCharacters(entry, context) {
|
|
@@ -271,7 +295,10 @@ function register(ctx) {
|
|
|
271
295
|
// Only enable dot completions when the previous character is not a dot preceded by whitespace.
|
|
272
296
|
// Prevents incorrectly completing while typing spread operators.
|
|
273
297
|
if (position.character > 1) {
|
|
274
|
-
const preText = document.getText(
|
|
298
|
+
const preText = document.getText({
|
|
299
|
+
start: { line: position.line, character: 0 },
|
|
300
|
+
end: position,
|
|
301
|
+
});
|
|
275
302
|
return preText.match(/(\s|^)\.$/ig) === null;
|
|
276
303
|
}
|
|
277
304
|
}
|
|
@@ -293,10 +320,10 @@ function handleKindModifiers(item, tsEntry) {
|
|
|
293
320
|
item.label += '?';
|
|
294
321
|
}
|
|
295
322
|
if (kindModifiers.has(PConst.KindModifiers.deprecated)) {
|
|
296
|
-
item.tags = [
|
|
323
|
+
item.tags = [1];
|
|
297
324
|
}
|
|
298
325
|
if (kindModifiers.has(PConst.KindModifiers.color)) {
|
|
299
|
-
item.kind =
|
|
326
|
+
item.kind = 16;
|
|
300
327
|
}
|
|
301
328
|
if (tsEntry.kind === PConst.Kind.script) {
|
|
302
329
|
for (const extModifier of PConst.KindModifiers.fileExtensionKindModifiers) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import * as vscode from '
|
|
1
|
+
import type * as vscode from '@volar/language-service';
|
|
2
2
|
import { SharedContext } from '../../types';
|
|
3
3
|
export declare function register(ctx: SharedContext): (uri: string, position: vscode.Position) => vscode.CompletionItem[] | undefined;
|
|
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.register = void 0;
|
|
27
|
-
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
28
27
|
const nls = __importStar(require("vscode-nls"));
|
|
29
28
|
const localize = nls.loadMessageBundle(); // TODO: not working
|
|
30
29
|
const directives = [
|
|
@@ -54,11 +53,20 @@ function register(ctx) {
|
|
|
54
53
|
const match = prefix.match(/^\s*\/\/+\s?(@[a-zA-Z\-]*)?$/);
|
|
55
54
|
if (match) {
|
|
56
55
|
return directives.map(directive => {
|
|
57
|
-
const item =
|
|
58
|
-
item.insertTextFormat =
|
|
56
|
+
const item = { label: directive.value };
|
|
57
|
+
item.insertTextFormat = 2;
|
|
59
58
|
item.detail = directive.description;
|
|
60
|
-
const range =
|
|
61
|
-
|
|
59
|
+
const range = {
|
|
60
|
+
start: {
|
|
61
|
+
line: position.line,
|
|
62
|
+
character: Math.max(0, position.character - (match[1] ? match[1].length : 0)),
|
|
63
|
+
},
|
|
64
|
+
end: position,
|
|
65
|
+
};
|
|
66
|
+
item.textEdit = {
|
|
67
|
+
range,
|
|
68
|
+
newText: directive.value,
|
|
69
|
+
};
|
|
62
70
|
return item;
|
|
63
71
|
});
|
|
64
72
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { SharedContext } from '../../types';
|
|
2
|
-
import * as vscode from '
|
|
2
|
+
import type * as vscode from '@volar/language-service';
|
|
3
3
|
export declare function register(ctx: SharedContext): (uri: string, position: vscode.Position) => vscode.CompletionItem | undefined;
|
|
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.register = void 0;
|
|
27
|
-
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
28
27
|
const nls = __importStar(require("vscode-nls"));
|
|
29
28
|
const resolve_1 = require("./resolve");
|
|
30
29
|
const localize = nls.loadMessageBundle(); // TODO: not working
|
|
@@ -57,18 +56,18 @@ function register(ctx) {
|
|
|
57
56
|
}
|
|
58
57
|
exports.register = register;
|
|
59
58
|
function createCompletionItem(document, position, insertText) {
|
|
60
|
-
const item =
|
|
61
|
-
item.kind =
|
|
59
|
+
const item = { label: '/** */' };
|
|
60
|
+
item.kind = 1;
|
|
62
61
|
item.detail = localize('typescript.jsDocCompletionItem.documentation', 'JSDoc comment');
|
|
63
62
|
item.sortText = '\0';
|
|
64
|
-
item.insertTextFormat =
|
|
63
|
+
item.insertTextFormat = 2;
|
|
65
64
|
const line = (0, resolve_1.getLineText)(document, position.line);
|
|
66
65
|
const prefix = line.slice(0, position.character).match(/\/\**\s*$/);
|
|
67
66
|
const suffix = line.slice(position.character).match(/^\s*\**\//);
|
|
68
|
-
const start =
|
|
69
|
-
const end =
|
|
70
|
-
const range =
|
|
71
|
-
item.textEdit =
|
|
67
|
+
const start = { line: position.line, character: position.character + (prefix ? -prefix[0].length : 0) };
|
|
68
|
+
const end = { line: position.line, character: position.character + (suffix ? suffix[0].length : 0) };
|
|
69
|
+
const range = { start, end };
|
|
70
|
+
item.textEdit = { range, newText: insertText };
|
|
72
71
|
return item;
|
|
73
72
|
}
|
|
74
73
|
function isPotentiallyValidDocCompletionPosition(document, position) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SharedContext } from '../../types';
|
|
2
|
-
import * as vscode from '
|
|
3
|
-
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
+
import type * as vscode from '@volar/language-service';
|
|
3
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
export declare function register(ctx: SharedContext): (item: vscode.CompletionItem, newPosition?: vscode.Position) => Promise<vscode.CompletionItem>;
|
|
5
5
|
export declare function getLineText(document: TextDocument, line: number): string;
|
|
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.getLineText = exports.register = void 0;
|
|
27
|
-
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
28
27
|
const getFormatCodeSettings_1 = require("../../configs/getFormatCodeSettings");
|
|
29
28
|
const getUserPreferences_1 = require("../../configs/getUserPreferences");
|
|
30
29
|
const shared_1 = require("../../shared");
|
|
@@ -78,7 +77,7 @@ function register(ctx) {
|
|
|
78
77
|
});
|
|
79
78
|
const locs = (0, transforms_1.entriesToLocations)(entries, ctx);
|
|
80
79
|
locs.forEach((loc, index) => {
|
|
81
|
-
item.additionalTextEdits?.push(
|
|
80
|
+
item.additionalTextEdits?.push({ range: loc.range, newText: changes.textChanges[index].newText });
|
|
82
81
|
});
|
|
83
82
|
}
|
|
84
83
|
}
|
|
@@ -98,7 +97,7 @@ function register(ctx) {
|
|
|
98
97
|
}
|
|
99
98
|
if (document) {
|
|
100
99
|
const useCodeSnippetsOnMethodSuggest = await ctx.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.suggest.completeFunctionCalls') ?? false;
|
|
101
|
-
const useCodeSnippet = useCodeSnippetsOnMethodSuggest && (item.kind ===
|
|
100
|
+
const useCodeSnippet = useCodeSnippetsOnMethodSuggest && (item.kind === 3 || item.kind === 2);
|
|
102
101
|
if (useCodeSnippet) {
|
|
103
102
|
const shouldCompleteFunction = isValidFunctionCompletionContext(ctx.typescript.languageService, fileName, offset, document);
|
|
104
103
|
if (shouldCompleteFunction) {
|
|
@@ -112,7 +111,7 @@ function register(ctx) {
|
|
|
112
111
|
if (item.insertText) {
|
|
113
112
|
item.insertText = snippet;
|
|
114
113
|
}
|
|
115
|
-
item.insertTextFormat =
|
|
114
|
+
item.insertTextFormat = 2;
|
|
116
115
|
if (parameterCount > 0) {
|
|
117
116
|
//Fix for https://github.com/microsoft/vscode/issues/104059
|
|
118
117
|
//Don't show parameter hints if "editor.parameterHints.enabled": false
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import * as vscode from '
|
|
1
|
+
import type * as vscode from '@volar/language-service';
|
|
2
2
|
import { SharedContext } from '../types';
|
|
3
3
|
export declare function register(ctx: SharedContext): (uri: string, position: vscode.Position) => vscode.LocationLink[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as vscode from '
|
|
1
|
+
import type * as vscode from '@volar/language-service';
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
3
|
import { SharedContext } from '../types';
|
|
4
4
|
export declare function register(ctx: SharedContext): (uri: string, options: {
|