volar-service-typescript 0.0.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.
Files changed (82) hide show
  1. package/out/configs/getFormatCodeSettings.d.ts +5 -0
  2. package/out/configs/getFormatCodeSettings.js +34 -0
  3. package/out/configs/getUserPreferences.d.ts +4 -0
  4. package/out/configs/getUserPreferences.js +97 -0
  5. package/out/index.d.ts +3 -0
  6. package/out/index.js +421 -0
  7. package/out/protocol.const.d.ts +72 -0
  8. package/out/protocol.const.js +92 -0
  9. package/out/services/callHierarchy.d.ts +7 -0
  10. package/out/services/callHierarchy.js +126 -0
  11. package/out/services/codeAction.d.ts +26 -0
  12. package/out/services/codeAction.js +242 -0
  13. package/out/services/codeActionResolve.d.ts +9 -0
  14. package/out/services/codeActionResolve.js +51 -0
  15. package/out/services/completions/basic.d.ts +16 -0
  16. package/out/services/completions/basic.js +322 -0
  17. package/out/services/completions/directiveComment.d.ts +3 -0
  18. package/out/services/completions/directiveComment.js +69 -0
  19. package/out/services/completions/jsDoc.d.ts +3 -0
  20. package/out/services/completions/jsDoc.js +106 -0
  21. package/out/services/completions/resolve.d.ts +5 -0
  22. package/out/services/completions/resolve.js +170 -0
  23. package/out/services/definition.d.ts +3 -0
  24. package/out/services/definition.js +20 -0
  25. package/out/services/diagnostics.d.ts +10 -0
  26. package/out/services/diagnostics.js +144 -0
  27. package/out/services/documentHighlight.d.ts +3 -0
  28. package/out/services/documentHighlight.js +56 -0
  29. package/out/services/documentSymbol.d.ts +3 -0
  30. package/out/services/documentSymbol.js +106 -0
  31. package/out/services/fileReferences.d.ts +3 -0
  32. package/out/services/fileReferences.js +19 -0
  33. package/out/services/fileRename.d.ts +3 -0
  34. package/out/services/fileRename.js +25 -0
  35. package/out/services/foldingRanges.d.ts +3 -0
  36. package/out/services/foldingRanges.js +73 -0
  37. package/out/services/formatting.d.ts +6 -0
  38. package/out/services/formatting.js +58 -0
  39. package/out/services/hover.d.ts +3 -0
  40. package/out/services/hover.js +64 -0
  41. package/out/services/implementation.d.ts +3 -0
  42. package/out/services/implementation.js +20 -0
  43. package/out/services/inlayHints.d.ts +3 -0
  44. package/out/services/inlayHints.js +54 -0
  45. package/out/services/prepareRename.d.ts +6 -0
  46. package/out/services/prepareRename.js +51 -0
  47. package/out/services/references.d.ts +3 -0
  48. package/out/services/references.js +20 -0
  49. package/out/services/rename.d.ts +5 -0
  50. package/out/services/rename.js +135 -0
  51. package/out/services/selectionRanges.d.ts +3 -0
  52. package/out/services/selectionRanges.js +53 -0
  53. package/out/services/semanticTokens.d.ts +3 -0
  54. package/out/services/semanticTokens.js +128 -0
  55. package/out/services/signatureHelp.d.ts +3 -0
  56. package/out/services/signatureHelp.js +87 -0
  57. package/out/services/tsconfig.d.ts +6 -0
  58. package/out/services/tsconfig.js +199 -0
  59. package/out/services/typeDefinition.d.ts +3 -0
  60. package/out/services/typeDefinition.js +20 -0
  61. package/out/services/workspaceSymbol.d.ts +3 -0
  62. package/out/services/workspaceSymbol.js +80 -0
  63. package/out/shared.d.ts +5 -0
  64. package/out/shared.js +33 -0
  65. package/out/types.d.ts +5 -0
  66. package/out/types.js +3 -0
  67. package/out/utils/errorCodes.d.ts +11 -0
  68. package/out/utils/errorCodes.js +19 -0
  69. package/out/utils/fixNames.d.ts +13 -0
  70. package/out/utils/fixNames.js +21 -0
  71. package/out/utils/modifiers.d.ts +1 -0
  72. package/out/utils/modifiers.js +12 -0
  73. package/out/utils/previewer.d.ts +13 -0
  74. package/out/utils/previewer.js +182 -0
  75. package/out/utils/snippetForFunctionCall.d.ts +8 -0
  76. package/out/utils/snippetForFunctionCall.js +112 -0
  77. package/out/utils/transforms.d.ts +10 -0
  78. package/out/utils/transforms.js +76 -0
  79. package/out/utils/typeConverters.d.ts +4 -0
  80. package/out/utils/typeConverters.js +67 -0
  81. package/package.json +32 -0
  82. package/rules.d.ts +13 -0
@@ -0,0 +1,5 @@
1
+ import { SharedContext } from '../types';
2
+ import type * as ts from 'typescript/lib/tsserverlibrary';
3
+ import * as vscode from 'vscode-languageserver-protocol';
4
+ import type { TextDocument } from 'vscode-languageserver-textdocument';
5
+ export declare function getFormatCodeSettings(ctx: SharedContext, document: TextDocument, options?: vscode.FormattingOptions): Promise<ts.FormatCodeSettings>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFormatCodeSettings = void 0;
4
+ const shared_1 = require("../shared");
5
+ async function getFormatCodeSettings(ctx, document, options) {
6
+ let config = await ctx.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.format');
7
+ config = config ?? {};
8
+ return {
9
+ convertTabsToSpaces: options?.insertSpaces,
10
+ tabSize: options?.tabSize,
11
+ indentSize: options?.tabSize,
12
+ indentStyle: 2 /** ts.IndentStyle.Smart */,
13
+ newLineCharacter: '\n',
14
+ insertSpaceAfterCommaDelimiter: config.insertSpaceAfterCommaDelimiter ?? true,
15
+ insertSpaceAfterConstructor: config.insertSpaceAfterConstructor ?? false,
16
+ insertSpaceAfterSemicolonInForStatements: config.insertSpaceAfterSemicolonInForStatements ?? true,
17
+ insertSpaceBeforeAndAfterBinaryOperators: config.insertSpaceBeforeAndAfterBinaryOperators ?? true,
18
+ insertSpaceAfterKeywordsInControlFlowStatements: config.insertSpaceAfterKeywordsInControlFlowStatements ?? true,
19
+ insertSpaceAfterFunctionKeywordForAnonymousFunctions: config.insertSpaceAfterFunctionKeywordForAnonymousFunctions ?? true,
20
+ insertSpaceBeforeFunctionParenthesis: config.insertSpaceBeforeFunctionParenthesis ?? false,
21
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: config.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis ?? false,
22
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: config.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets ?? false,
23
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: config.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces ?? true,
24
+ insertSpaceAfterOpeningAndBeforeClosingEmptyBraces: config.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces ?? true,
25
+ insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: config.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces ?? false,
26
+ insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: config.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces ?? false,
27
+ insertSpaceAfterTypeAssertion: config.insertSpaceAfterTypeAssertion ?? false,
28
+ placeOpenBraceOnNewLineForFunctions: config.placeOpenBraceOnNewLineForFunctions ?? false,
29
+ placeOpenBraceOnNewLineForControlBlocks: config.placeOpenBraceOnNewLineForControlBlocks ?? false,
30
+ semicolons: config.semicolons ?? 'ignore',
31
+ };
32
+ }
33
+ exports.getFormatCodeSettings = getFormatCodeSettings;
34
+ //# sourceMappingURL=getFormatCodeSettings.js.map
@@ -0,0 +1,4 @@
1
+ import type * as ts from 'typescript/lib/tsserverlibrary';
2
+ import { SharedContext } from '../types';
3
+ import type { TextDocument } from 'vscode-languageserver-textdocument';
4
+ export declare function getUserPreferences(ctx: SharedContext, document: TextDocument): Promise<ts.UserPreferences>;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUserPreferences = void 0;
4
+ const shared_1 = require("../shared");
5
+ const path_1 = require("path");
6
+ const vscode_uri_1 = require("vscode-uri");
7
+ async function getUserPreferences(ctx, document) {
8
+ const config = await ctx.env.getConfiguration?.((0, shared_1.getConfigTitle)(document)) ?? {};
9
+ const preferencesConfig = config?.preferences ?? {};
10
+ const preferences = {
11
+ ...config.unstable ?? {},
12
+ quotePreference: getQuoteStylePreference(preferencesConfig),
13
+ importModuleSpecifierPreference: getImportModuleSpecifierPreference(preferencesConfig),
14
+ importModuleSpecifierEnding: getImportModuleSpecifierEndingPreference(preferencesConfig),
15
+ jsxAttributeCompletionStyle: getJsxAttributeCompletionStyle(preferencesConfig),
16
+ allowTextChangesInNewFiles: document.uri.startsWith('file://'),
17
+ providePrefixAndSuffixTextForRename: (preferencesConfig.renameShorthandProperties ?? true) === false ? false : (preferencesConfig.useAliasesForRenames ?? true),
18
+ allowRenameOfImportPath: true,
19
+ includeAutomaticOptionalChainCompletions: config.suggest?.includeAutomaticOptionalChainCompletions ?? true,
20
+ provideRefactorNotApplicableReason: true,
21
+ generateReturnInDocTemplate: config.suggest?.jsdoc?.generateReturns ?? true,
22
+ includeCompletionsForImportStatements: config.suggest?.includeCompletionsForImportStatements ?? true,
23
+ includeCompletionsWithSnippetText: config.suggest?.includeCompletionsWithSnippetText ?? true,
24
+ includeCompletionsWithClassMemberSnippets: config.suggest?.classMemberSnippets?.enabled ?? true,
25
+ includeCompletionsWithObjectLiteralMethodSnippets: config.suggest?.objectLiteralMethodSnippets?.enabled ?? true,
26
+ autoImportFileExcludePatterns: getAutoImportFileExcludePatternsPreference(preferencesConfig, ctx.env.rootUri),
27
+ useLabelDetailsInCompletionEntries: true,
28
+ allowIncompleteCompletions: true,
29
+ displayPartsForJSDoc: true,
30
+ // inlay hints
31
+ includeInlayParameterNameHints: getInlayParameterNameHintsPreference(config),
32
+ includeInlayParameterNameHintsWhenArgumentMatchesName: !(config.inlayHints?.parameterNames?.suppressWhenArgumentMatchesName ?? true),
33
+ includeInlayFunctionParameterTypeHints: config.inlayHints?.parameterTypes?.enabled ?? false,
34
+ includeInlayVariableTypeHints: config.inlayHints?.variableTypes?.enabled ?? false,
35
+ includeInlayVariableTypeHintsWhenTypeMatchesName: !(config.inlayHints?.variableTypes?.suppressWhenTypeMatchesName ?? true),
36
+ includeInlayPropertyDeclarationTypeHints: config.inlayHints?.propertyDeclarationTypes?.enabled ?? false,
37
+ includeInlayFunctionLikeReturnTypeHints: config.inlayHints?.functionLikeReturnTypes?.enabled ?? false,
38
+ includeInlayEnumMemberValueHints: config.inlayHints?.enumMemberValues?.enabled ?? false,
39
+ // https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/completions.ts#L728-L730
40
+ includeCompletionsForModuleExports: config.suggest?.autoImports ?? true,
41
+ includeCompletionsWithInsertText: true,
42
+ includePackageJsonAutoImports: preferencesConfig.includePackageJsonAutoImports ?? 'auto',
43
+ };
44
+ return preferences;
45
+ }
46
+ exports.getUserPreferences = getUserPreferences;
47
+ function getQuoteStylePreference(config) {
48
+ switch (config.quoteStyle) {
49
+ case 'single': return 'single';
50
+ case 'double': return 'double';
51
+ default: return 'auto';
52
+ }
53
+ }
54
+ function getAutoImportFileExcludePatternsPreference(config, workspaceFolder) {
55
+ return workspaceFolder && config.autoImportFileExcludePatterns?.map(p => {
56
+ // Normalization rules: https://github.com/microsoft/TypeScript/pull/49578
57
+ const slashNormalized = p.replace(/\\/g, '/');
58
+ const isRelative = /^\.\.?($|\/)/.test(slashNormalized);
59
+ return path_1.posix.isAbsolute(p) ? p :
60
+ p.startsWith('*') ? '/' + slashNormalized :
61
+ isRelative ? vscode_uri_1.URI.parse(path_1.posix.join(workspaceFolder.toString(), p)).fsPath :
62
+ '/**/' + slashNormalized;
63
+ });
64
+ }
65
+ function getImportModuleSpecifierPreference(config) {
66
+ switch (config.importModuleSpecifier) {
67
+ case 'project-relative': return 'project-relative';
68
+ case 'relative': return 'relative';
69
+ case 'non-relative': return 'non-relative';
70
+ default: return undefined;
71
+ }
72
+ }
73
+ function getImportModuleSpecifierEndingPreference(config) {
74
+ switch (config.importModuleSpecifierEnding) {
75
+ case 'minimal': return 'minimal';
76
+ case 'index': return 'index';
77
+ case 'js': return 'js';
78
+ default: return 'minimal'; // fix https://github.com/johnsoncodehk/volar/issues/1667
79
+ // default: return 'auto';
80
+ }
81
+ }
82
+ function getJsxAttributeCompletionStyle(config) {
83
+ switch (config.jsxAttributeCompletionStyle) {
84
+ case 'braces': return 'braces';
85
+ case 'none': return 'none';
86
+ default: return 'auto';
87
+ }
88
+ }
89
+ function getInlayParameterNameHintsPreference(config) {
90
+ switch (config.inlayHints?.parameterNames?.enabled) {
91
+ case 'none': return 'none';
92
+ case 'literals': return 'literals';
93
+ case 'all': return 'all';
94
+ default: return undefined;
95
+ }
96
+ }
97
+ //# sourceMappingURL=getUserPreferences.js.map
package/out/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { Service } from '@volar/language-service';
2
+ declare const _default: () => Service;
3
+ export default _default;
package/out/index.js ADDED
@@ -0,0 +1,421 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const semver = __importStar(require("semver"));
27
+ const vscode = __importStar(require("vscode-languageserver-protocol"));
28
+ const shared_1 = require("./shared");
29
+ const _callHierarchy = __importStar(require("./services/callHierarchy"));
30
+ const codeActions = __importStar(require("./services/codeAction"));
31
+ const codeActionResolve = __importStar(require("./services/codeActionResolve"));
32
+ const completions = __importStar(require("./services/completions/basic"));
33
+ const directiveCommentCompletions = __importStar(require("./services/completions/directiveComment"));
34
+ const jsDocCompletions = __importStar(require("./services/completions/jsDoc"));
35
+ const completionResolve = __importStar(require("./services/completions/resolve"));
36
+ const definitions = __importStar(require("./services/definition"));
37
+ const diagnostics = __importStar(require("./services/diagnostics"));
38
+ const documentHighlight = __importStar(require("./services/documentHighlight"));
39
+ const documentSymbol = __importStar(require("./services/documentSymbol"));
40
+ const fileReferences = __importStar(require("./services/fileReferences"));
41
+ const fileRename = __importStar(require("./services/fileRename"));
42
+ const foldingRanges = __importStar(require("./services/foldingRanges"));
43
+ const formatting = __importStar(require("./services/formatting"));
44
+ const hover = __importStar(require("./services/hover"));
45
+ const implementation = __importStar(require("./services/implementation"));
46
+ const inlayHints = __importStar(require("./services/inlayHints"));
47
+ const prepareRename = __importStar(require("./services/prepareRename"));
48
+ const references = __importStar(require("./services/references"));
49
+ const rename = __importStar(require("./services/rename"));
50
+ const selectionRanges = __importStar(require("./services/selectionRanges"));
51
+ const semanticTokens = __importStar(require("./services/semanticTokens"));
52
+ const signatureHelp = __importStar(require("./services/signatureHelp"));
53
+ const typeDefinitions = __importStar(require("./services/typeDefinition"));
54
+ const workspaceSymbols = __importStar(require("./services/workspaceSymbol"));
55
+ const tsconfig = __importStar(require("./services/tsconfig"));
56
+ exports.default = () => (contextOrNull, modules) => {
57
+ const jsDocTriggerCharacter = '*';
58
+ const directiveCommentTriggerCharacter = '@';
59
+ const triggerCharacters = {
60
+ triggerCharacters: [
61
+ ...getBasicTriggerCharacters('4.3.0'),
62
+ jsDocTriggerCharacter,
63
+ directiveCommentTriggerCharacter,
64
+ ],
65
+ signatureHelpTriggerCharacters: ['(', ',', '<'],
66
+ signatureHelpRetriggerCharacters: [')'],
67
+ // https://github.com/microsoft/vscode/blob/ce119308e8fd4cd3f992d42b297588e7abe33a0c/extensions/typescript-language-features/src/languageFeatures/formatting.ts#L99
68
+ autoFormatTriggerCharacters: [';', '}', '\n'],
69
+ };
70
+ if (!contextOrNull) {
71
+ return triggerCharacters;
72
+ }
73
+ const context = contextOrNull;
74
+ if (!modules?.typescript) {
75
+ console.warn('[volar-service-typescript] context.typescript not found, @volar/typescript plugin disabled. Make sure you have provide tsdk in language client.');
76
+ return {};
77
+ }
78
+ const ts = modules.typescript;
79
+ const basicTriggerCharacters = getBasicTriggerCharacters(ts.version);
80
+ const semanticCtx = {
81
+ ...context,
82
+ typescript: context.typescript,
83
+ ts,
84
+ getTextDocument(uri) {
85
+ for (const [_, map] of context.documents.getMapsByVirtualFileUri(uri)) {
86
+ return map.virtualFileDocument;
87
+ }
88
+ return context.getTextDocument(uri);
89
+ },
90
+ };
91
+ const findDefinition = definitions.register(semanticCtx);
92
+ const findTypeDefinition = typeDefinitions.register(semanticCtx);
93
+ const findReferences = references.register(semanticCtx);
94
+ const findFileReferences = fileReferences.register(semanticCtx);
95
+ const findImplementations = implementation.register(semanticCtx);
96
+ const doPrepareRename = prepareRename.register(semanticCtx);
97
+ const doRename = rename.register(semanticCtx);
98
+ const getEditsForFileRename = fileRename.register(semanticCtx);
99
+ const getCodeActions = codeActions.register(semanticCtx);
100
+ const doCodeActionResolve = codeActionResolve.register(semanticCtx);
101
+ const getInlayHints = inlayHints.register(semanticCtx);
102
+ const findDocumentHighlights = documentHighlight.register(semanticCtx);
103
+ const findWorkspaceSymbols = workspaceSymbols.register(semanticCtx);
104
+ const doComplete = completions.register(semanticCtx);
105
+ const doCompletionResolve = completionResolve.register(semanticCtx);
106
+ const doDirectiveCommentComplete = directiveCommentCompletions.register(semanticCtx);
107
+ const doJsDocComplete = jsDocCompletions.register(semanticCtx);
108
+ const doHover = hover.register(semanticCtx);
109
+ const getSignatureHelp = signatureHelp.register(semanticCtx);
110
+ const getSelectionRanges = selectionRanges.register(semanticCtx);
111
+ const doValidation = diagnostics.register(semanticCtx);
112
+ const getDocumentSemanticTokens = semanticTokens.register(semanticCtx);
113
+ const callHierarchy = _callHierarchy.register(semanticCtx);
114
+ const tsconfigRequests = tsconfig.register(semanticCtx);
115
+ let syntacticHostCtx = {
116
+ fileName: '',
117
+ fileVersion: 0,
118
+ snapshot: ts.ScriptSnapshot.fromString(''),
119
+ };
120
+ const syntacticServiceHost = {
121
+ getProjectVersion: () => syntacticHostCtx.fileName + '::' + syntacticHostCtx.fileVersion,
122
+ getScriptFileNames: () => [syntacticHostCtx.fileName],
123
+ getScriptVersion: fileName => fileName === syntacticHostCtx.fileName ? syntacticHostCtx.fileVersion.toString() : '',
124
+ getScriptSnapshot: fileName => fileName === syntacticHostCtx.fileName ? syntacticHostCtx.snapshot : undefined,
125
+ getCompilationSettings: () => context.typescript?.languageServiceHost.getCompilationSettings() ?? {},
126
+ getCurrentDirectory: () => '',
127
+ getDefaultLibFileName: () => '',
128
+ readFile: () => undefined,
129
+ fileExists: fileName => fileName === syntacticHostCtx.fileName,
130
+ };
131
+ const syntacticCtx = {
132
+ ...semanticCtx,
133
+ typescript: {
134
+ ...semanticCtx.typescript,
135
+ languageServiceHost: syntacticServiceHost,
136
+ languageService: ts.createLanguageService(syntacticServiceHost),
137
+ },
138
+ };
139
+ const findDocumentSymbols = documentSymbol.register(syntacticCtx);
140
+ const doFormatting = formatting.register(syntacticCtx);
141
+ const getFoldingRanges = foldingRanges.register(syntacticCtx);
142
+ return {
143
+ ...triggerCharacters,
144
+ triggerCharacters: [
145
+ ...basicTriggerCharacters,
146
+ jsDocTriggerCharacter,
147
+ directiveCommentTriggerCharacter,
148
+ ],
149
+ resolveRuleContext(ruleCtx, type) {
150
+ if ((0, shared_1.isTsDocument)(ruleCtx.document)) {
151
+ let sourceFile;
152
+ if (type === 'format' || type === 'syntax') {
153
+ prepareSyntacticService(ruleCtx.document);
154
+ sourceFile = syntacticCtx.typescript.languageService.getProgram()?.getSourceFile(syntacticHostCtx.fileName);
155
+ }
156
+ else {
157
+ sourceFile = semanticCtx.typescript.languageService.getProgram()?.getSourceFile(context.env.uriToFileName(ruleCtx.document.uri));
158
+ }
159
+ if (sourceFile) {
160
+ ruleCtx.typescript = {
161
+ sourceFile,
162
+ getTextDocument: syntacticCtx.getTextDocument,
163
+ ...syntacticCtx.typescript,
164
+ };
165
+ }
166
+ else {
167
+ console.warn('[volar-service-typescript] sourceFile not found', ruleCtx.document.uri);
168
+ }
169
+ }
170
+ return ruleCtx;
171
+ },
172
+ provideAutoInsertionEdit(document, position, ctx) {
173
+ if ((document.languageId === 'javascriptreact' || document.languageId === 'typescriptreact')
174
+ && ctx.lastChange.text.endsWith('>')) {
175
+ const configName = document.languageId === 'javascriptreact' ? 'javascript.autoClosingTags' : 'typescript.autoClosingTags';
176
+ const config = context.env.getConfiguration?.(configName) ?? true;
177
+ if (config) {
178
+ prepareSyntacticService(document);
179
+ const close = syntacticCtx.typescript.languageService.getJsxClosingTagAtPosition(context.env.uriToFileName(document.uri), document.offsetAt(position));
180
+ if (close) {
181
+ return '$0' + close.newText;
182
+ }
183
+ }
184
+ }
185
+ },
186
+ async provideCompletionItems(document, position, context) {
187
+ if ((0, shared_1.isTsDocument)(document)) {
188
+ let result = {
189
+ isIncomplete: false,
190
+ items: [],
191
+ };
192
+ if (!context || context.triggerKind !== vscode.CompletionTriggerKind.TriggerCharacter || (context.triggerCharacter && basicTriggerCharacters.includes(context.triggerCharacter))) {
193
+ const completeOptions = {
194
+ triggerCharacter: context?.triggerCharacter,
195
+ triggerKind: context?.triggerKind,
196
+ };
197
+ const basicResult = await doComplete(document.uri, position, completeOptions);
198
+ if (basicResult) {
199
+ result = basicResult;
200
+ }
201
+ }
202
+ if (!context || context.triggerKind !== vscode.CompletionTriggerKind.TriggerCharacter || context.triggerCharacter === jsDocTriggerCharacter) {
203
+ const jsdocResult = await doJsDocComplete(document.uri, position);
204
+ if (jsdocResult) {
205
+ result.items.push(jsdocResult);
206
+ }
207
+ }
208
+ if (!context || context.triggerKind !== vscode.CompletionTriggerKind.TriggerCharacter || context.triggerCharacter === directiveCommentTriggerCharacter) {
209
+ const directiveCommentResult = await doDirectiveCommentComplete(document.uri, position);
210
+ if (directiveCommentResult) {
211
+ result.items = result.items.concat(directiveCommentResult);
212
+ }
213
+ }
214
+ return result;
215
+ }
216
+ },
217
+ resolveCompletionItem(item) {
218
+ return doCompletionResolve(item);
219
+ },
220
+ provideRenameRange(document, position) {
221
+ if ((0, shared_1.isTsDocument)(document)) {
222
+ return doPrepareRename(document.uri, position);
223
+ }
224
+ },
225
+ provideRenameEdits(document, position, newName) {
226
+ if ((0, shared_1.isTsDocument)(document) || (0, shared_1.isJsonDocument)(document)) {
227
+ return doRename(document.uri, position, newName);
228
+ }
229
+ },
230
+ provideCodeActions(document, range, context) {
231
+ if ((0, shared_1.isTsDocument)(document)) {
232
+ return getCodeActions(document.uri, range, context);
233
+ }
234
+ },
235
+ resolveCodeAction(codeAction) {
236
+ return doCodeActionResolve(codeAction);
237
+ },
238
+ provideInlayHints(document, range) {
239
+ if ((0, shared_1.isTsDocument)(document)) {
240
+ return getInlayHints(document.uri, range);
241
+ }
242
+ },
243
+ provideCallHierarchyItems(document, position) {
244
+ if ((0, shared_1.isTsDocument)(document)) {
245
+ return callHierarchy.doPrepare(document.uri, position);
246
+ }
247
+ },
248
+ provideCallHierarchyIncomingCalls(item) {
249
+ return callHierarchy.getIncomingCalls(item);
250
+ },
251
+ provideCallHierarchyOutgoingCalls(item) {
252
+ return callHierarchy.getOutgoingCalls(item);
253
+ },
254
+ provideDefinition(document, position) {
255
+ if ((0, shared_1.isTsDocument)(document)) {
256
+ return findDefinition(document.uri, position);
257
+ }
258
+ },
259
+ provideTypeDefinition(document, position) {
260
+ if ((0, shared_1.isTsDocument)(document)) {
261
+ return findTypeDefinition(document.uri, position);
262
+ }
263
+ },
264
+ provideDiagnostics(document) {
265
+ if ((0, shared_1.isTsDocument)(document)) {
266
+ return doValidation(document.uri, { syntactic: true, suggestion: true });
267
+ }
268
+ },
269
+ provideSemanticDiagnostics(document) {
270
+ if ((0, shared_1.isTsDocument)(document)) {
271
+ return doValidation(document.uri, { semantic: true, declaration: true });
272
+ }
273
+ },
274
+ provideHover(document, position) {
275
+ if ((0, shared_1.isTsDocument)(document)) {
276
+ return doHover(document.uri, position);
277
+ }
278
+ },
279
+ provideImplementation(document, position) {
280
+ if ((0, shared_1.isTsDocument)(document)) {
281
+ return findImplementations(document.uri, position);
282
+ }
283
+ },
284
+ provideReferences(document, position) {
285
+ if ((0, shared_1.isTsDocument)(document) || (0, shared_1.isJsonDocument)(document)) {
286
+ return findReferences(document.uri, position);
287
+ }
288
+ },
289
+ provideFileReferences(document) {
290
+ if ((0, shared_1.isTsDocument)(document) || (0, shared_1.isJsonDocument)(document)) {
291
+ return findFileReferences(document.uri);
292
+ }
293
+ },
294
+ provideDocumentHighlights(document, position) {
295
+ if ((0, shared_1.isTsDocument)(document)) {
296
+ return findDocumentHighlights(document.uri, position);
297
+ }
298
+ },
299
+ provideDocumentSymbols(document) {
300
+ if ((0, shared_1.isTsDocument)(document)) {
301
+ prepareSyntacticService(document);
302
+ return findDocumentSymbols(document.uri);
303
+ }
304
+ },
305
+ provideDocumentSemanticTokens(document, range, legend) {
306
+ if ((0, shared_1.isTsDocument)(document)) {
307
+ return getDocumentSemanticTokens(document.uri, range, legend);
308
+ }
309
+ },
310
+ provideWorkspaceSymbols(query) {
311
+ return findWorkspaceSymbols(query);
312
+ },
313
+ provideFileRenameEdits(oldUri, newUri) {
314
+ return getEditsForFileRename(oldUri, newUri);
315
+ },
316
+ provideFoldingRanges(document) {
317
+ if ((0, shared_1.isTsDocument)(document)) {
318
+ prepareSyntacticService(document);
319
+ return getFoldingRanges(document.uri);
320
+ }
321
+ },
322
+ provideSelectionRanges(document, positions) {
323
+ if ((0, shared_1.isTsDocument)(document)) {
324
+ return getSelectionRanges(document.uri, positions);
325
+ }
326
+ },
327
+ provideSignatureHelp(document, position, context) {
328
+ if ((0, shared_1.isTsDocument)(document)) {
329
+ return getSignatureHelp(document.uri, position, context);
330
+ }
331
+ },
332
+ async provideDocumentFormattingEdits(document, range, options_2) {
333
+ if ((0, shared_1.isTsDocument)(document)) {
334
+ const enable = await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.format.enable');
335
+ if (enable === false) {
336
+ return;
337
+ }
338
+ prepareSyntacticService(document);
339
+ return doFormatting.onRange(document.uri, range, options_2);
340
+ }
341
+ },
342
+ async provideOnTypeFormattingEdits(document, position, key, options_2) {
343
+ if ((0, shared_1.isTsDocument)(document)) {
344
+ const enable = await context.env.getConfiguration?.((0, shared_1.getConfigTitle)(document) + '.format.enable');
345
+ if (enable === false) {
346
+ return;
347
+ }
348
+ prepareSyntacticService(document);
349
+ return doFormatting.onType(document.uri, options_2, position, key);
350
+ }
351
+ },
352
+ provideFormattingIndentSensitiveLines(document) {
353
+ if ((0, shared_1.isTsDocument)(document)) {
354
+ prepareSyntacticService(document);
355
+ const sourceFile = syntacticCtx.typescript.languageService.getProgram()?.getSourceFile(context.env.uriToFileName(document.uri));
356
+ if (sourceFile) {
357
+ const lines = [];
358
+ sourceFile.forEachChild(function walk(node) {
359
+ if (node.kind === ts.SyntaxKind.FirstTemplateToken
360
+ || node.kind === ts.SyntaxKind.LastTemplateToken
361
+ || node.kind === ts.SyntaxKind.TemplateHead) {
362
+ const startLine = document.positionAt(node.getStart(sourceFile)).line;
363
+ const endLine = document.positionAt(node.getEnd()).line;
364
+ for (let i = startLine + 1; i <= endLine; i++) {
365
+ lines.push(i);
366
+ }
367
+ }
368
+ node.forEachChild(walk);
369
+ });
370
+ return lines;
371
+ }
372
+ }
373
+ },
374
+ /**
375
+ * for tsconfig: https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/tsconfig.ts
376
+ */
377
+ provideDocumentLinks(document, token) {
378
+ return tsconfigRequests.provideDocumentLinks(document, token);
379
+ },
380
+ resolveDocumentLink(link, token) {
381
+ return tsconfigRequests.resolve(link, token);
382
+ },
383
+ };
384
+ function prepareSyntacticService(document) {
385
+ syntacticHostCtx.fileName = context.env.uriToFileName(document.uri);
386
+ syntacticHostCtx.fileVersion = document.version;
387
+ if (context.documents.isVirtualFileUri(document.uri)) {
388
+ const snapshot = context.documents.getVirtualFileByUri(document.uri)[0]?.snapshot;
389
+ if (snapshot) {
390
+ syntacticHostCtx.snapshot = snapshot;
391
+ }
392
+ else {
393
+ throw new Error('No snapshot found for ' + document.uri);
394
+ }
395
+ }
396
+ else {
397
+ const snapshot = context.host.getScriptSnapshot(syntacticHostCtx.fileName);
398
+ if (snapshot) {
399
+ syntacticHostCtx.snapshot = snapshot;
400
+ }
401
+ else {
402
+ throw new Error('No snapshot found for ' + document.uri);
403
+ }
404
+ }
405
+ }
406
+ };
407
+ function getBasicTriggerCharacters(tsVersion) {
408
+ const triggerCharacters = ['.', '"', '\'', '`', '/', '<'];
409
+ // https://github.com/microsoft/vscode/blob/8e65ae28d5fb8b3c931135da1a41edb9c80ae46f/extensions/typescript-language-features/src/languageFeatures/completions.ts#L811-L833
410
+ if (semver.lt(tsVersion, '3.1.0') || semver.gte(tsVersion, '3.2.0')) {
411
+ triggerCharacters.push('@');
412
+ }
413
+ if (semver.gte(tsVersion, '3.8.1')) {
414
+ triggerCharacters.push('#');
415
+ }
416
+ if (semver.gte(tsVersion, '4.3.0')) {
417
+ triggerCharacters.push(' ');
418
+ }
419
+ return triggerCharacters;
420
+ }
421
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,72 @@
1
+ export declare class Kind {
2
+ static readonly alias = "alias";
3
+ static readonly callSignature = "call";
4
+ static readonly class = "class";
5
+ static readonly const = "const";
6
+ static readonly constructorImplementation = "constructor";
7
+ static readonly constructSignature = "construct";
8
+ static readonly directory = "directory";
9
+ static readonly enum = "enum";
10
+ static readonly enumMember = "enum member";
11
+ static readonly externalModuleName = "external module name";
12
+ static readonly function = "function";
13
+ static readonly indexSignature = "index";
14
+ static readonly interface = "interface";
15
+ static readonly keyword = "keyword";
16
+ static readonly let = "let";
17
+ static readonly localFunction = "local function";
18
+ static readonly localVariable = "local var";
19
+ static readonly method = "method";
20
+ static readonly memberGetAccessor = "getter";
21
+ static readonly memberSetAccessor = "setter";
22
+ static readonly memberVariable = "property";
23
+ static readonly module = "module";
24
+ static readonly primitiveType = "primitive type";
25
+ static readonly script = "script";
26
+ static readonly type = "type";
27
+ static readonly variable = "var";
28
+ static readonly warning = "warning";
29
+ static readonly string = "string";
30
+ static readonly parameter = "parameter";
31
+ static readonly typeParameter = "type parameter";
32
+ }
33
+ export declare class DiagnosticCategory {
34
+ static readonly error = "error";
35
+ static readonly warning = "warning";
36
+ static readonly suggestion = "suggestion";
37
+ }
38
+ export declare class KindModifiers {
39
+ static readonly optional = "optional";
40
+ static readonly deprecated = "deprecated";
41
+ static readonly color = "color";
42
+ static readonly dtsFile = ".d.ts";
43
+ static readonly tsFile = ".ts";
44
+ static readonly tsxFile = ".tsx";
45
+ static readonly jsFile = ".js";
46
+ static readonly jsxFile = ".jsx";
47
+ static readonly jsonFile = ".json";
48
+ static readonly fileExtensionKindModifiers: string[];
49
+ }
50
+ export declare class DisplayPartKind {
51
+ static readonly functionName = "functionName";
52
+ static readonly methodName = "methodName";
53
+ static readonly parameterName = "parameterName";
54
+ static readonly propertyName = "propertyName";
55
+ static readonly punctuation = "punctuation";
56
+ static readonly text = "text";
57
+ }
58
+ export declare enum EventName {
59
+ syntaxDiag = "syntaxDiag",
60
+ semanticDiag = "semanticDiag",
61
+ suggestionDiag = "suggestionDiag",
62
+ configFileDiag = "configFileDiag",
63
+ telemetry = "telemetry",
64
+ projectLanguageServiceState = "projectLanguageServiceState",
65
+ projectsUpdatedInBackground = "projectsUpdatedInBackground",
66
+ beginInstallTypes = "beginInstallTypes",
67
+ endInstallTypes = "endInstallTypes",
68
+ typesInstallerInitializationFailed = "typesInstallerInitializationFailed",
69
+ surveyReady = "surveyReady",
70
+ projectLoadingStart = "projectLoadingStart",
71
+ projectLoadingFinish = "projectLoadingFinish"
72
+ }