volar-service-typescript 0.0.31-patch.1 → 0.0.32

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.
Files changed (77) hide show
  1. package/index.d.ts +4 -17
  2. package/index.js +12 -545
  3. package/lib/configs/getFormatCodeSettings.d.ts +2 -3
  4. package/lib/configs/getUserPreferences.d.ts +1 -1
  5. package/lib/plugins/directiveComment.d.ts +3 -0
  6. package/lib/plugins/directiveComment.js +65 -0
  7. package/lib/plugins/docCommentTemplate.d.ts +3 -0
  8. package/lib/{features/completions/jsDoc.js → plugins/docCommentTemplate.js} +42 -30
  9. package/lib/plugins/semantic.d.ts +23 -0
  10. package/lib/plugins/semantic.js +706 -0
  11. package/lib/plugins/syntactic.d.ts +7 -0
  12. package/lib/plugins/syntactic.js +92 -0
  13. package/lib/{features → semanticFeatures}/codeAction.d.ts +3 -2
  14. package/lib/{features → semanticFeatures}/codeAction.js +14 -17
  15. package/lib/{features → semanticFeatures}/codeActionResolve.d.ts +1 -1
  16. package/lib/{features → semanticFeatures}/codeActionResolve.js +7 -7
  17. package/lib/semanticFeatures/semanticTokens.d.ts +5 -0
  18. package/lib/{features → semanticFeatures}/semanticTokens.js +4 -8
  19. package/lib/{types.d.ts → semanticFeatures/types.d.ts} +1 -2
  20. package/lib/shared.d.ts +1 -0
  21. package/lib/shared.js +5 -1
  22. package/lib/syntacticLanguageService.d.ts +7 -0
  23. package/lib/syntacticLanguageService.js +38 -0
  24. package/lib/utils/lspConverters.d.ts +27 -0
  25. package/lib/utils/lspConverters.js +782 -0
  26. package/lib/utils/previewer.d.ts +5 -11
  27. package/lib/utils/previewer.js +30 -35
  28. package/package.json +5 -6
  29. package/lib/features/callHierarchy.d.ts +0 -8
  30. package/lib/features/callHierarchy.js +0 -102
  31. package/lib/features/completions/basic.d.ts +0 -17
  32. package/lib/features/completions/basic.js +0 -326
  33. package/lib/features/completions/directiveComment.d.ts +0 -4
  34. package/lib/features/completions/directiveComment.js +0 -54
  35. package/lib/features/completions/jsDoc.d.ts +0 -4
  36. package/lib/features/completions/resolve.d.ts +0 -6
  37. package/lib/features/completions/resolve.js +0 -146
  38. package/lib/features/definition.d.ts +0 -4
  39. package/lib/features/definition.js +0 -20
  40. package/lib/features/diagnostics.d.ts +0 -11
  41. package/lib/features/diagnostics.js +0 -120
  42. package/lib/features/documentHighlight.d.ts +0 -4
  43. package/lib/features/documentHighlight.js +0 -32
  44. package/lib/features/documentSymbol.d.ts +0 -4
  45. package/lib/features/documentSymbol.js +0 -94
  46. package/lib/features/fileReferences.d.ts +0 -4
  47. package/lib/features/fileReferences.js +0 -19
  48. package/lib/features/fileRename.d.ts +0 -4
  49. package/lib/features/fileRename.js +0 -25
  50. package/lib/features/foldingRanges.d.ts +0 -4
  51. package/lib/features/foldingRanges.js +0 -55
  52. package/lib/features/formatting.d.ts +0 -8
  53. package/lib/features/formatting.js +0 -55
  54. package/lib/features/hover.d.ts +0 -4
  55. package/lib/features/hover.js +0 -43
  56. package/lib/features/implementation.d.ts +0 -4
  57. package/lib/features/implementation.js +0 -20
  58. package/lib/features/inlayHints.d.ts +0 -4
  59. package/lib/features/inlayHints.js +0 -34
  60. package/lib/features/prepareRename.d.ts +0 -9
  61. package/lib/features/prepareRename.js +0 -27
  62. package/lib/features/references.d.ts +0 -4
  63. package/lib/features/references.js +0 -35
  64. package/lib/features/rename.d.ts +0 -6
  65. package/lib/features/rename.js +0 -116
  66. package/lib/features/selectionRanges.d.ts +0 -4
  67. package/lib/features/selectionRanges.js +0 -32
  68. package/lib/features/semanticTokens.d.ts +0 -4
  69. package/lib/features/signatureHelp.d.ts +0 -4
  70. package/lib/features/signatureHelp.js +0 -63
  71. package/lib/features/typeDefinition.d.ts +0 -4
  72. package/lib/features/typeDefinition.js +0 -20
  73. package/lib/features/workspaceSymbol.d.ts +0 -4
  74. package/lib/features/workspaceSymbol.js +0 -63
  75. package/lib/utils/transforms.d.ts +0 -15
  76. package/lib/utils/transforms.js +0 -85
  77. /package/lib/{types.js → semanticFeatures/types.js} +0 -0
@@ -1,13 +1,7 @@
1
1
  import type * as ts from 'typescript';
2
- import type { SharedContext } from '../types';
3
- export interface IFilePathToResourceConverter {
4
- /**
5
- * Convert a typescript filepath to a VS Code resource.
6
- */
7
- toResource(filepath: string): string;
8
- }
9
- export declare function plainWithLinks(parts: readonly ts.server.protocol.SymbolDisplayPart[] | string, filePathConverter: IFilePathToResourceConverter, ctx: SharedContext): string;
10
- export declare function tagsMarkdownPreview(tags: readonly ts.JSDocTagInfo[], filePathConverter: IFilePathToResourceConverter, ctx: SharedContext): string;
11
- export declare function markdownDocumentation(documentation: ts.server.protocol.SymbolDisplayPart[] | string | undefined, tags: ts.JSDocTagInfo[] | undefined, filePathConverter: IFilePathToResourceConverter, ctx: SharedContext): string;
12
- export declare function addMarkdownDocumentation(out: string, documentation: ts.server.protocol.SymbolDisplayPart[] | string | undefined, tags: ts.JSDocTagInfo[] | undefined, converter: IFilePathToResourceConverter, ctx: SharedContext): string;
2
+ import type { TextDocument } from 'vscode-languageserver-textdocument';
3
+ export declare function plainWithLinks(parts: readonly ts.server.protocol.SymbolDisplayPart[] | string, fileNameToUri: (fileName: string) => string, getTextDocument: (uri: string) => TextDocument): string;
4
+ export declare function tagsMarkdownPreview(tags: readonly ts.JSDocTagInfo[], fileNameToUri: (fileName: string) => string, getTextDocument: (uri: string) => TextDocument): string;
5
+ export declare function markdownDocumentation(documentation: ts.server.protocol.SymbolDisplayPart[] | string | undefined, tags: ts.JSDocTagInfo[] | undefined, fileNameToUri: (fileName: string) => string, getTextDocument: (uri: string) => TextDocument): string;
6
+ export declare function addMarkdownDocumentation(out: string, documentation: ts.server.protocol.SymbolDisplayPart[] | string | undefined, tags: ts.JSDocTagInfo[] | undefined, fileNameToUri: (fileName: string) => string, getTextDocument: (uri: string) => TextDocument): string;
13
7
  //# sourceMappingURL=previewer.d.ts.map
@@ -20,7 +20,7 @@ function replaceLinks(text) {
20
20
  function processInlineTags(text) {
21
21
  return replaceLinks(text);
22
22
  }
23
- function getTagBodyText(tag, filePathConverter, ctx) {
23
+ function getTagBodyText(tag, fileNameToUri, getTextDocument) {
24
24
  if (!tag.text) {
25
25
  return undefined;
26
26
  }
@@ -31,7 +31,7 @@ function getTagBodyText(tag, filePathConverter, ctx) {
31
31
  }
32
32
  return '```\n' + text + '\n```';
33
33
  }
34
- const text = convertLinkTags(tag.text, filePathConverter, ctx);
34
+ const text = convertLinkTags(tag.text, fileNameToUri, getTextDocument);
35
35
  switch (tag.name) {
36
36
  case 'example':
37
37
  // check for caption tags, fix for #79704
@@ -56,13 +56,13 @@ function getTagBodyText(tag, filePathConverter, ctx) {
56
56
  }
57
57
  return processInlineTags(text);
58
58
  }
59
- function getTagDocumentation(tag, filePathConverter, ctx) {
59
+ function getTagDocumentation(tag, fileNameToUri, getTextDocument) {
60
60
  switch (tag.name) {
61
61
  case 'augments':
62
62
  case 'extends':
63
63
  case 'param':
64
64
  case 'template':
65
- const body = (convertLinkTags(tag.text, filePathConverter, ctx)).split(/^(\S+)\s*-?\s*/);
65
+ const body = (convertLinkTags(tag.text, fileNameToUri, getTextDocument)).split(/^(\S+)\s*-?\s*/);
66
66
  if (body?.length === 3) {
67
67
  const param = body[1];
68
68
  const doc = body[2];
@@ -75,20 +75,20 @@ function getTagDocumentation(tag, filePathConverter, ctx) {
75
75
  }
76
76
  // Generic tag
77
77
  const label = `*@${tag.name}*`;
78
- const text = getTagBodyText(tag, filePathConverter, ctx);
78
+ const text = getTagBodyText(tag, fileNameToUri, getTextDocument);
79
79
  if (!text) {
80
80
  return label;
81
81
  }
82
82
  return label + (text.match(/\r\n|\n/g) ? ' \n' + text : ` — ${text}`);
83
83
  }
84
- function plainWithLinks(parts, filePathConverter, ctx) {
85
- return processInlineTags(convertLinkTags(parts, filePathConverter, ctx));
84
+ function plainWithLinks(parts, fileNameToUri, getTextDocument) {
85
+ return processInlineTags(convertLinkTags(parts, fileNameToUri, getTextDocument));
86
86
  }
87
87
  exports.plainWithLinks = plainWithLinks;
88
88
  /**
89
89
  * Convert `@link` inline tags to markdown links
90
90
  */
91
- function convertLinkTags(parts, filePathConverter, ctx) {
91
+ function convertLinkTags(parts, fileNameToUri, getTextDocument) {
92
92
  if (!parts) {
93
93
  return '';
94
94
  }
@@ -105,28 +105,23 @@ function convertLinkTags(parts, filePathConverter, ctx) {
105
105
  let target = currentLink.target;
106
106
  if (typeof currentLink.target === 'object' && 'fileName' in currentLink.target) {
107
107
  const _target = currentLink.target;
108
- const fileDoc = ctx.getTextDocument(ctx.uriToFileName(_target.fileName));
109
- if (fileDoc) {
110
- const start = fileDoc.positionAt(_target.textSpan.start);
111
- const end = fileDoc.positionAt(_target.textSpan.start + _target.textSpan.length);
112
- target = {
113
- file: _target.fileName,
114
- start: {
115
- line: start.line + 1,
116
- offset: start.character + 1,
117
- },
118
- end: {
119
- line: end.line + 1,
120
- offset: end.character + 1,
121
- },
122
- };
123
- }
124
- else {
125
- target = undefined;
126
- }
108
+ const fileDoc = getTextDocument(fileNameToUri(_target.fileName));
109
+ const start = fileDoc.positionAt(_target.textSpan.start);
110
+ const end = fileDoc.positionAt(_target.textSpan.start + _target.textSpan.length);
111
+ target = {
112
+ file: _target.fileName,
113
+ start: {
114
+ line: start.line + 1,
115
+ offset: start.character + 1,
116
+ },
117
+ end: {
118
+ line: end.line + 1,
119
+ offset: end.character + 1,
120
+ },
121
+ };
127
122
  }
128
123
  if (target) {
129
- const link = filePathConverter.toResource(target.file) + '#' + `L${target.start.line},${target.start.offset}`;
124
+ const link = fileNameToUri(target.file) + '#' + `L${target.start.line},${target.start.offset}`;
130
125
  out.push(`[${text}](${link})`);
131
126
  }
132
127
  else {
@@ -158,20 +153,20 @@ function convertLinkTags(parts, filePathConverter, ctx) {
158
153
  }
159
154
  return processInlineTags(out.join(''));
160
155
  }
161
- function tagsMarkdownPreview(tags, filePathConverter, ctx) {
162
- return tags.map(tag => getTagDocumentation(tag, filePathConverter, ctx)).join(' \n\n');
156
+ function tagsMarkdownPreview(tags, fileNameToUri, getTextDocument) {
157
+ return tags.map(tag => getTagDocumentation(tag, fileNameToUri, getTextDocument)).join(' \n\n');
163
158
  }
164
159
  exports.tagsMarkdownPreview = tagsMarkdownPreview;
165
- function markdownDocumentation(documentation, tags, filePathConverter, ctx) {
166
- return addMarkdownDocumentation('', documentation, tags, filePathConverter, ctx);
160
+ function markdownDocumentation(documentation, tags, fileNameToUri, getTextDocument) {
161
+ return addMarkdownDocumentation('', documentation, tags, fileNameToUri, getTextDocument);
167
162
  }
168
163
  exports.markdownDocumentation = markdownDocumentation;
169
- function addMarkdownDocumentation(out, documentation, tags, converter, ctx) {
164
+ function addMarkdownDocumentation(out, documentation, tags, fileNameToUri, getTextDocument) {
170
165
  if (documentation) {
171
- out += plainWithLinks(documentation, converter, ctx);
166
+ out += plainWithLinks(documentation, fileNameToUri, getTextDocument);
172
167
  }
173
168
  if (tags) {
174
- const tagsPreview = tagsMarkdownPreview(tags, converter, ctx);
169
+ const tagsPreview = tagsMarkdownPreview(tags, fileNameToUri, getTextDocument);
175
170
  if (tagsPreview) {
176
171
  out += '\n\n' + tagsPreview;
177
172
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "volar-service-typescript",
3
- "version": "0.0.31-patch.1",
3
+ "version": "0.0.32",
4
4
  "description": "Integrate TypeScript into Volar",
5
5
  "homepage": "https://github.com/volarjs/services/tree/master/packages/typescript",
6
6
  "bugs": "https://github.com/volarjs/services/issues",
@@ -25,8 +25,7 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/path-browserify": "latest",
28
- "@types/semver": "latest",
29
- "@volar/typescript": "latest"
28
+ "@types/semver": "latest"
30
29
  },
31
30
  "dependencies": {
32
31
  "path-browserify": "^1.0.1",
@@ -36,12 +35,12 @@
36
35
  "vscode-nls": "^5.2.0"
37
36
  },
38
37
  "peerDependencies": {
39
- "@volar/language-service": "~2.1.0",
40
- "@volar/typescript": "~2.1.0"
38
+ "@volar/language-service": "~2.1.0"
41
39
  },
42
40
  "peerDependenciesMeta": {
43
41
  "@volar/language-service": {
44
42
  "optional": true
45
43
  }
46
- }
44
+ },
45
+ "gitHead": "717049e7dcd5c30f451f6db8eb71eaba43f74c83"
47
46
  }
@@ -1,8 +0,0 @@
1
- import type * as vscode from '@volar/language-service';
2
- import type { SharedContext } from '../types';
3
- export declare function register(ctx: SharedContext): {
4
- doPrepare: (uri: string, position: vscode.Position) => vscode.CallHierarchyItem[];
5
- getIncomingCalls: (item: vscode.CallHierarchyItem) => vscode.CallHierarchyIncomingCall[];
6
- getOutgoingCalls: (item: vscode.CallHierarchyItem) => vscode.CallHierarchyOutgoingCall[];
7
- };
8
- //# sourceMappingURL=callHierarchy.d.ts.map
@@ -1,102 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.register = void 0;
4
- const path = require("path-browserify");
5
- const PConst = require("../protocol.const");
6
- const shared_1 = require("../shared");
7
- const modifiers_1 = require("../utils/modifiers");
8
- const typeConverters = require("../utils/typeConverters");
9
- function register(ctx) {
10
- function doPrepare(uri, position) {
11
- const document = ctx.getTextDocument(uri);
12
- if (!document)
13
- return [];
14
- const fileName = ctx.uriToFileName(document.uri);
15
- const offset = document.offsetAt(position);
16
- const calls = (0, shared_1.safeCall)(() => ctx.languageService.prepareCallHierarchy(fileName, offset));
17
- if (!calls)
18
- return [];
19
- const items = Array.isArray(calls) ? calls : [calls];
20
- return items.map(item => fromProtocolCallHierarchyItem(item));
21
- }
22
- function getIncomingCalls(item) {
23
- const document = ctx.getTextDocument(item.uri);
24
- if (!document)
25
- return [];
26
- const fileName = ctx.uriToFileName(item.uri);
27
- const offset = document.offsetAt(item.selectionRange.start);
28
- const calls = (0, shared_1.safeCall)(() => ctx.languageService.provideCallHierarchyIncomingCalls(fileName, offset));
29
- if (!calls)
30
- return [];
31
- const items = Array.isArray(calls) ? calls : [calls];
32
- return items.map(item => fromProtocolCallHierarchyIncomingCall(item));
33
- }
34
- function getOutgoingCalls(item) {
35
- const document = ctx.getTextDocument(item.uri);
36
- if (!document)
37
- return [];
38
- const fileName = ctx.uriToFileName(item.uri);
39
- const offset = document.offsetAt(item.selectionRange.start);
40
- const calls = (0, shared_1.safeCall)(() => ctx.languageService.provideCallHierarchyOutgoingCalls(fileName, offset));
41
- if (!calls)
42
- return [];
43
- const items = Array.isArray(calls) ? calls : [calls];
44
- return items.map(item => fromProtocolCallHierarchyOutgoingCall(item, document));
45
- }
46
- return {
47
- doPrepare,
48
- getIncomingCalls,
49
- getOutgoingCalls,
50
- };
51
- function isSourceFileItem(item) {
52
- return item.kind === PConst.Kind.script || item.kind === PConst.Kind.module && item.selectionSpan.start === 0;
53
- }
54
- function fromProtocolCallHierarchyItem(item) {
55
- const rootPath = ctx.languageService.getProgram()?.getCompilerOptions().rootDir ?? '';
56
- const document = ctx.getTextDocument(ctx.fileNameToUri(item.file)); // TODO
57
- const useFileName = isSourceFileItem(item);
58
- const name = useFileName ? path.basename(item.file) : item.name;
59
- const detail = useFileName ? path.relative(rootPath, path.dirname(item.file)) : item.containerName ?? '';
60
- const result = {
61
- kind: typeConverters.SymbolKind.fromProtocolScriptElementKind(item.kind),
62
- name,
63
- detail,
64
- uri: ctx.fileNameToUri(item.file),
65
- range: {
66
- start: document.positionAt(item.span.start),
67
- end: document.positionAt(item.span.start + item.span.length),
68
- },
69
- selectionRange: {
70
- start: document.positionAt(item.selectionSpan.start),
71
- end: document.positionAt(item.selectionSpan.start + item.selectionSpan.length),
72
- },
73
- };
74
- const kindModifiers = item.kindModifiers ? (0, modifiers_1.parseKindModifier)(item.kindModifiers) : undefined;
75
- if (kindModifiers?.has(PConst.KindModifiers.deprecated)) {
76
- result.tags = [1];
77
- }
78
- return result;
79
- }
80
- function fromProtocolCallHierarchyIncomingCall(item) {
81
- const document = ctx.getTextDocument(ctx.fileNameToUri(item.from.file));
82
- return {
83
- from: fromProtocolCallHierarchyItem(item.from),
84
- fromRanges: item.fromSpans.map(fromSpan => ({
85
- start: document.positionAt(fromSpan.start),
86
- end: document.positionAt(fromSpan.start + fromSpan.length),
87
- })),
88
- };
89
- }
90
- function fromProtocolCallHierarchyOutgoingCall(item, document) {
91
- return {
92
- to: fromProtocolCallHierarchyItem(item.to),
93
- fromRanges: item.fromSpans.map(fromSpan => ({
94
- start: document.positionAt(fromSpan.start),
95
- end: document.positionAt(fromSpan.start + fromSpan.length),
96
- })),
97
- };
98
- }
99
- }
100
- exports.register = register;
101
- ;
102
- //# sourceMappingURL=callHierarchy.js.map
@@ -1,17 +0,0 @@
1
- import type * as vscode from '@volar/language-service';
2
- import type * as ts from 'typescript';
3
- import type { SharedContext } from '../../types';
4
- export interface Data {
5
- uri: string;
6
- fileName: string;
7
- offset: number;
8
- originalItem: {
9
- name: ts.CompletionEntry['name'];
10
- source: ts.CompletionEntry['source'];
11
- data: ts.CompletionEntry['data'];
12
- labelDetails: ts.CompletionEntry['labelDetails'];
13
- };
14
- }
15
- export declare function register(ctx: SharedContext): (uri: string, position: vscode.Position, options?: ts.GetCompletionsAtPositionOptions | undefined) => Promise<vscode.CompletionList | undefined>;
16
- export declare function handleKindModifiers(item: vscode.CompletionItem, tsEntry: ts.CompletionEntry | ts.CompletionEntryDetails): void;
17
- //# sourceMappingURL=basic.d.ts.map
@@ -1,326 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleKindModifiers = exports.register = void 0;
4
- const semver = require("semver");
5
- const getUserPreferences_1 = require("../../configs/getUserPreferences");
6
- const PConst = require("../../protocol.const");
7
- const shared_1 = require("../../shared");
8
- const modifiers_1 = require("../../utils/modifiers");
9
- function register(ctx) {
10
- const { ts } = ctx;
11
- const lt_320 = semver.lt(ts.version, '3.2.0');
12
- const gte_300 = semver.gte(ts.version, '3.0.0');
13
- return async (uri, position, options) => {
14
- const document = ctx.getTextDocument(uri);
15
- if (!document)
16
- return;
17
- const preferences = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
18
- const fileName = ctx.uriToFileName(document.uri);
19
- const offset = document.offsetAt(position);
20
- const completionContext = (0, shared_1.safeCall)(() => ctx.languageService.getCompletionsAtPosition(fileName, offset, {
21
- ...preferences,
22
- ...options,
23
- }));
24
- if (completionContext === undefined)
25
- return;
26
- const wordRange = completionContext.optionalReplacementSpan ? {
27
- start: document.positionAt(completionContext.optionalReplacementSpan.start),
28
- end: document.positionAt(completionContext.optionalReplacementSpan.start + completionContext.optionalReplacementSpan.length),
29
- } : undefined;
30
- let line = document.getText({
31
- start: { line: position.line, character: 0 },
32
- end: { line: position.line + 1, character: 0 },
33
- });
34
- if (line.endsWith('\n')) {
35
- line = line.substring(0, line.length - 1);
36
- }
37
- const dotAccessorContext = getDotAccessorContext(document);
38
- const entries = completionContext.entries
39
- .map(tsEntry => toVScodeItem(tsEntry, document));
40
- return {
41
- isIncomplete: !!completionContext.isIncomplete,
42
- items: entries,
43
- };
44
- function toVScodeItem(tsEntry, document) {
45
- const item = { label: tsEntry.name };
46
- item.kind = convertKind(tsEntry.kind);
47
- if (tsEntry.source && tsEntry.hasAction) {
48
- // De-prioritize auto-imports
49
- // https://github.com/microsoft/vscode/issues/40311
50
- item.sortText = '\uffff' + tsEntry.sortText;
51
- }
52
- else {
53
- item.sortText = tsEntry.sortText;
54
- }
55
- const { sourceDisplay, isSnippet, labelDetails } = tsEntry;
56
- if (sourceDisplay) {
57
- item.labelDetails ??= {};
58
- item.labelDetails.description = ts.displayPartsToString(sourceDisplay);
59
- }
60
- if (labelDetails) {
61
- item.labelDetails ??= {};
62
- Object.assign(item.labelDetails, labelDetails);
63
- }
64
- item.preselect = tsEntry.isRecommended;
65
- let range = getRangeFromReplacementSpan(tsEntry, document);
66
- item.commitCharacters = getCommitCharacters(tsEntry, {
67
- isNewIdentifierLocation: completionContext.isNewIdentifierLocation,
68
- isInValidCommitCharacterContext: isInValidCommitCharacterContext(document, position),
69
- enableCallCompletions: true, // TODO: suggest.completeFunctionCalls
70
- });
71
- item.insertText = tsEntry.insertText;
72
- item.insertTextFormat = isSnippet ? 2 : 1;
73
- item.filterText = getFilterText(tsEntry, wordRange, line, tsEntry.insertText);
74
- if (completionContext?.isMemberCompletion && dotAccessorContext && !isSnippet) {
75
- item.filterText = dotAccessorContext.text + (item.insertText || item.label);
76
- if (!range) {
77
- const replacementRange = wordRange;
78
- if (replacementRange) {
79
- range = {
80
- inserting: dotAccessorContext.range,
81
- replacing: rangeUnion(dotAccessorContext.range, replacementRange),
82
- };
83
- }
84
- else {
85
- range = dotAccessorContext.range;
86
- }
87
- item.insertText = item.filterText;
88
- }
89
- }
90
- handleKindModifiers(item, tsEntry);
91
- if (!range && wordRange) {
92
- range = {
93
- inserting: { start: wordRange.start, end: position },
94
- replacing: wordRange,
95
- };
96
- }
97
- if (range) {
98
- if ('start' in range) {
99
- item.textEdit = {
100
- range,
101
- newText: item.insertText || item.label,
102
- };
103
- }
104
- else {
105
- item.textEdit = {
106
- insert: range.inserting,
107
- replace: range.replacing,
108
- newText: item.insertText || item.label,
109
- };
110
- }
111
- }
112
- return {
113
- ...item,
114
- data: {
115
- uri,
116
- fileName,
117
- offset,
118
- originalItem: {
119
- name: tsEntry.name,
120
- source: tsEntry.source,
121
- data: tsEntry.data,
122
- labelDetails: tsEntry.labelDetails,
123
- },
124
- },
125
- };
126
- }
127
- function getDotAccessorContext(document) {
128
- let dotAccessorContext;
129
- if (gte_300) {
130
- if (!completionContext)
131
- return;
132
- const isMemberCompletion = completionContext.isMemberCompletion;
133
- if (isMemberCompletion) {
134
- const dotMatch = line.slice(0, position.character).match(/\??\.\s*$/) || undefined;
135
- if (dotMatch) {
136
- const range = {
137
- start: { line: position.line, character: position.character - dotMatch[0].length },
138
- end: position,
139
- };
140
- const text = document.getText(range);
141
- dotAccessorContext = { range, text };
142
- }
143
- }
144
- }
145
- return dotAccessorContext;
146
- }
147
- // from vscode typescript
148
- function getRangeFromReplacementSpan(tsEntry, document) {
149
- if (!tsEntry.replacementSpan) {
150
- return;
151
- }
152
- let replaceRange = {
153
- start: document.positionAt(tsEntry.replacementSpan.start),
154
- end: document.positionAt(tsEntry.replacementSpan.start + tsEntry.replacementSpan.length),
155
- };
156
- // Make sure we only replace a single line at most
157
- if (replaceRange.start.line !== replaceRange.end.line) {
158
- replaceRange = {
159
- start: {
160
- line: replaceRange.start.line,
161
- character: replaceRange.start.character,
162
- },
163
- end: {
164
- line: replaceRange.start.line,
165
- character: document.positionAt(document.offsetAt({ line: replaceRange.start.line + 1, character: 0 }) - 1).character,
166
- },
167
- };
168
- }
169
- // If TS returns an explicit replacement range, we should use it for both types of completion
170
- return {
171
- inserting: replaceRange,
172
- replacing: replaceRange,
173
- };
174
- }
175
- function getFilterText(tsEntry, wordRange, line, insertText) {
176
- // Handle private field completions
177
- if (tsEntry.name.startsWith('#')) {
178
- const wordStart = wordRange ? line.charAt(wordRange.start.character) : undefined;
179
- if (insertText) {
180
- if (insertText.startsWith('this.#')) {
181
- return wordStart === '#' ? insertText : insertText.replace(/^this\.#/, '');
182
- }
183
- else {
184
- return insertText;
185
- }
186
- }
187
- else {
188
- return wordStart === '#' ? undefined : tsEntry.name.replace(/^#/, '');
189
- }
190
- }
191
- // For `this.` completions, generally don't set the filter text since we don't want them to be overly prioritized. #74164
192
- if (insertText?.startsWith('this.')) {
193
- return undefined;
194
- }
195
- // Handle the case:
196
- // ```
197
- // const xyz = { 'ab c': 1 };
198
- // xyz.ab|
199
- // ```
200
- // In which case we want to insert a bracket accessor but should use `.abc` as the filter text instead of
201
- // the bracketed insert text.
202
- else if (insertText?.startsWith('[')) {
203
- return insertText.replace(/^\[['"](.+)[['"]\]$/, '.$1');
204
- }
205
- // In all other cases, fallback to using the insertText
206
- return insertText;
207
- }
208
- function convertKind(kind) {
209
- switch (kind) {
210
- case PConst.Kind.primitiveType:
211
- case PConst.Kind.keyword:
212
- return 14;
213
- case PConst.Kind.const:
214
- case PConst.Kind.let:
215
- case PConst.Kind.variable:
216
- case PConst.Kind.localVariable:
217
- case PConst.Kind.alias:
218
- case PConst.Kind.parameter:
219
- return 6;
220
- case PConst.Kind.memberVariable:
221
- case PConst.Kind.memberGetAccessor:
222
- case PConst.Kind.memberSetAccessor:
223
- return 5;
224
- case PConst.Kind.function:
225
- case PConst.Kind.localFunction:
226
- return 3;
227
- case PConst.Kind.method:
228
- case PConst.Kind.constructSignature:
229
- case PConst.Kind.callSignature:
230
- case PConst.Kind.indexSignature:
231
- return 2;
232
- case PConst.Kind.enum:
233
- return 13;
234
- case PConst.Kind.enumMember:
235
- return 20;
236
- case PConst.Kind.module:
237
- case PConst.Kind.externalModuleName:
238
- return 9;
239
- case PConst.Kind.class:
240
- case PConst.Kind.type:
241
- return 7;
242
- case PConst.Kind.interface:
243
- return 8;
244
- case PConst.Kind.warning:
245
- return 1;
246
- case PConst.Kind.script:
247
- return 17;
248
- case PConst.Kind.directory:
249
- return 19;
250
- case PConst.Kind.string:
251
- return 21;
252
- default:
253
- return 10;
254
- }
255
- }
256
- function getCommitCharacters(entry, context) {
257
- if (entry.kind === PConst.Kind.warning) { // Ambient JS word based suggestion
258
- return undefined;
259
- }
260
- if (context.isNewIdentifierLocation || !context.isInValidCommitCharacterContext) {
261
- return undefined;
262
- }
263
- const commitCharacters = ['.', ',', ';'];
264
- if (context.enableCallCompletions) {
265
- commitCharacters.push('(');
266
- }
267
- return commitCharacters;
268
- }
269
- function isInValidCommitCharacterContext(document, position) {
270
- if (lt_320) {
271
- // Workaround for https://github.com/microsoft/TypeScript/issues/27742
272
- // Only enable dot completions when the previous character is not a dot preceded by whitespace.
273
- // Prevents incorrectly completing while typing spread operators.
274
- if (position.character > 1) {
275
- const preText = document.getText({
276
- start: { line: position.line, character: 0 },
277
- end: position,
278
- });
279
- return preText.match(/(\s|^)\.$/ig) === null;
280
- }
281
- }
282
- return true;
283
- }
284
- };
285
- }
286
- exports.register = register;
287
- function handleKindModifiers(item, tsEntry) {
288
- if (tsEntry.kindModifiers) {
289
- const kindModifiers = (0, modifiers_1.parseKindModifier)(tsEntry.kindModifiers);
290
- if (kindModifiers.has(PConst.KindModifiers.optional)) {
291
- if (!item.insertText) {
292
- item.insertText = item.label;
293
- }
294
- if (!item.filterText) {
295
- item.filterText = item.label;
296
- }
297
- item.label += '?';
298
- }
299
- if (kindModifiers.has(PConst.KindModifiers.deprecated)) {
300
- item.tags = [1];
301
- }
302
- if (kindModifiers.has(PConst.KindModifiers.color)) {
303
- item.kind = 16;
304
- }
305
- if (tsEntry.kind === PConst.Kind.script) {
306
- for (const extModifier of PConst.KindModifiers.fileExtensionKindModifiers) {
307
- if (kindModifiers.has(extModifier)) {
308
- if (tsEntry.name.toLowerCase().endsWith(extModifier)) {
309
- item.detail = tsEntry.name;
310
- }
311
- else {
312
- item.detail = tsEntry.name + extModifier;
313
- }
314
- break;
315
- }
316
- }
317
- }
318
- }
319
- }
320
- exports.handleKindModifiers = handleKindModifiers;
321
- function rangeUnion(a, b) {
322
- const start = (a.start.line < b.start.line || (a.start.line === b.start.line && a.start.character < b.start.character)) ? a.start : b.start;
323
- const end = (a.end.line > b.end.line || (a.end.line === b.end.line && a.end.character > b.end.character)) ? a.end : b.end;
324
- return { start, end };
325
- }
326
- //# sourceMappingURL=basic.js.map
@@ -1,4 +0,0 @@
1
- import type * as vscode from '@volar/language-service';
2
- import type { SharedContext } from '../../types';
3
- export declare function register(ctx: SharedContext): (uri: string, position: vscode.Position) => vscode.CompletionItem[] | undefined;
4
- //# sourceMappingURL=directiveComment.d.ts.map