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
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.create = void 0;
4
+ const nls = require("vscode-nls");
5
+ const shared_1 = require("../shared");
6
+ const localize = nls.loadMessageBundle(); // TODO: not working
7
+ const directives = [
8
+ {
9
+ value: '@ts-check',
10
+ description: localize('ts-check', "Enables semantic checking in a JavaScript file. Must be at the top of a file.")
11
+ }, {
12
+ value: '@ts-nocheck',
13
+ description: localize('ts-nocheck', "Disables semantic checking in a JavaScript file. Must be at the top of a file.")
14
+ }, {
15
+ value: '@ts-ignore',
16
+ description: localize('ts-ignore', "Suppresses @ts-check errors on the next line of a file.")
17
+ }, {
18
+ value: '@ts-expect-error',
19
+ description: localize('ts-expect-error', "Suppresses @ts-check errors on the next line of a file, expecting at least one to exist.")
20
+ }
21
+ ];
22
+ function create() {
23
+ return {
24
+ name: 'typescript-directive-comment',
25
+ triggerCharacters: ['@'],
26
+ create() {
27
+ return {
28
+ provideCompletionItems(document, position) {
29
+ if (!(0, shared_1.isTsDocument)(document))
30
+ return;
31
+ const prefix = document.getText({
32
+ start: { line: position.line, character: 0 },
33
+ end: position,
34
+ });
35
+ const match = prefix.match(/^\s*\/\/+\s?(@[a-zA-Z\-]*)?$/);
36
+ if (match) {
37
+ const items = directives.map(directive => {
38
+ const item = { label: directive.value };
39
+ item.insertTextFormat = 2;
40
+ item.detail = directive.description;
41
+ const range = {
42
+ start: {
43
+ line: position.line,
44
+ character: Math.max(0, position.character - (match[1] ? match[1].length : 0)),
45
+ },
46
+ end: position,
47
+ };
48
+ item.textEdit = {
49
+ range,
50
+ newText: directive.value,
51
+ };
52
+ return item;
53
+ });
54
+ return {
55
+ isIncomplete: false,
56
+ items,
57
+ };
58
+ }
59
+ },
60
+ };
61
+ },
62
+ };
63
+ }
64
+ exports.create = create;
65
+ //# sourceMappingURL=directiveComment.js.map
@@ -0,0 +1,3 @@
1
+ import type * as vscode from '@volar/language-service';
2
+ export declare function create(ts: typeof import('typescript')): vscode.ServicePlugin;
3
+ //# sourceMappingURL=docCommentTemplate.d.ts.map
@@ -1,44 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.register = void 0;
3
+ exports.create = void 0;
4
4
  const nls = require("vscode-nls");
5
- const resolve_1 = require("./resolve");
5
+ const shared_1 = require("../shared");
6
+ const syntacticLanguageService_1 = require("../syntacticLanguageService");
7
+ const lspConverters_1 = require("../utils/lspConverters");
6
8
  const localize = nls.loadMessageBundle(); // TODO: not working
7
9
  const defaultJsDoc = `/**\n * $0\n */`;
8
- function register(ctx) {
9
- return (uri, position) => {
10
- const document = ctx.getTextDocument(uri);
11
- if (!document)
12
- return;
13
- if (!isPotentiallyValidDocCompletionPosition(document, position))
14
- return;
15
- const fileName = ctx.uriToFileName(document.uri);
16
- const offset = document.offsetAt(position);
17
- const docCommentTemplate = ctx.languageService.getDocCommentTemplateAtPosition(fileName, offset);
18
- if (!docCommentTemplate)
19
- return;
20
- let insertText;
21
- // Workaround for #43619
22
- // docCommentTemplate previously returned undefined for empty jsdoc templates.
23
- // TS 2.7 now returns a single line doc comment, which breaks indentation.
24
- if (docCommentTemplate.newText === '/** */') {
25
- insertText = defaultJsDoc;
26
- }
27
- else {
28
- insertText = templateToSnippet(docCommentTemplate.newText);
29
- }
30
- const item = createCompletionItem(document, position, insertText);
31
- return item;
10
+ function create(ts) {
11
+ return {
12
+ name: 'typescript-doc-comment-template',
13
+ triggerCharacters: ['*'],
14
+ create() {
15
+ return {
16
+ provideCompletionItems(document, position) {
17
+ if (!(0, shared_1.isTsDocument)(document))
18
+ return;
19
+ if (!isPotentiallyValidDocCompletionPosition(document, position))
20
+ return;
21
+ const { languageService, fileName } = (0, syntacticLanguageService_1.getLanguageService)(ts, document);
22
+ const offset = document.offsetAt(position);
23
+ const docCommentTemplate = languageService.getDocCommentTemplateAtPosition(fileName, offset);
24
+ if (!docCommentTemplate)
25
+ return;
26
+ let insertText;
27
+ // Workaround for #43619
28
+ // docCommentTemplate previously returned undefined for empty jsdoc templates.
29
+ // TS 2.7 now returns a single line doc comment, which breaks indentation.
30
+ if (docCommentTemplate.newText === '/** */') {
31
+ insertText = defaultJsDoc;
32
+ }
33
+ else {
34
+ insertText = templateToSnippet(docCommentTemplate.newText);
35
+ }
36
+ const item = createCompletionItem(document, position, insertText);
37
+ return {
38
+ isIncomplete: false,
39
+ items: [item],
40
+ };
41
+ },
42
+ };
43
+ },
32
44
  };
33
45
  }
34
- exports.register = register;
46
+ exports.create = create;
35
47
  function createCompletionItem(document, position, insertText) {
36
48
  const item = { label: '/** */' };
37
49
  item.kind = 1;
38
50
  item.detail = localize('typescript.jsDocCompletionItem.documentation', 'JSDoc comment');
39
51
  item.sortText = '\0';
40
52
  item.insertTextFormat = 2;
41
- const line = (0, resolve_1.getLineText)(document, position.line);
53
+ const line = (0, lspConverters_1.getLineText)(document, position.line);
42
54
  const prefix = line.slice(0, position.character).match(/\/\**\s*$/);
43
55
  const suffix = line.slice(position.character).match(/^\s*\**\//);
44
56
  const start = { line: position.line, character: position.character + (prefix ? -prefix[0].length : 0) };
@@ -50,7 +62,7 @@ function createCompletionItem(document, position, insertText) {
50
62
  function isPotentiallyValidDocCompletionPosition(document, position) {
51
63
  // Only show the JSdoc completion when the everything before the cursor is whitespace
52
64
  // or could be the opening of a comment
53
- const line = (0, resolve_1.getLineText)(document, position.line);
65
+ const line = (0, lspConverters_1.getLineText)(document, position.line);
54
66
  const prefix = line.slice(0, position.character);
55
67
  if (!/^\s*$|\/\*\*\s*$|^\s*\/\*\*+\s*$/.test(prefix)) {
56
68
  return false;
@@ -79,4 +91,4 @@ function templateToSnippet(template) {
79
91
  template = template.replace(/\* @returns[ \t]*$/gm, `* @returns \${${snippetIndex++}}`);
80
92
  return template;
81
93
  }
82
- //# sourceMappingURL=jsDoc.js.map
94
+ //# sourceMappingURL=docCommentTemplate.js.map
@@ -0,0 +1,23 @@
1
+ import type { Result, ServiceContext, ServicePlugin } from '@volar/language-service';
2
+ import type * as ts from 'typescript';
3
+ import type { TextDocument } from 'vscode-languageserver-textdocument';
4
+ export interface Provide {
5
+ 'typescript/languageService': () => ts.LanguageService;
6
+ 'typescript/languageServiceHost': () => ts.LanguageServiceHost;
7
+ }
8
+ export interface CompletionItemData {
9
+ uri: string;
10
+ fileName: string;
11
+ offset: number;
12
+ originalItem: {
13
+ name: ts.CompletionEntry['name'];
14
+ source: ts.CompletionEntry['source'];
15
+ data: ts.CompletionEntry['data'];
16
+ labelDetails: ts.CompletionEntry['labelDetails'];
17
+ };
18
+ }
19
+ export declare function create(ts: typeof import('typescript'), { isValidationEnabled, isSuggestionsEnabled, }?: {
20
+ isValidationEnabled?(document: TextDocument, context: ServiceContext): Result<boolean>;
21
+ isSuggestionsEnabled?(document: TextDocument, context: ServiceContext): Result<boolean>;
22
+ }): ServicePlugin;
23
+ //# sourceMappingURL=semantic.d.ts.map