@astrojs/language-server 0.9.3 → 0.12.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 (97) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/bin/browserServer.js +3 -0
  3. package/bin/nodeServer.js +3 -0
  4. package/dist/browser.d.ts +1 -0
  5. package/dist/browser.js +8 -0
  6. package/dist/check.js +2 -5
  7. package/dist/core/DiagnosticsManager.d.ts +3 -3
  8. package/dist/core/DiagnosticsManager.js +2 -2
  9. package/dist/core/config/ConfigManager.d.ts +19 -164
  10. package/dist/core/config/ConfigManager.js +62 -101
  11. package/dist/core/config/index.d.ts +1 -0
  12. package/dist/core/config/index.js +6 -1
  13. package/dist/core/config/interfaces.d.ts +123 -0
  14. package/dist/core/config/interfaces.js +2 -0
  15. package/dist/core/documents/AstroDocument.d.ts +18 -0
  16. package/dist/core/documents/AstroDocument.js +37 -0
  17. package/dist/core/documents/DocumentBase.d.ts +10 -2
  18. package/dist/core/documents/DocumentBase.js +15 -50
  19. package/dist/core/documents/DocumentManager.d.ts +12 -16
  20. package/dist/core/documents/DocumentManager.js +32 -26
  21. package/dist/core/documents/DocumentMapper.js +3 -1
  22. package/dist/core/documents/index.d.ts +1 -1
  23. package/dist/core/documents/index.js +6 -2
  24. package/dist/core/documents/parseAstro.d.ts +2 -2
  25. package/dist/core/documents/parseHtml.d.ts +2 -2
  26. package/dist/core/documents/parseHtml.js +4 -1
  27. package/dist/core/documents/utils.d.ts +22 -26
  28. package/dist/core/documents/utils.js +96 -134
  29. package/dist/index.d.ts +0 -1
  30. package/dist/index.js +1 -3
  31. package/dist/node.d.ts +1 -0
  32. package/dist/node.js +29 -0
  33. package/dist/plugins/PluginHost.d.ts +10 -9
  34. package/dist/plugins/PluginHost.js +30 -36
  35. package/dist/plugins/astro/AstroPlugin.d.ts +11 -12
  36. package/dist/plugins/astro/AstroPlugin.js +17 -38
  37. package/dist/plugins/astro/features/{CompletionProvider.d.ts → CompletionsProvider.d.ts} +5 -5
  38. package/dist/plugins/astro/features/{CompletionProvider.js → CompletionsProvider.js} +33 -54
  39. package/dist/plugins/css/CSSDocument.d.ts +3 -3
  40. package/dist/plugins/css/CSSDocument.js +7 -16
  41. package/dist/plugins/css/CSSPlugin.d.ts +22 -12
  42. package/dist/plugins/css/CSSPlugin.js +112 -41
  43. package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
  44. package/dist/plugins/css/StyleAttributeDocument.js +2 -2
  45. package/dist/plugins/css/features/astro-selectors.d.ts +2 -0
  46. package/dist/plugins/css/features/astro-selectors.js +16 -0
  47. package/dist/plugins/css/features/{getIdClassCompletion.d.ts → getIdClassCompletions.d.ts} +3 -3
  48. package/dist/plugins/css/features/{getIdClassCompletion.js → getIdClassCompletions.js} +10 -9
  49. package/dist/plugins/css/{service.d.ts → language-service.d.ts} +0 -0
  50. package/dist/plugins/css/{service.js → language-service.js} +2 -1
  51. package/dist/plugins/html/HTMLPlugin.d.ts +15 -17
  52. package/dist/plugins/html/HTMLPlugin.js +33 -41
  53. package/dist/plugins/index.d.ts +2 -2
  54. package/dist/plugins/index.js +7 -3
  55. package/dist/plugins/interfaces.d.ts +35 -48
  56. package/dist/plugins/typescript/LanguageServiceManager.d.ts +33 -14
  57. package/dist/plugins/typescript/LanguageServiceManager.js +57 -32
  58. package/dist/plugins/typescript/TypeScriptPlugin.d.ts +16 -23
  59. package/dist/plugins/typescript/TypeScriptPlugin.js +48 -56
  60. package/dist/plugins/typescript/astro-sys.d.ts +5 -3
  61. package/dist/plugins/typescript/astro-sys.js +24 -41
  62. package/dist/plugins/typescript/features/CompletionsProvider.d.ts +6 -6
  63. package/dist/plugins/typescript/features/CompletionsProvider.js +17 -33
  64. package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +4 -4
  65. package/dist/plugins/typescript/features/DiagnosticsProvider.js +22 -61
  66. package/dist/plugins/typescript/features/HoverProvider.d.ts +4 -5
  67. package/dist/plugins/typescript/features/HoverProvider.js +9 -10
  68. package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +4 -5
  69. package/dist/plugins/typescript/features/SignatureHelpProvider.js +15 -11
  70. package/dist/plugins/typescript/features/utils.d.ts +1 -12
  71. package/dist/plugins/typescript/features/utils.js +2 -22
  72. package/dist/plugins/typescript/language-service.d.ts +38 -0
  73. package/dist/plugins/typescript/language-service.js +222 -0
  74. package/dist/plugins/typescript/module-loader.d.ts +5 -8
  75. package/dist/plugins/typescript/module-loader.js +43 -23
  76. package/dist/plugins/typescript/{DocumentSnapshot.d.ts → snapshots/DocumentSnapshot.d.ts} +45 -42
  77. package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +135 -0
  78. package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +42 -0
  79. package/dist/plugins/typescript/snapshots/SnapshotManager.js +197 -0
  80. package/dist/plugins/typescript/snapshots/utils.d.ts +28 -0
  81. package/dist/plugins/typescript/snapshots/utils.js +84 -0
  82. package/dist/plugins/typescript/utils.d.ts +10 -11
  83. package/dist/plugins/typescript/utils.js +122 -151
  84. package/dist/server.d.ts +2 -4
  85. package/dist/server.js +91 -54
  86. package/dist/utils.d.ts +16 -8
  87. package/dist/utils.js +29 -14
  88. package/package.json +19 -13
  89. package/bin/server.js +0 -7
  90. package/dist/core/documents/Document.d.ts +0 -51
  91. package/dist/core/documents/Document.js +0 -135
  92. package/dist/plugins/typescript/DocumentSnapshot.js +0 -202
  93. package/dist/plugins/typescript/SnapshotManager.d.ts +0 -24
  94. package/dist/plugins/typescript/SnapshotManager.js +0 -97
  95. package/dist/plugins/typescript/languageService.d.ts +0 -17
  96. package/dist/plugins/typescript/languageService.js +0 -169
  97. package/types/index.d.ts +0 -4
@@ -1,202 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.TypeScriptDocumentSnapshot = exports.DocumentFragmentSnapshot = exports.createDocumentSnapshot = void 0;
26
- const ts = __importStar(require("typescript"));
27
- const documents_1 = require("../../core/documents");
28
- const utils_1 = require("../../core/documents/utils");
29
- const utils_2 = require("../../utils");
30
- const utils_3 = require("./utils");
31
- const os_1 = require("os");
32
- const astro2tsx_1 = __importDefault(require("./astro2tsx"));
33
- const createDocumentSnapshot = (filePath, currentText, createDocument) => {
34
- var _a;
35
- const text = currentText || ((_a = ts.sys.readFile(filePath)) !== null && _a !== void 0 ? _a : '');
36
- if ((0, utils_3.isAstroFilePath)(filePath)) {
37
- if (!createDocument)
38
- throw new Error('Astro documents require the "createDocument" utility to be provided');
39
- const snapshot = new AstroDocumentSnapshot(createDocument(filePath, text, currentText !== null));
40
- return snapshot;
41
- }
42
- return new TypeScriptDocumentSnapshot(0, filePath, text);
43
- };
44
- exports.createDocumentSnapshot = createDocumentSnapshot;
45
- class AstroDocumentSnapshot {
46
- constructor(doc) {
47
- this.doc = doc;
48
- this.version = this.doc.version;
49
- this.scriptKind = ts.ScriptKind.Unknown;
50
- this.parserError = null;
51
- }
52
- async getFragment() {
53
- const uri = (0, utils_2.pathToUrl)(this.filePath);
54
- const mapper = await this.getMapper(uri);
55
- return new DocumentFragmentSnapshot(mapper, this.doc);
56
- }
57
- async destroyFragment() {
58
- return;
59
- }
60
- get text() {
61
- let raw = this.doc.getText();
62
- return (0, astro2tsx_1.default)(raw).code;
63
- }
64
- get filePath() {
65
- return this.doc.getFilePath() || '';
66
- }
67
- getText(start, end) {
68
- return this.text.substring(start, end);
69
- }
70
- getLength() {
71
- return this.text.length;
72
- }
73
- getFullText() {
74
- return this.text;
75
- }
76
- getChangeRange() {
77
- return undefined;
78
- }
79
- positionAt(offset) {
80
- return (0, utils_1.positionAt)(offset, this.text);
81
- }
82
- getLineContainingOffset(offset) {
83
- const chunks = this.getText(0, offset).split(os_1.EOL);
84
- return chunks[chunks.length - 1];
85
- }
86
- offsetAt(position) {
87
- return (0, utils_1.offsetAt)(position, this.text);
88
- }
89
- getMapper(uri) {
90
- return new documents_1.IdentityMapper(uri);
91
- }
92
- }
93
- class DocumentFragmentSnapshot {
94
- constructor(mapper, parent) {
95
- this.mapper = mapper;
96
- this.parent = parent;
97
- this.parserError = null;
98
- this.scriptKind = ts.ScriptKind.TSX;
99
- this.scriptInfo = null;
100
- const filePath = parent.getFilePath();
101
- if (!filePath)
102
- throw new Error('Cannot create a document fragment from a non-local document');
103
- const text = parent.getText();
104
- this.version = parent.version;
105
- this.filePath = (0, utils_3.toVirtualAstroFilePath)(filePath);
106
- this.url = (0, utils_3.toVirtualAstroFilePath)(filePath);
107
- this.text = (0, astro2tsx_1.default)(text).code;
108
- }
109
- getText(start, end) {
110
- return this.text.substring(start, end);
111
- }
112
- getLength() {
113
- return this.text.length;
114
- }
115
- getFullText() {
116
- return this.text;
117
- }
118
- getChangeRange() {
119
- return undefined;
120
- }
121
- positionAt(offset) {
122
- return (0, utils_1.positionAt)(offset, this.text);
123
- }
124
- getLineContainingOffset(offset) {
125
- const chunks = this.getText(0, offset).split(os_1.EOL);
126
- return chunks[chunks.length - 1];
127
- }
128
- offsetAt(position) {
129
- return (0, utils_1.offsetAt)(position, this.text);
130
- }
131
- getOriginalPosition(pos) {
132
- return this.mapper.getOriginalPosition(pos);
133
- }
134
- getGeneratedPosition(pos) {
135
- return this.mapper.getGeneratedPosition(pos);
136
- }
137
- isInGenerated(pos) {
138
- return !(0, utils_1.isInTag)(pos, this.parent.styleInfo);
139
- }
140
- getURL() {
141
- return this.url;
142
- }
143
- }
144
- exports.DocumentFragmentSnapshot = DocumentFragmentSnapshot;
145
- class TypeScriptDocumentSnapshot {
146
- constructor(version, filePath, text) {
147
- this.version = version;
148
- this.filePath = filePath;
149
- this.text = text;
150
- this.scriptKind = (0, utils_3.getScriptKindFromFileName)(this.filePath);
151
- this.scriptInfo = null;
152
- this.parserError = null;
153
- this.url = (0, utils_2.pathToUrl)(filePath);
154
- }
155
- getText(start, end) {
156
- return this.text.substring(start, end);
157
- }
158
- getLength() {
159
- return this.text.length;
160
- }
161
- getFullText() {
162
- return this.text;
163
- }
164
- getChangeRange() {
165
- return undefined;
166
- }
167
- positionAt(offset) {
168
- return (0, utils_1.positionAt)(offset, this.text);
169
- }
170
- offsetAt(position) {
171
- return (0, utils_1.offsetAt)(position, this.text);
172
- }
173
- async getFragment() {
174
- return this;
175
- }
176
- getOriginalPosition(pos) {
177
- return pos;
178
- }
179
- destroyFragment() {
180
- // nothing to clean up
181
- }
182
- getLineContainingOffset(offset) {
183
- const chunks = this.getText(0, offset).split('\n');
184
- return chunks[chunks.length - 1];
185
- }
186
- update(changes) {
187
- for (const change of changes) {
188
- let start = 0;
189
- let end = 0;
190
- if ('range' in change) {
191
- start = this.offsetAt(change.range.start);
192
- end = this.offsetAt(change.range.end);
193
- }
194
- else {
195
- end = this.getLength();
196
- }
197
- this.text = this.text.slice(0, start) + change.text + this.text.slice(end);
198
- }
199
- this.version++;
200
- }
201
- }
202
- exports.TypeScriptDocumentSnapshot = TypeScriptDocumentSnapshot;
@@ -1,24 +0,0 @@
1
- import { TextDocumentContentChangeEvent } from 'vscode-languageserver';
2
- import { DocumentSnapshot } from './DocumentSnapshot';
3
- export interface TsFilesSpec {
4
- include?: readonly string[];
5
- exclude?: readonly string[];
6
- }
7
- export declare class SnapshotManager {
8
- private projectFiles;
9
- private fileSpec;
10
- private workspaceRoot;
11
- private documents;
12
- private lastLogged;
13
- private readonly watchExtensions;
14
- constructor(projectFiles: string[], fileSpec: TsFilesSpec, workspaceRoot: string);
15
- updateProjectFiles(): void;
16
- updateProjectFile(fileName: string, changes?: TextDocumentContentChangeEvent[]): void;
17
- has(fileName: string): boolean;
18
- get(fileName: string): DocumentSnapshot | undefined;
19
- set(fileName: string, snapshot: DocumentSnapshot): Map<string, DocumentSnapshot>;
20
- delete(fileName: string): boolean;
21
- getFileNames(): string[];
22
- getProjectFileNames(): string[];
23
- private logStatistics;
24
- }
@@ -1,97 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.SnapshotManager = void 0;
23
- const ts = __importStar(require("typescript"));
24
- const utils_1 = require("./utils");
25
- const DocumentSnapshot_1 = require("./DocumentSnapshot");
26
- class SnapshotManager {
27
- constructor(projectFiles, fileSpec, workspaceRoot) {
28
- this.projectFiles = projectFiles;
29
- this.fileSpec = fileSpec;
30
- this.workspaceRoot = workspaceRoot;
31
- this.documents = new Map();
32
- this.lastLogged = new Date(new Date().getTime() - 60001);
33
- this.watchExtensions = [ts.Extension.Dts, ts.Extension.Js, ts.Extension.Jsx, ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Json];
34
- }
35
- updateProjectFiles() {
36
- const { include, exclude } = this.fileSpec;
37
- if ((include === null || include === void 0 ? void 0 : include.length) === 0)
38
- return;
39
- const projectFiles = ts.sys.readDirectory(this.workspaceRoot, this.watchExtensions, exclude, include);
40
- this.projectFiles = Array.from(new Set([...this.projectFiles, ...projectFiles]));
41
- }
42
- updateProjectFile(fileName, changes) {
43
- const previousSnapshot = this.get(fileName);
44
- if (changes) {
45
- if (!(previousSnapshot instanceof DocumentSnapshot_1.TypeScriptDocumentSnapshot)) {
46
- return;
47
- }
48
- previousSnapshot.update(changes);
49
- }
50
- else {
51
- const newSnapshot = (0, DocumentSnapshot_1.createDocumentSnapshot)(fileName, null);
52
- if (previousSnapshot) {
53
- newSnapshot.version = previousSnapshot.version + 1;
54
- }
55
- else {
56
- // ensure it's greater than initial version
57
- // so that ts server picks up the change
58
- newSnapshot.version += 1;
59
- }
60
- this.set(fileName, newSnapshot);
61
- }
62
- }
63
- has(fileName) {
64
- return this.projectFiles.includes(fileName) || this.getFileNames().includes(fileName);
65
- }
66
- get(fileName) {
67
- return this.documents.get(fileName);
68
- }
69
- set(fileName, snapshot) {
70
- return this.documents.set(fileName, snapshot);
71
- }
72
- delete(fileName) {
73
- this.projectFiles = this.projectFiles.filter((s) => s !== fileName);
74
- return this.documents.delete(fileName);
75
- }
76
- getFileNames() {
77
- return Array.from(this.documents.keys()).map((fileName) => (0, utils_1.toVirtualAstroFilePath)(fileName));
78
- }
79
- getProjectFileNames() {
80
- return [...this.projectFiles];
81
- }
82
- logStatistics() {
83
- const date = new Date();
84
- // Don't use setInterval because that will keep tests running forever
85
- if (date.getTime() - this.lastLogged.getTime() > 60000) {
86
- this.lastLogged = date;
87
- const projectFiles = this.getProjectFileNames();
88
- const allFiles = Array.from(new Set([...projectFiles, ...this.getFileNames()]));
89
- console.log('SnapshotManager File Statistics:\n' +
90
- `Project files: ${projectFiles.length}\n` +
91
- `Astro files: ${allFiles.filter((name) => name.endsWith('.astro')).length}\n` +
92
- `From node_modules: ${allFiles.filter((name) => name.includes('node_modules')).length}\n` +
93
- `Total: ${allFiles.length}`);
94
- }
95
- }
96
- }
97
- exports.SnapshotManager = SnapshotManager;
@@ -1,17 +0,0 @@
1
- import * as ts from 'typescript';
2
- import { Document } from '../../core/documents';
3
- import { SnapshotManager } from './SnapshotManager';
4
- export interface LanguageServiceContainer {
5
- readonly tsconfigPath: string;
6
- readonly snapshotManager: SnapshotManager;
7
- getService(): ts.LanguageService;
8
- updateDocument(documentOrFilePath: Document | string): ts.IScriptSnapshot;
9
- deleteDocument(filePath: string): void;
10
- }
11
- export interface LanguageServiceDocumentContext {
12
- getWorkspaceRoot(fileName: string): string;
13
- createDocument: (fileName: string, content: string, overrideText: boolean) => Document;
14
- }
15
- export declare function getLanguageService(path: string, workspaceUris: string[], docContext: LanguageServiceDocumentContext): Promise<LanguageServiceContainer>;
16
- export declare function getLanguageServiceForDocument(document: Document, workspaceUris: string[], docContext: LanguageServiceDocumentContext): Promise<ts.LanguageService>;
17
- export declare function getLanguageServiceForPath(path: string, workspaceUris: string[], docContext: LanguageServiceDocumentContext): Promise<ts.LanguageService>;
@@ -1,169 +0,0 @@
1
- "use strict";
2
- /* eslint-disable require-jsdoc */
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
- }) : (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- o[k2] = m[k];
9
- }));
10
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
- Object.defineProperty(o, "default", { enumerable: true, value: v });
12
- }) : function(o, v) {
13
- o["default"] = v;
14
- });
15
- var __importStar = (this && this.__importStar) || function (mod) {
16
- if (mod && mod.__esModule) return mod;
17
- var result = {};
18
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
- __setModuleDefault(result, mod);
20
- return result;
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.getLanguageServiceForPath = exports.getLanguageServiceForDocument = exports.getLanguageService = void 0;
24
- const ts = __importStar(require("typescript"));
25
- const path_1 = require("path");
26
- const utils_1 = require("./utils");
27
- const SnapshotManager_1 = require("./SnapshotManager");
28
- const DocumentSnapshot_1 = require("./DocumentSnapshot");
29
- const module_loader_1 = require("./module-loader");
30
- const services = new Map();
31
- async function getLanguageService(path, workspaceUris, docContext) {
32
- const tsconfigPath = (0, utils_1.findTsConfigPath)(path, workspaceUris);
33
- const workspaceRoot = docContext.getWorkspaceRoot(path);
34
- let service;
35
- if (services.has(tsconfigPath)) {
36
- service = (await services.get(tsconfigPath));
37
- }
38
- else {
39
- const newServicePromise = createLanguageService(tsconfigPath, workspaceRoot, docContext);
40
- services.set(tsconfigPath, newServicePromise);
41
- service = await newServicePromise;
42
- }
43
- return service;
44
- }
45
- exports.getLanguageService = getLanguageService;
46
- async function getLanguageServiceForDocument(document, workspaceUris, docContext) {
47
- return getLanguageServiceForPath(document.getFilePath() || '', workspaceUris, docContext);
48
- }
49
- exports.getLanguageServiceForDocument = getLanguageServiceForDocument;
50
- async function getLanguageServiceForPath(path, workspaceUris, docContext) {
51
- return (await getLanguageService(path, workspaceUris, docContext)).getService();
52
- }
53
- exports.getLanguageServiceForPath = getLanguageServiceForPath;
54
- async function createLanguageService(tsconfigPath, workspaceRoot, docContext) {
55
- var _a, _b, _c;
56
- const parseConfigHost = {
57
- ...ts.sys,
58
- readDirectory: (path, extensions, exclude, include, depth) => {
59
- return ts.sys.readDirectory(path, [...extensions, '.vue', '.svelte', '.astro', '.js', '.jsx'], exclude, include, depth);
60
- },
61
- };
62
- let configJson = (tsconfigPath && ts.readConfigFile(tsconfigPath, ts.sys.readFile).config) || {};
63
- // If our user has types in their config but it doesn't include the types needed for Astro, add them to the config
64
- if (((_a = configJson.compilerOptions) === null || _a === void 0 ? void 0 : _a.types) &&
65
- !((_b = configJson.compilerOptions) === null || _b === void 0 ? void 0 : _b.types.includes("astro/env"))) {
66
- configJson.compilerOptions.types.push("astro/env");
67
- }
68
- configJson.compilerOptions = Object.assign(getDefaultCompilerOptions(), configJson.compilerOptions);
69
- // If the user supplied exclude, let's use theirs
70
- (_c = configJson.exclude) !== null && _c !== void 0 ? _c : (configJson.exclude = getDefaultExclude());
71
- // Delete include so that .astro files don't get mistakenly excluded by the user
72
- delete configJson.include;
73
- // Everything here will always, unconditionally, be in the resulting config, not the opposite, tricky
74
- const existingCompilerOptions = {
75
- // Setting strict to true for .astro files leads to a lot of unrelated errors (see language-tools#91) so we force it off for .astro files
76
- strict: false,
77
- jsx: ts.JsxEmit.Preserve,
78
- module: ts.ModuleKind.ESNext,
79
- target: ts.ScriptTarget.ESNext,
80
- };
81
- const project = ts.parseJsonConfigFileContent(configJson, parseConfigHost, workspaceRoot, existingCompilerOptions, (0, path_1.basename)(tsconfigPath), undefined, [
82
- { extension: '.vue', isMixedContent: true, scriptKind: ts.ScriptKind.Deferred },
83
- { extension: '.svelte', isMixedContent: true, scriptKind: ts.ScriptKind.Deferred },
84
- { extension: '.astro', isMixedContent: true, scriptKind: ts.ScriptKind.Deferred },
85
- ]);
86
- let projectVersion = 0;
87
- const snapshotManager = new SnapshotManager_1.SnapshotManager(project.fileNames, {
88
- exclude: ['node_modules', 'dist'],
89
- include: ['src'],
90
- }, workspaceRoot || process.cwd());
91
- const astroModuleLoader = (0, module_loader_1.createAstroModuleLoader)(getScriptSnapshot, {});
92
- const host = {
93
- getNewLine: () => ts.sys.newLine,
94
- useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
95
- readFile: astroModuleLoader.readFile,
96
- writeFile: astroModuleLoader.writeFile,
97
- fileExists: astroModuleLoader.fileExists,
98
- directoryExists: astroModuleLoader.directoryExists,
99
- getDirectories: astroModuleLoader.getDirectories,
100
- readDirectory: astroModuleLoader.readDirectory,
101
- realpath: astroModuleLoader.realpath,
102
- getCompilationSettings: () => project.options,
103
- getCurrentDirectory: () => workspaceRoot,
104
- getDefaultLibFileName: () => ts.getDefaultLibFilePath(project.options),
105
- getProjectVersion: () => projectVersion.toString(),
106
- getScriptFileNames: () => Array.from(new Set([...snapshotManager.getFileNames(), ...snapshotManager.getProjectFileNames()])),
107
- getScriptSnapshot,
108
- getScriptVersion: (fileName) => {
109
- let snapshotVersion = getScriptSnapshot(fileName).version.toString();
110
- return snapshotVersion;
111
- },
112
- };
113
- const languageService = ts.createLanguageService(host);
114
- const languageServiceProxy = new Proxy(languageService, {
115
- get(target, prop) {
116
- return Reflect.get(target, prop);
117
- },
118
- });
119
- return {
120
- tsconfigPath,
121
- snapshotManager,
122
- getService: () => languageServiceProxy,
123
- updateDocument,
124
- deleteDocument,
125
- };
126
- function onProjectUpdated() {
127
- projectVersion++;
128
- }
129
- function deleteDocument(filePath) {
130
- snapshotManager.delete(filePath);
131
- }
132
- function updateDocument(documentOrFilePath) {
133
- const filePath = (0, utils_1.ensureRealAstroFilePath)(typeof documentOrFilePath === 'string' ? documentOrFilePath : documentOrFilePath.getFilePath() || '');
134
- const document = typeof documentOrFilePath === 'string' ? undefined : documentOrFilePath;
135
- if (!filePath) {
136
- throw new Error(`Unable to find document`);
137
- }
138
- const previousSnapshot = snapshotManager.get(filePath);
139
- if (document && (previousSnapshot === null || previousSnapshot === void 0 ? void 0 : previousSnapshot.version.toString()) === `${document.version}`) {
140
- return previousSnapshot;
141
- }
142
- const currentText = document ? document.getText() : null;
143
- const snapshot = (0, DocumentSnapshot_1.createDocumentSnapshot)(filePath, currentText, docContext.createDocument);
144
- snapshotManager.set(filePath, snapshot);
145
- onProjectUpdated();
146
- return snapshot;
147
- }
148
- function getScriptSnapshot(fileName) {
149
- fileName = (0, utils_1.ensureRealAstroFilePath)(fileName);
150
- let doc = snapshotManager.get(fileName);
151
- if (doc) {
152
- return doc;
153
- }
154
- doc = (0, DocumentSnapshot_1.createDocumentSnapshot)(fileName, null, docContext.createDocument);
155
- snapshotManager.set(fileName, doc);
156
- return doc;
157
- }
158
- }
159
- function getDefaultCompilerOptions() {
160
- return {
161
- maxNodeModuleJsDepth: 2,
162
- allowSyntheticDefaultImports: true,
163
- allowJs: true,
164
- types: ["astro/env"]
165
- };
166
- }
167
- function getDefaultExclude() {
168
- return ['dist', 'node_modules'];
169
- }
package/types/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * Starts `astro-languageservice`
3
- */
4
- export function startServer(): void {}