@astrojs/language-server 0.23.2 → 0.24.1

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 (84) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/browser.js +8 -1
  3. package/dist/check.d.ts +2 -1
  4. package/dist/check.js +8 -2
  5. package/dist/core/DiagnosticsManager.d.ts +2 -2
  6. package/dist/core/config/ConfigManager.d.ts +5 -6
  7. package/dist/core/config/ConfigManager.js +2 -9
  8. package/dist/core/documents/AstroDocument.d.ts +1 -1
  9. package/dist/core/documents/AstroDocument.js +1 -1
  10. package/dist/core/documents/DocumentBase.d.ts +2 -2
  11. package/dist/core/documents/DocumentManager.d.ts +1 -1
  12. package/dist/core/documents/DocumentManager.js +1 -1
  13. package/dist/core/documents/DocumentMapper.d.ts +2 -2
  14. package/dist/core/documents/parseHtml.d.ts +3 -2
  15. package/dist/core/documents/parseHtml.js +12 -5
  16. package/dist/core/documents/utils.d.ts +3 -3
  17. package/dist/core/documents/utils.js +1 -2
  18. package/dist/node.js +15 -1
  19. package/dist/plugins/PluginHost.d.ts +2 -2
  20. package/dist/plugins/PluginHost.js +1 -1
  21. package/dist/plugins/astro/AstroPlugin.d.ts +6 -5
  22. package/dist/plugins/astro/AstroPlugin.js +1 -0
  23. package/dist/plugins/astro/features/CompletionsProvider.d.ts +4 -3
  24. package/dist/plugins/astro/features/CompletionsProvider.js +12 -15
  25. package/dist/plugins/css/CSSDocument.d.ts +2 -2
  26. package/dist/plugins/css/CSSDocument.js +1 -1
  27. package/dist/plugins/css/CSSPlugin.d.ts +1 -1
  28. package/dist/plugins/css/CSSPlugin.js +3 -3
  29. package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
  30. package/dist/plugins/css/StyleAttributeDocument.js +1 -1
  31. package/dist/plugins/css/features/astro-selectors.d.ts +1 -1
  32. package/dist/plugins/css/features/getIdClassCompletions.d.ts +2 -2
  33. package/dist/plugins/html/HTMLPlugin.d.ts +3 -3
  34. package/dist/plugins/html/HTMLPlugin.js +1 -1
  35. package/dist/plugins/html/utils.d.ts +1 -1
  36. package/dist/plugins/index.d.ts +4 -4
  37. package/dist/plugins/index.js +4 -4
  38. package/dist/plugins/interfaces.d.ts +2 -2
  39. package/dist/plugins/typescript/LanguageServiceManager.d.ts +8 -9
  40. package/dist/plugins/typescript/LanguageServiceManager.js +5 -3
  41. package/dist/plugins/typescript/TypeScriptPlugin.d.ts +7 -6
  42. package/dist/plugins/typescript/TypeScriptPlugin.js +15 -15
  43. package/dist/plugins/typescript/astro-sys.d.ts +2 -3
  44. package/dist/plugins/typescript/astro-sys.js +7 -11
  45. package/dist/plugins/typescript/astro2tsx.js +3 -4
  46. package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +5 -4
  47. package/dist/plugins/typescript/features/CodeActionsProvider.js +6 -9
  48. package/dist/plugins/typescript/features/CompletionsProvider.d.ts +9 -7
  49. package/dist/plugins/typescript/features/CompletionsProvider.js +56 -80
  50. package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +4 -4
  51. package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +6 -4
  52. package/dist/plugins/typescript/features/DiagnosticsProvider.js +29 -19
  53. package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +3 -2
  54. package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +3 -4
  55. package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +7 -4
  56. package/dist/plugins/typescript/features/FoldingRangesProvider.js +12 -15
  57. package/dist/plugins/typescript/features/HoverProvider.d.ts +5 -4
  58. package/dist/plugins/typescript/features/HoverProvider.js +3 -6
  59. package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +5 -4
  60. package/dist/plugins/typescript/features/InlayHintsProvider.js +5 -8
  61. package/dist/plugins/typescript/features/SemanticTokenProvider.d.ts +3 -2
  62. package/dist/plugins/typescript/features/SemanticTokenProvider.js +4 -7
  63. package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +5 -4
  64. package/dist/plugins/typescript/features/SignatureHelpProvider.js +7 -10
  65. package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +3 -3
  66. package/dist/plugins/typescript/features/utils.d.ts +3 -3
  67. package/dist/plugins/typescript/language-service.d.ts +7 -6
  68. package/dist/plugins/typescript/language-service.js +29 -30
  69. package/dist/plugins/typescript/module-loader.d.ts +2 -2
  70. package/dist/plugins/typescript/module-loader.js +12 -16
  71. package/dist/plugins/typescript/previewer.d.ts +3 -7
  72. package/dist/plugins/typescript/previewer.js +13 -17
  73. package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +4 -5
  74. package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +2 -7
  75. package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +5 -2
  76. package/dist/plugins/typescript/snapshots/SnapshotManager.js +15 -17
  77. package/dist/plugins/typescript/snapshots/utils.d.ts +7 -7
  78. package/dist/plugins/typescript/snapshots/utils.js +28 -29
  79. package/dist/plugins/typescript/utils.d.ts +8 -10
  80. package/dist/plugins/typescript/utils.js +90 -107
  81. package/dist/server.d.ts +5 -1
  82. package/dist/server.js +27 -17
  83. package/dist/utils.d.ts +1 -1
  84. package/package.json +5 -4
@@ -22,24 +22,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.SnapshotManager = exports.GlobalSnapshotManager = void 0;
30
- const typescript_1 = __importDefault(require("typescript"));
31
- const DocumentSnapshot_1 = require("./DocumentSnapshot");
32
- const utils_1 = require("../../../utils");
33
27
  const events_1 = require("events");
34
- const DocumentSnapshotUtils = __importStar(require("./utils"));
28
+ const utils_1 = require("../../../utils");
35
29
  const utils_2 = require("../utils");
30
+ const DocumentSnapshot_1 = require("./DocumentSnapshot");
31
+ const DocumentSnapshotUtils = __importStar(require("./utils"));
36
32
  /**
37
33
  * Every snapshot corresponds to a unique file on disk.
38
34
  * A snapshot can be part of multiple projects, but for a given file path
39
35
  * there can be only one snapshot.
40
36
  */
41
37
  class GlobalSnapshotManager {
42
- constructor() {
38
+ constructor(ts) {
39
+ this.ts = ts;
43
40
  this.emitter = new events_1.EventEmitter();
44
41
  this.documents = new Map();
45
42
  }
@@ -74,7 +71,7 @@ class GlobalSnapshotManager {
74
71
  return previousSnapshot;
75
72
  }
76
73
  else {
77
- const newSnapshot = DocumentSnapshotUtils.createFromNonAstroFilePath(fileName);
74
+ const newSnapshot = DocumentSnapshotUtils.createFromNonAstroFilePath(fileName, this.ts);
78
75
  if (previousSnapshot) {
79
76
  newSnapshot.version = previousSnapshot.version + 1;
80
77
  }
@@ -96,20 +93,21 @@ exports.GlobalSnapshotManager = GlobalSnapshotManager;
96
93
  * Should only be used by `language-service.ts`
97
94
  */
98
95
  class SnapshotManager {
99
- constructor(globalSnapshotsManager, projectFiles, fileSpec, workspaceRoot) {
96
+ constructor(globalSnapshotsManager, projectFiles, fileSpec, workspaceRoot, ts) {
100
97
  this.globalSnapshotsManager = globalSnapshotsManager;
101
98
  this.projectFiles = projectFiles;
102
99
  this.fileSpec = fileSpec;
103
100
  this.workspaceRoot = workspaceRoot;
101
+ this.ts = ts;
104
102
  this.documents = new Map();
105
103
  this.lastLogged = new Date(new Date().getTime() - 60001);
106
104
  this.watchExtensions = [
107
- typescript_1.default.Extension.Dts,
108
- typescript_1.default.Extension.Js,
109
- typescript_1.default.Extension.Jsx,
110
- typescript_1.default.Extension.Ts,
111
- typescript_1.default.Extension.Tsx,
112
- typescript_1.default.Extension.Json,
105
+ this.ts.Extension.Dts,
106
+ this.ts.Extension.Js,
107
+ this.ts.Extension.Jsx,
108
+ this.ts.Extension.Ts,
109
+ this.ts.Extension.Tsx,
110
+ this.ts.Extension.Json,
113
111
  ];
114
112
  this.globalSnapshotsManager.onChange((fileName, document) => {
115
113
  // Only delete/update snapshots, don't add new ones,
@@ -132,7 +130,7 @@ class SnapshotManager {
132
130
  if (include?.length === 0) {
133
131
  return;
134
132
  }
135
- const projectFiles = typescript_1.default.sys
133
+ const projectFiles = this.ts.sys
136
134
  .readDirectory(this.workspaceRoot, this.watchExtensions, exclude, include)
137
135
  .map(utils_1.normalizePath);
138
136
  this.projectFiles = Array.from(new Set([...this.projectFiles, ...projectFiles]));
@@ -1,29 +1,29 @@
1
- import { AstroDocument } from '../../../core/documents';
1
+ import type { AstroDocument } from '../../../core/documents';
2
2
  import { FrameworkExt } from '../utils';
3
3
  import { AstroSnapshot, TypeScriptDocumentSnapshot } from './DocumentSnapshot';
4
- export declare function createFromDocument(document: AstroDocument): AstroSnapshot;
4
+ export declare function createFromDocument(document: AstroDocument, ts: typeof import('typescript/lib/tsserverlibrary')): AstroSnapshot;
5
5
  /**
6
6
  * Returns an Astro or Framework or a ts/js snapshot from a file path, depending on the file contents.
7
7
  * @param filePath path to the file
8
8
  * @param createDocument function that is used to create a document in case it's an Astro file
9
9
  */
10
- export declare function createFromFilePath(filePath: string, createDocument: (filePath: string, text: string) => AstroDocument): AstroSnapshot | TypeScriptDocumentSnapshot;
10
+ export declare function createFromFilePath(filePath: string, createDocument: (filePath: string, text: string) => AstroDocument, ts: typeof import('typescript/lib/tsserverlibrary')): AstroSnapshot | TypeScriptDocumentSnapshot;
11
11
  /**
12
12
  * Return a Framework or a TS snapshot from a file path, depending on the file contents
13
13
  * Unlike createFromFilePath, this does not support creating an Astro snapshot
14
14
  */
15
- export declare function createFromNonAstroFilePath(filePath: string): TypeScriptDocumentSnapshot;
15
+ export declare function createFromNonAstroFilePath(filePath: string, ts: typeof import('typescript/lib/tsserverlibrary')): TypeScriptDocumentSnapshot;
16
16
  /**
17
17
  * Returns a ts/js snapshot from a file path.
18
18
  * @param filePath path to the js/ts file
19
19
  * @param options options that apply in case it's a svelte file
20
20
  */
21
- export declare function createFromTSFilePath(filePath: string): TypeScriptDocumentSnapshot;
21
+ export declare function createFromTSFilePath(filePath: string, ts: typeof import('typescript/lib/tsserverlibrary')): TypeScriptDocumentSnapshot;
22
22
  /**
23
23
  * Returns an Astro snapshot from a file path.
24
24
  * @param filePath path to the Astro file
25
25
  * @param createDocument function that is used to create a document
26
26
  */
27
- export declare function createFromAstroFilePath(filePath: string, createDocument: (filePath: string, text: string) => AstroDocument): AstroSnapshot;
28
- export declare function createFromFrameworkFilePath(filePath: string, framework: FrameworkExt): TypeScriptDocumentSnapshot;
27
+ export declare function createFromAstroFilePath(filePath: string, createDocument: (filePath: string, text: string) => AstroDocument, ts: typeof import('typescript/lib/tsserverlibrary')): AstroSnapshot;
28
+ export declare function createFromFrameworkFilePath(filePath: string, framework: FrameworkExt, ts: typeof import('typescript/lib/tsserverlibrary')): TypeScriptDocumentSnapshot;
29
29
  export declare function classNameFromFilename(filename: string): string;
@@ -4,17 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.classNameFromFilename = exports.createFromFrameworkFilePath = exports.createFromAstroFilePath = exports.createFromTSFilePath = exports.createFromNonAstroFilePath = exports.createFromFilePath = exports.createFromDocument = void 0;
7
- const typescript_1 = __importDefault(require("typescript"));
8
- const astro2tsx_1 = __importDefault(require("../astro2tsx"));
9
7
  const vscode_uri_1 = require("vscode-uri");
10
- const utils_1 = require("../utils");
11
- const DocumentSnapshot_1 = require("./DocumentSnapshot");
12
- const utils_2 = require("../../../utils");
13
8
  const importPackage_1 = require("../../../importPackage");
9
+ const utils_1 = require("../../../utils");
10
+ const astro2tsx_1 = __importDefault(require("../astro2tsx"));
11
+ const utils_2 = require("../utils");
12
+ const DocumentSnapshot_1 = require("./DocumentSnapshot");
14
13
  // Utilities to create Snapshots from different contexts
15
- function createFromDocument(document) {
14
+ function createFromDocument(document, ts) {
16
15
  const { code } = (0, astro2tsx_1.default)(document.getText(), classNameFromFilename(document.getURL()));
17
- return new DocumentSnapshot_1.AstroSnapshot(document, code, typescript_1.default.ScriptKind.TSX);
16
+ return new DocumentSnapshot_1.AstroSnapshot(document, code, ts.ScriptKind.TSX);
18
17
  }
19
18
  exports.createFromDocument = createFromDocument;
20
19
  /**
@@ -22,16 +21,16 @@ exports.createFromDocument = createFromDocument;
22
21
  * @param filePath path to the file
23
22
  * @param createDocument function that is used to create a document in case it's an Astro file
24
23
  */
25
- function createFromFilePath(filePath, createDocument) {
26
- if ((0, utils_1.isAstroFilePath)(filePath)) {
27
- return createFromAstroFilePath(filePath, createDocument);
24
+ function createFromFilePath(filePath, createDocument, ts) {
25
+ if ((0, utils_2.isAstroFilePath)(filePath)) {
26
+ return createFromAstroFilePath(filePath, createDocument, ts);
28
27
  }
29
- else if ((0, utils_1.isFrameworkFilePath)(filePath)) {
30
- const framework = (0, utils_1.getFrameworkFromFilePath)(filePath);
31
- return createFromFrameworkFilePath(filePath, framework);
28
+ else if ((0, utils_2.isFrameworkFilePath)(filePath)) {
29
+ const framework = (0, utils_2.getFrameworkFromFilePath)(filePath);
30
+ return createFromFrameworkFilePath(filePath, framework, ts);
32
31
  }
33
32
  else {
34
- return createFromTSFilePath(filePath);
33
+ return createFromTSFilePath(filePath, ts);
35
34
  }
36
35
  }
37
36
  exports.createFromFilePath = createFromFilePath;
@@ -39,13 +38,13 @@ exports.createFromFilePath = createFromFilePath;
39
38
  * Return a Framework or a TS snapshot from a file path, depending on the file contents
40
39
  * Unlike createFromFilePath, this does not support creating an Astro snapshot
41
40
  */
42
- function createFromNonAstroFilePath(filePath) {
43
- if ((0, utils_1.isFrameworkFilePath)(filePath)) {
44
- const framework = (0, utils_1.getFrameworkFromFilePath)(filePath);
45
- return createFromFrameworkFilePath(filePath, framework);
41
+ function createFromNonAstroFilePath(filePath, ts) {
42
+ if ((0, utils_2.isFrameworkFilePath)(filePath)) {
43
+ const framework = (0, utils_2.getFrameworkFromFilePath)(filePath);
44
+ return createFromFrameworkFilePath(filePath, framework, ts);
46
45
  }
47
46
  else {
48
- return createFromTSFilePath(filePath);
47
+ return createFromTSFilePath(filePath, ts);
49
48
  }
50
49
  }
51
50
  exports.createFromNonAstroFilePath = createFromNonAstroFilePath;
@@ -54,9 +53,9 @@ exports.createFromNonAstroFilePath = createFromNonAstroFilePath;
54
53
  * @param filePath path to the js/ts file
55
54
  * @param options options that apply in case it's a svelte file
56
55
  */
57
- function createFromTSFilePath(filePath) {
58
- const originalText = typescript_1.default.sys.readFile(filePath) ?? '';
59
- return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, originalText);
56
+ function createFromTSFilePath(filePath, ts) {
57
+ const originalText = ts.sys.readFile(filePath) ?? '';
58
+ return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, originalText, (0, utils_2.getScriptKindFromFileName)(filePath, ts));
60
59
  }
61
60
  exports.createFromTSFilePath = createFromTSFilePath;
62
61
  /**
@@ -64,14 +63,14 @@ exports.createFromTSFilePath = createFromTSFilePath;
64
63
  * @param filePath path to the Astro file
65
64
  * @param createDocument function that is used to create a document
66
65
  */
67
- function createFromAstroFilePath(filePath, createDocument) {
68
- const originalText = typescript_1.default.sys.readFile(filePath) ?? '';
69
- return createFromDocument(createDocument(filePath, originalText));
66
+ function createFromAstroFilePath(filePath, createDocument, ts) {
67
+ const originalText = ts.sys.readFile(filePath) ?? '';
68
+ return createFromDocument(createDocument(filePath, originalText), ts);
70
69
  }
71
70
  exports.createFromAstroFilePath = createFromAstroFilePath;
72
- function createFromFrameworkFilePath(filePath, framework) {
71
+ function createFromFrameworkFilePath(filePath, framework, ts) {
73
72
  const className = classNameFromFilename(filePath);
74
- const originalText = typescript_1.default.sys.readFile(filePath) ?? '';
73
+ const originalText = ts.sys.readFile(filePath) ?? '';
75
74
  let code = '';
76
75
  if (framework === 'svelte') {
77
76
  const svelteIntegration = (0, importPackage_1.importSvelteIntegration)(filePath);
@@ -85,7 +84,7 @@ function createFromFrameworkFilePath(filePath, framework) {
85
84
  code = vueIntegration.toTSX(originalText, className);
86
85
  }
87
86
  }
88
- return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, code, typescript_1.default.ScriptKind.TSX);
87
+ return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, code, ts.ScriptKind.TSX);
89
88
  }
90
89
  exports.createFromFrameworkFilePath = createFromFrameworkFilePath;
91
90
  function classNameFromFilename(filename) {
@@ -102,7 +101,7 @@ function classNameFromFilename(filename) {
102
101
  // for tag names. For a better import autocompletion experience, we therefore throw them out.
103
102
  .findIndex((char) => /[A-Za-z]/.test(char));
104
103
  const withoutLeadingInvalidCharacters = withoutInvalidCharacters.substr(firstValidCharIdx);
105
- const inPascalCase = (0, utils_2.toPascalCase)(withoutLeadingInvalidCharacters);
104
+ const inPascalCase = (0, utils_1.toPascalCase)(withoutLeadingInvalidCharacters);
106
105
  const finalName = firstValidCharIdx === -1 ? `A${inPascalCase}` : inPascalCase;
107
106
  return finalName;
108
107
  }
@@ -1,8 +1,7 @@
1
- import ts from 'typescript';
2
- import { CompletionItemKind, DiagnosticSeverity, Position, Range, SymbolKind, SemanticTokensLegend } from 'vscode-languageserver';
1
+ import type { Node } from 'vscode-html-languageservice';
2
+ import { CompletionItemKind, Position, Range, SemanticTokensLegend, SymbolKind } from 'vscode-languageserver';
3
3
  import { AstroDocument, TagInformation } from '../../core/documents';
4
- import { AstroSnapshot, ScriptTagDocumentSnapshot, SnapshotFragment } from './snapshots/DocumentSnapshot';
5
- import { Node } from 'vscode-html-languageservice';
4
+ import type { AstroSnapshot, ScriptTagDocumentSnapshot, SnapshotFragment } from './snapshots/DocumentSnapshot';
6
5
  export declare const enum TokenType {
7
6
  class = 0,
8
7
  enum = 1,
@@ -27,13 +26,12 @@ export declare const enum TokenModifier {
27
26
  }
28
27
  export declare function getSemanticTokenLegend(): SemanticTokensLegend;
29
28
  export declare function symbolKindFromString(kind: string): SymbolKind;
30
- export declare function scriptElementKindToCompletionItemKind(kind: ts.ScriptElementKind): CompletionItemKind;
31
- export declare function getCommitCharactersForScriptElement(kind: ts.ScriptElementKind): string[] | undefined;
32
- export declare function getExtensionFromScriptKind(kind: ts.ScriptKind | undefined): ts.Extension;
33
- export declare function findTsConfigPath(fileName: string, rootUris: string[]): string;
29
+ export declare function scriptElementKindToCompletionItemKind(kind: ts.ScriptElementKind, ts: typeof import('typescript/lib/tsserverlibrary')): CompletionItemKind;
30
+ export declare function getCommitCharactersForScriptElement(kind: ts.ScriptElementKind, ts: typeof import('typescript/lib/tsserverlibrary')): string[] | undefined;
31
+ export declare function getExtensionFromScriptKind(kind: ts.ScriptKind | undefined, ts: typeof import('typescript/lib/tsserverlibrary')): ts.Extension;
32
+ export declare function findTsConfigPath(fileName: string, rootUris: string[], ts: typeof import('typescript/lib/tsserverlibrary')): string;
34
33
  export declare function isSubPath(uri: string, possibleSubPath: string): boolean;
35
- export declare function getScriptKindFromFileName(fileName: string): ts.ScriptKind;
36
- export declare function mapSeverity(category: ts.DiagnosticCategory): DiagnosticSeverity;
34
+ export declare function getScriptKindFromFileName(fileName: string, ts: typeof import('typescript/lib/tsserverlibrary')): ts.ScriptKind;
37
35
  export declare function convertRange(document: {
38
36
  positionAt: (offset: number) => Position;
39
37
  }, range: {
@@ -1,38 +1,34 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getScriptTagSnapshot = exports.getScriptTagLanguage = exports.ensureRealFilePath = exports.ensureRealAstroFilePath = exports.toRealAstroFilePath = exports.toVirtualFilePath = exports.toVirtualAstroFilePath = exports.isVirtualFilePath = exports.isVirtualSvelteFilePath = exports.isVirtualVueFilePath = exports.isVirtualAstroFilePath = exports.isFrameworkFilePath = exports.isAstroFilePath = exports.isVirtualFrameworkFilePath = exports.getFrameworkFromFilePath = exports.removeAstroComponentSuffix = exports.checkEndOfFileCodeInsert = exports.ensureFrontmatterInsert = exports.convertToLocationRange = exports.convertRange = exports.mapSeverity = exports.getScriptKindFromFileName = exports.isSubPath = exports.findTsConfigPath = exports.getExtensionFromScriptKind = exports.getCommitCharactersForScriptElement = exports.scriptElementKindToCompletionItemKind = exports.symbolKindFromString = exports.getSemanticTokenLegend = void 0;
7
- const typescript_1 = __importDefault(require("typescript"));
3
+ exports.getScriptTagSnapshot = exports.getScriptTagLanguage = exports.ensureRealFilePath = exports.ensureRealAstroFilePath = exports.toRealAstroFilePath = exports.toVirtualFilePath = exports.toVirtualAstroFilePath = exports.isVirtualFilePath = exports.isVirtualSvelteFilePath = exports.isVirtualVueFilePath = exports.isVirtualAstroFilePath = exports.isFrameworkFilePath = exports.isAstroFilePath = exports.isVirtualFrameworkFilePath = exports.getFrameworkFromFilePath = exports.removeAstroComponentSuffix = exports.checkEndOfFileCodeInsert = exports.ensureFrontmatterInsert = exports.convertToLocationRange = exports.convertRange = exports.getScriptKindFromFileName = exports.isSubPath = exports.findTsConfigPath = exports.getExtensionFromScriptKind = exports.getCommitCharactersForScriptElement = exports.scriptElementKindToCompletionItemKind = exports.symbolKindFromString = exports.getSemanticTokenLegend = void 0;
8
4
  const path_1 = require("path");
9
- const utils_1 = require("../../utils");
10
5
  const vscode_languageserver_1 = require("vscode-languageserver");
11
6
  const documents_1 = require("../../core/documents");
7
+ const utils_1 = require("../../utils");
12
8
  function getSemanticTokenLegend() {
13
9
  const tokenModifiers = [];
14
10
  [
15
- [0 /* declaration */, vscode_languageserver_1.SemanticTokenModifiers.declaration],
16
- [1 /* static */, vscode_languageserver_1.SemanticTokenModifiers.static],
17
- [2 /* async */, vscode_languageserver_1.SemanticTokenModifiers.async],
18
- [3 /* readonly */, vscode_languageserver_1.SemanticTokenModifiers.readonly],
19
- [4 /* defaultLibrary */, vscode_languageserver_1.SemanticTokenModifiers.defaultLibrary],
20
- [5 /* local */, 'local'],
11
+ [0 /* TokenModifier.declaration */, vscode_languageserver_1.SemanticTokenModifiers.declaration],
12
+ [1 /* TokenModifier.static */, vscode_languageserver_1.SemanticTokenModifiers.static],
13
+ [2 /* TokenModifier.async */, vscode_languageserver_1.SemanticTokenModifiers.async],
14
+ [3 /* TokenModifier.readonly */, vscode_languageserver_1.SemanticTokenModifiers.readonly],
15
+ [4 /* TokenModifier.defaultLibrary */, vscode_languageserver_1.SemanticTokenModifiers.defaultLibrary],
16
+ [5 /* TokenModifier.local */, 'local'],
21
17
  ].forEach(([tsModifier, legend]) => (tokenModifiers[tsModifier] = legend));
22
18
  const tokenTypes = [];
23
19
  [
24
- [0 /* class */, vscode_languageserver_1.SemanticTokenTypes.class],
25
- [1 /* enum */, vscode_languageserver_1.SemanticTokenTypes.enum],
26
- [2 /* interface */, vscode_languageserver_1.SemanticTokenTypes.interface],
27
- [3 /* namespace */, vscode_languageserver_1.SemanticTokenTypes.namespace],
28
- [4 /* typeParameter */, vscode_languageserver_1.SemanticTokenTypes.typeParameter],
29
- [5 /* type */, vscode_languageserver_1.SemanticTokenTypes.type],
30
- [6 /* parameter */, vscode_languageserver_1.SemanticTokenTypes.parameter],
31
- [7 /* variable */, vscode_languageserver_1.SemanticTokenTypes.variable],
32
- [8 /* enumMember */, vscode_languageserver_1.SemanticTokenTypes.enumMember],
33
- [9 /* property */, vscode_languageserver_1.SemanticTokenTypes.property],
34
- [10 /* function */, vscode_languageserver_1.SemanticTokenTypes.function],
35
- [11 /* method */, vscode_languageserver_1.SemanticTokenTypes.method],
20
+ [0 /* TokenType.class */, vscode_languageserver_1.SemanticTokenTypes.class],
21
+ [1 /* TokenType.enum */, vscode_languageserver_1.SemanticTokenTypes.enum],
22
+ [2 /* TokenType.interface */, vscode_languageserver_1.SemanticTokenTypes.interface],
23
+ [3 /* TokenType.namespace */, vscode_languageserver_1.SemanticTokenTypes.namespace],
24
+ [4 /* TokenType.typeParameter */, vscode_languageserver_1.SemanticTokenTypes.typeParameter],
25
+ [5 /* TokenType.type */, vscode_languageserver_1.SemanticTokenTypes.type],
26
+ [6 /* TokenType.parameter */, vscode_languageserver_1.SemanticTokenTypes.parameter],
27
+ [7 /* TokenType.variable */, vscode_languageserver_1.SemanticTokenTypes.variable],
28
+ [8 /* TokenType.enumMember */, vscode_languageserver_1.SemanticTokenTypes.enumMember],
29
+ [9 /* TokenType.property */, vscode_languageserver_1.SemanticTokenTypes.property],
30
+ [10 /* TokenType.function */, vscode_languageserver_1.SemanticTokenTypes.function],
31
+ [11 /* TokenType.method */, vscode_languageserver_1.SemanticTokenTypes.method],
36
32
  ].forEach(([tokenType, legend]) => (tokenTypes[tokenType] = legend));
37
33
  return {
38
34
  tokenModifiers,
@@ -89,72 +85,72 @@ function symbolKindFromString(kind) {
89
85
  }
90
86
  }
91
87
  exports.symbolKindFromString = symbolKindFromString;
92
- function scriptElementKindToCompletionItemKind(kind) {
88
+ function scriptElementKindToCompletionItemKind(kind, ts) {
93
89
  switch (kind) {
94
- case typescript_1.default.ScriptElementKind.primitiveType:
95
- case typescript_1.default.ScriptElementKind.keyword:
90
+ case ts.ScriptElementKind.primitiveType:
91
+ case ts.ScriptElementKind.keyword:
96
92
  return vscode_languageserver_1.CompletionItemKind.Keyword;
97
- case typescript_1.default.ScriptElementKind.constElement:
93
+ case ts.ScriptElementKind.constElement:
98
94
  return vscode_languageserver_1.CompletionItemKind.Constant;
99
- case typescript_1.default.ScriptElementKind.letElement:
100
- case typescript_1.default.ScriptElementKind.variableElement:
101
- case typescript_1.default.ScriptElementKind.localVariableElement:
102
- case typescript_1.default.ScriptElementKind.alias:
95
+ case ts.ScriptElementKind.letElement:
96
+ case ts.ScriptElementKind.variableElement:
97
+ case ts.ScriptElementKind.localVariableElement:
98
+ case ts.ScriptElementKind.alias:
103
99
  return vscode_languageserver_1.CompletionItemKind.Variable;
104
- case typescript_1.default.ScriptElementKind.memberVariableElement:
105
- case typescript_1.default.ScriptElementKind.memberGetAccessorElement:
106
- case typescript_1.default.ScriptElementKind.memberSetAccessorElement:
100
+ case ts.ScriptElementKind.memberVariableElement:
101
+ case ts.ScriptElementKind.memberGetAccessorElement:
102
+ case ts.ScriptElementKind.memberSetAccessorElement:
107
103
  return vscode_languageserver_1.CompletionItemKind.Field;
108
- case typescript_1.default.ScriptElementKind.functionElement:
104
+ case ts.ScriptElementKind.functionElement:
109
105
  return vscode_languageserver_1.CompletionItemKind.Function;
110
- case typescript_1.default.ScriptElementKind.memberFunctionElement:
111
- case typescript_1.default.ScriptElementKind.constructSignatureElement:
112
- case typescript_1.default.ScriptElementKind.callSignatureElement:
113
- case typescript_1.default.ScriptElementKind.indexSignatureElement:
106
+ case ts.ScriptElementKind.memberFunctionElement:
107
+ case ts.ScriptElementKind.constructSignatureElement:
108
+ case ts.ScriptElementKind.callSignatureElement:
109
+ case ts.ScriptElementKind.indexSignatureElement:
114
110
  return vscode_languageserver_1.CompletionItemKind.Method;
115
- case typescript_1.default.ScriptElementKind.enumElement:
111
+ case ts.ScriptElementKind.enumElement:
116
112
  return vscode_languageserver_1.CompletionItemKind.Enum;
117
- case typescript_1.default.ScriptElementKind.moduleElement:
118
- case typescript_1.default.ScriptElementKind.externalModuleName:
113
+ case ts.ScriptElementKind.moduleElement:
114
+ case ts.ScriptElementKind.externalModuleName:
119
115
  return vscode_languageserver_1.CompletionItemKind.Module;
120
- case typescript_1.default.ScriptElementKind.classElement:
121
- case typescript_1.default.ScriptElementKind.typeElement:
116
+ case ts.ScriptElementKind.classElement:
117
+ case ts.ScriptElementKind.typeElement:
122
118
  return vscode_languageserver_1.CompletionItemKind.Class;
123
- case typescript_1.default.ScriptElementKind.interfaceElement:
119
+ case ts.ScriptElementKind.interfaceElement:
124
120
  return vscode_languageserver_1.CompletionItemKind.Interface;
125
- case typescript_1.default.ScriptElementKind.warning:
126
- case typescript_1.default.ScriptElementKind.scriptElement:
121
+ case ts.ScriptElementKind.warning:
122
+ case ts.ScriptElementKind.scriptElement:
127
123
  return vscode_languageserver_1.CompletionItemKind.File;
128
- case typescript_1.default.ScriptElementKind.directory:
124
+ case ts.ScriptElementKind.directory:
129
125
  return vscode_languageserver_1.CompletionItemKind.Folder;
130
- case typescript_1.default.ScriptElementKind.string:
126
+ case ts.ScriptElementKind.string:
131
127
  return vscode_languageserver_1.CompletionItemKind.Constant;
132
128
  }
133
129
  return vscode_languageserver_1.CompletionItemKind.Property;
134
130
  }
135
131
  exports.scriptElementKindToCompletionItemKind = scriptElementKindToCompletionItemKind;
136
- function getCommitCharactersForScriptElement(kind) {
132
+ function getCommitCharactersForScriptElement(kind, ts) {
137
133
  const commitCharacters = [];
138
134
  switch (kind) {
139
- case typescript_1.default.ScriptElementKind.memberGetAccessorElement:
140
- case typescript_1.default.ScriptElementKind.memberSetAccessorElement:
141
- case typescript_1.default.ScriptElementKind.constructSignatureElement:
142
- case typescript_1.default.ScriptElementKind.callSignatureElement:
143
- case typescript_1.default.ScriptElementKind.indexSignatureElement:
144
- case typescript_1.default.ScriptElementKind.enumElement:
145
- case typescript_1.default.ScriptElementKind.interfaceElement:
135
+ case ts.ScriptElementKind.memberGetAccessorElement:
136
+ case ts.ScriptElementKind.memberSetAccessorElement:
137
+ case ts.ScriptElementKind.constructSignatureElement:
138
+ case ts.ScriptElementKind.callSignatureElement:
139
+ case ts.ScriptElementKind.indexSignatureElement:
140
+ case ts.ScriptElementKind.enumElement:
141
+ case ts.ScriptElementKind.interfaceElement:
146
142
  commitCharacters.push('.');
147
143
  break;
148
- case typescript_1.default.ScriptElementKind.moduleElement:
149
- case typescript_1.default.ScriptElementKind.alias:
150
- case typescript_1.default.ScriptElementKind.constElement:
151
- case typescript_1.default.ScriptElementKind.letElement:
152
- case typescript_1.default.ScriptElementKind.variableElement:
153
- case typescript_1.default.ScriptElementKind.localVariableElement:
154
- case typescript_1.default.ScriptElementKind.memberVariableElement:
155
- case typescript_1.default.ScriptElementKind.classElement:
156
- case typescript_1.default.ScriptElementKind.functionElement:
157
- case typescript_1.default.ScriptElementKind.memberFunctionElement:
144
+ case ts.ScriptElementKind.moduleElement:
145
+ case ts.ScriptElementKind.alias:
146
+ case ts.ScriptElementKind.constElement:
147
+ case ts.ScriptElementKind.letElement:
148
+ case ts.ScriptElementKind.variableElement:
149
+ case ts.ScriptElementKind.localVariableElement:
150
+ case ts.ScriptElementKind.memberVariableElement:
151
+ case ts.ScriptElementKind.classElement:
152
+ case ts.ScriptElementKind.functionElement:
153
+ case ts.ScriptElementKind.memberFunctionElement:
158
154
  commitCharacters.push('.', ',');
159
155
  commitCharacters.push('(');
160
156
  break;
@@ -162,26 +158,26 @@ function getCommitCharactersForScriptElement(kind) {
162
158
  return commitCharacters.length === 0 ? undefined : commitCharacters;
163
159
  }
164
160
  exports.getCommitCharactersForScriptElement = getCommitCharactersForScriptElement;
165
- function getExtensionFromScriptKind(kind) {
161
+ function getExtensionFromScriptKind(kind, ts) {
166
162
  switch (kind) {
167
- case typescript_1.default.ScriptKind.JSX:
168
- return typescript_1.default.Extension.Jsx;
169
- case typescript_1.default.ScriptKind.TS:
170
- return typescript_1.default.Extension.Ts;
171
- case typescript_1.default.ScriptKind.TSX:
172
- return typescript_1.default.Extension.Tsx;
173
- case typescript_1.default.ScriptKind.JSON:
174
- return typescript_1.default.Extension.Json;
175
- case typescript_1.default.ScriptKind.JS:
163
+ case ts.ScriptKind.JSX:
164
+ return ts.Extension.Jsx;
165
+ case ts.ScriptKind.TS:
166
+ return ts.Extension.Ts;
167
+ case ts.ScriptKind.TSX:
168
+ return ts.Extension.Tsx;
169
+ case ts.ScriptKind.JSON:
170
+ return ts.Extension.Json;
171
+ case ts.ScriptKind.JS:
176
172
  default:
177
- return typescript_1.default.Extension.Js;
173
+ return ts.Extension.Js;
178
174
  }
179
175
  }
180
176
  exports.getExtensionFromScriptKind = getExtensionFromScriptKind;
181
- function findTsConfigPath(fileName, rootUris) {
177
+ function findTsConfigPath(fileName, rootUris, ts) {
182
178
  const searchDir = (0, path_1.dirname)(fileName);
183
- const path = typescript_1.default.findConfigFile(searchDir, typescript_1.default.sys.fileExists, 'tsconfig.json') ||
184
- typescript_1.default.findConfigFile(searchDir, typescript_1.default.sys.fileExists, 'jsconfig.json') ||
179
+ const path = ts.findConfigFile(searchDir, ts.sys.fileExists, 'tsconfig.json') ||
180
+ ts.findConfigFile(searchDir, ts.sys.fileExists, 'jsconfig.json') ||
185
181
  '';
186
182
  // Don't return config files that exceed the current workspace context.
187
183
  return !!path && rootUris.some((rootUri) => isSubPath(rootUri, path)) ? path : '';
@@ -191,37 +187,24 @@ function isSubPath(uri, possibleSubPath) {
191
187
  return (0, utils_1.pathToUrl)(possibleSubPath).startsWith(uri);
192
188
  }
193
189
  exports.isSubPath = isSubPath;
194
- function getScriptKindFromFileName(fileName) {
190
+ function getScriptKindFromFileName(fileName, ts) {
195
191
  const ext = fileName.substring(fileName.lastIndexOf('.'));
196
192
  switch (ext.toLowerCase()) {
197
- case typescript_1.default.Extension.Js:
198
- return typescript_1.default.ScriptKind.JS;
199
- case typescript_1.default.Extension.Jsx:
200
- return typescript_1.default.ScriptKind.JSX;
201
- case typescript_1.default.Extension.Ts:
202
- return typescript_1.default.ScriptKind.TS;
203
- case typescript_1.default.Extension.Tsx:
204
- return typescript_1.default.ScriptKind.TSX;
205
- case typescript_1.default.Extension.Json:
206
- return typescript_1.default.ScriptKind.JSON;
193
+ case ts.Extension.Js:
194
+ return ts.ScriptKind.JS;
195
+ case ts.Extension.Jsx:
196
+ return ts.ScriptKind.JSX;
197
+ case ts.Extension.Ts:
198
+ return ts.ScriptKind.TS;
199
+ case ts.Extension.Tsx:
200
+ return ts.ScriptKind.TSX;
201
+ case ts.Extension.Json:
202
+ return ts.ScriptKind.JSON;
207
203
  default:
208
- return typescript_1.default.ScriptKind.Unknown;
204
+ return ts.ScriptKind.Unknown;
209
205
  }
210
206
  }
211
207
  exports.getScriptKindFromFileName = getScriptKindFromFileName;
212
- function mapSeverity(category) {
213
- switch (category) {
214
- case typescript_1.default.DiagnosticCategory.Error:
215
- return vscode_languageserver_1.DiagnosticSeverity.Error;
216
- case typescript_1.default.DiagnosticCategory.Warning:
217
- return vscode_languageserver_1.DiagnosticSeverity.Warning;
218
- case typescript_1.default.DiagnosticCategory.Suggestion:
219
- return vscode_languageserver_1.DiagnosticSeverity.Hint;
220
- case typescript_1.default.DiagnosticCategory.Message:
221
- return vscode_languageserver_1.DiagnosticSeverity.Information;
222
- }
223
- }
224
- exports.mapSeverity = mapSeverity;
225
208
  function convertRange(document, range) {
226
209
  return vscode_languageserver_1.Range.create(document.positionAt(range.start || 0), document.positionAt((range.start || 0) + (range.length || 0)));
227
210
  }
package/dist/server.d.ts CHANGED
@@ -1,2 +1,6 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
- export declare function startLanguageServer(connection: vscode.Connection): void;
2
+ export interface RuntimeEnvironment {
3
+ loadTypescript: (initOptions: any) => typeof import('typescript/lib/tsserverlibrary');
4
+ loadTypescriptLocalized: (initOptions: any) => Record<string, string> | undefined;
5
+ }
6
+ export declare function startLanguageServer(connection: vscode.Connection, env: RuntimeEnvironment): void;