@astrojs/language-server 0.9.3 → 0.11.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @astrojs/language-server
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - fd92a85: Add support for loading files from non-JSX frameworks such as Vue and Svelte
8
+
9
+ ### Patch Changes
10
+
11
+ - d056cd5: Fixes production bugs in extension
12
+
3
13
  ## 0.9.3
4
14
 
5
15
  ### Patch Changes
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,6 +1,6 @@
1
1
  import * as ts from 'typescript';
2
2
  import { TextDocumentContentChangeEvent, Position, Range } from 'vscode-languageserver';
3
- import { Document, DocumentMapper } from '../../core/documents';
3
+ import { Document, DocumentMapper, IdentityMapper } from '../../core/documents';
4
4
  /**
5
5
  * The mapper to get from original snapshot positions to generated and vice versa.
6
6
  */
@@ -39,9 +39,10 @@ export interface DocumentSnapshot extends ts.IScriptSnapshot {
39
39
  * Convenience function for getText(0, getLength())
40
40
  */
41
41
  getFullText(): string;
42
+ createFragment(mapper: IdentityMapper): DocumentFragmentSnapshot;
43
+ toTSX(code: string, filePath: string): string;
42
44
  }
43
- export declare const createDocumentSnapshot: (filePath: string, currentText: string | null, createDocument?: ((_filePath: string, text: string, overrideText: boolean) => Document) | undefined) => DocumentSnapshot;
44
- export declare class DocumentFragmentSnapshot implements Omit<DocumentSnapshot, 'getFragment' | 'destroyFragment'>, SnapshotFragment {
45
+ export declare abstract class DocumentFragmentSnapshot implements Omit<DocumentSnapshot, 'createFragment' | 'getFragment' | 'destroyFragment' | 'toTSX'>, SnapshotFragment {
45
46
  private mapper;
46
47
  private parent;
47
48
  version: number;
@@ -51,7 +52,8 @@ export declare class DocumentFragmentSnapshot implements Omit<DocumentSnapshot,
51
52
  parserError: null;
52
53
  scriptKind: ts.ScriptKind;
53
54
  scriptInfo: null;
54
- constructor(mapper: any, parent: Document);
55
+ constructor(mapper: any, parent: Document, toTSX: (code: string, filePath: string) => string);
56
+ abstract toVirtualFilePath(filePath: string): string;
55
57
  getText(start: number, end: number): string;
56
58
  getLength(): number;
57
59
  getFullText(): string;
@@ -64,6 +66,12 @@ export declare class DocumentFragmentSnapshot implements Omit<DocumentSnapshot,
64
66
  isInGenerated(pos: Position): boolean;
65
67
  getURL(): string;
66
68
  }
69
+ declare class FrameworkDocumentFragmentSnapshot extends DocumentFragmentSnapshot {
70
+ toVirtualFilePath(filePath: string): string;
71
+ }
72
+ export declare class AstroDocumentFragmentSnapshot extends DocumentFragmentSnapshot {
73
+ toVirtualFilePath(filePath: string): string;
74
+ }
67
75
  export declare class TypeScriptDocumentSnapshot implements DocumentSnapshot {
68
76
  version: number;
69
77
  readonly filePath: string;
@@ -73,15 +81,19 @@ export declare class TypeScriptDocumentSnapshot implements DocumentSnapshot {
73
81
  parserError: null;
74
82
  url: string;
75
83
  constructor(version: number, filePath: string, text: string);
84
+ toTSX(): any;
85
+ createFragment(): any;
86
+ destroyFragment(): void;
76
87
  getText(start: number, end: number): string;
77
88
  getLength(): number;
78
89
  getFullText(): string;
79
90
  getChangeRange(): undefined;
80
91
  positionAt(offset: number): import("vscode-html-languageservice").Position;
81
92
  offsetAt(position: Position): number;
82
- getFragment(): Promise<DocumentFragmentSnapshot>;
93
+ getFragment(): Promise<FrameworkDocumentFragmentSnapshot>;
83
94
  getOriginalPosition(pos: Position): Position;
84
- destroyFragment(): void;
85
95
  getLineContainingOffset(offset: number): string;
86
96
  update(changes: TextDocumentContentChangeEvent[]): void;
87
97
  }
98
+ export declare const createDocumentSnapshot: (filePath: string, currentText: string | null, createDocument?: ((_filePath: string, text: string, overrideText: boolean) => Document) | undefined) => DocumentSnapshot;
99
+ export {};
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -22,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
27
  };
24
28
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.TypeScriptDocumentSnapshot = exports.DocumentFragmentSnapshot = exports.createDocumentSnapshot = void 0;
29
+ exports.createDocumentSnapshot = exports.TypeScriptDocumentSnapshot = exports.AstroDocumentFragmentSnapshot = exports.DocumentFragmentSnapshot = void 0;
26
30
  const ts = __importStar(require("typescript"));
27
31
  const documents_1 = require("../../core/documents");
28
32
  const utils_1 = require("../../core/documents/utils");
@@ -30,39 +34,22 @@ const utils_2 = require("../../utils");
30
34
  const utils_3 = require("./utils");
31
35
  const os_1 = require("os");
32
36
  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;
37
+ const svelte_language_integration_1 = require("@astrojs/svelte-language-integration");
38
+ class DocumentFragmentSnapshot {
39
+ constructor(mapper, parent, toTSX) {
40
+ this.mapper = mapper;
41
+ this.parent = parent;
50
42
  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() || '';
43
+ this.scriptKind = ts.ScriptKind.TSX;
44
+ this.scriptInfo = null;
45
+ const filePath = parent.getFilePath();
46
+ if (!filePath)
47
+ throw new Error('Cannot create a document fragment from a non-local document');
48
+ const text = parent.getText();
49
+ this.version = parent.version;
50
+ this.filePath = this.toVirtualFilePath(filePath);
51
+ this.url = this.toVirtualFilePath(filePath);
52
+ this.text = toTSX(text, this.filePath);
66
53
  }
67
54
  getText(start, end) {
68
55
  return this.text.substring(start, end);
@@ -86,25 +73,33 @@ class AstroDocumentSnapshot {
86
73
  offsetAt(position) {
87
74
  return (0, utils_1.offsetAt)(position, this.text);
88
75
  }
89
- getMapper(uri) {
90
- return new documents_1.IdentityMapper(uri);
76
+ getOriginalPosition(pos) {
77
+ return this.mapper.getOriginalPosition(pos);
78
+ }
79
+ getGeneratedPosition(pos) {
80
+ return this.mapper.getGeneratedPosition(pos);
81
+ }
82
+ isInGenerated(pos) {
83
+ return !(0, utils_1.isInTag)(pos, this.parent.styleInfo);
84
+ }
85
+ getURL() {
86
+ return this.url;
91
87
  }
92
88
  }
93
- class DocumentFragmentSnapshot {
94
- constructor(mapper, parent) {
95
- this.mapper = mapper;
96
- this.parent = parent;
97
- this.parserError = null;
89
+ exports.DocumentFragmentSnapshot = DocumentFragmentSnapshot;
90
+ class DocumentSnapshotBase {
91
+ constructor(doc) {
92
+ this.doc = doc;
93
+ this.version = this.doc.version;
98
94
  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;
95
+ this.parserError = null;
96
+ }
97
+ get text() {
98
+ let raw = this.doc.getText();
99
+ return this.toTSX(raw, this.filePath);
100
+ }
101
+ get filePath() {
102
+ return this.doc.getFilePath() || '';
108
103
  }
109
104
  getText(start, end) {
110
105
  return this.text.substring(start, end);
@@ -128,20 +123,56 @@ class DocumentFragmentSnapshot {
128
123
  offsetAt(position) {
129
124
  return (0, utils_1.offsetAt)(position, this.text);
130
125
  }
131
- getOriginalPosition(pos) {
132
- return this.mapper.getOriginalPosition(pos);
126
+ getMapper(uri) {
127
+ return new documents_1.IdentityMapper(uri);
133
128
  }
134
- getGeneratedPosition(pos) {
135
- return this.mapper.getGeneratedPosition(pos);
129
+ }
130
+ class FrameworkDocumentSnapshot extends DocumentSnapshotBase {
131
+ toTSX(code, filePath) {
132
+ if ((0, utils_3.isVirtualSvelteFilePath)(filePath)) {
133
+ return (0, svelte_language_integration_1.toTSX)(code);
134
+ }
135
+ return 'export default function() {}';
136
136
  }
137
- isInGenerated(pos) {
138
- return !(0, utils_1.isInTag)(pos, this.parent.styleInfo);
137
+ createFragment(mapper) {
138
+ return new FrameworkDocumentFragmentSnapshot(mapper, this.doc, this.toTSX);
139
139
  }
140
- getURL() {
141
- return this.url;
140
+ async getFragment() {
141
+ const uri = (0, utils_2.pathToUrl)(this.filePath);
142
+ const mapper = await this.getMapper(uri);
143
+ return this.createFragment(mapper);
144
+ }
145
+ async destroyFragment() {
146
+ return;
142
147
  }
143
148
  }
144
- exports.DocumentFragmentSnapshot = DocumentFragmentSnapshot;
149
+ class FrameworkDocumentFragmentSnapshot extends DocumentFragmentSnapshot {
150
+ toVirtualFilePath(filePath) {
151
+ return filePath;
152
+ }
153
+ }
154
+ class AstroDocumentSnapshot extends DocumentSnapshotBase {
155
+ createFragment(mapper) {
156
+ return new AstroDocumentFragmentSnapshot(mapper, this.doc, this.toTSX);
157
+ }
158
+ async getFragment() {
159
+ const uri = (0, utils_2.pathToUrl)(this.filePath);
160
+ const mapper = await this.getMapper(uri);
161
+ return new AstroDocumentFragmentSnapshot(mapper, this.doc, this.toTSX);
162
+ }
163
+ async destroyFragment() {
164
+ return;
165
+ }
166
+ toTSX(code, filePath) {
167
+ return (0, astro2tsx_1.default)(code).code;
168
+ }
169
+ }
170
+ class AstroDocumentFragmentSnapshot extends DocumentFragmentSnapshot {
171
+ toVirtualFilePath(filePath) {
172
+ return (0, utils_3.toVirtualAstroFilePath)(filePath);
173
+ }
174
+ }
175
+ exports.AstroDocumentFragmentSnapshot = AstroDocumentFragmentSnapshot;
145
176
  class TypeScriptDocumentSnapshot {
146
177
  constructor(version, filePath, text) {
147
178
  this.version = version;
@@ -152,6 +183,17 @@ class TypeScriptDocumentSnapshot {
152
183
  this.parserError = null;
153
184
  this.url = (0, utils_2.pathToUrl)(filePath);
154
185
  }
186
+ // We don't create Fragments for TypescriptDocument, nor do we convert them to TSX so those three methods are not
187
+ // necessary, though they're required to be implemented for DocumentSnapshot
188
+ toTSX() {
189
+ return;
190
+ }
191
+ createFragment() {
192
+ return;
193
+ }
194
+ destroyFragment() {
195
+ return;
196
+ }
155
197
  getText(start, end) {
156
198
  return this.text.substring(start, end);
157
199
  }
@@ -176,9 +218,6 @@ class TypeScriptDocumentSnapshot {
176
218
  getOriginalPosition(pos) {
177
219
  return pos;
178
220
  }
179
- destroyFragment() {
180
- // nothing to clean up
181
- }
182
221
  getLineContainingOffset(offset) {
183
222
  const chunks = this.getText(0, offset).split('\n');
184
223
  return chunks[chunks.length - 1];
@@ -200,3 +239,21 @@ class TypeScriptDocumentSnapshot {
200
239
  }
201
240
  }
202
241
  exports.TypeScriptDocumentSnapshot = TypeScriptDocumentSnapshot;
242
+ const createDocumentSnapshot = (filePath, currentText, createDocument) => {
243
+ var _a;
244
+ let text = currentText || ((_a = ts.sys.readFile(filePath.replace(".tsx", ""))) !== null && _a !== void 0 ? _a : '');
245
+ if ((0, utils_3.isVirtualFrameworkFilePath)('vue', 'tsx', filePath) || (0, utils_3.isVirtualFrameworkFilePath)('svelte', 'tsx', filePath)) {
246
+ if (!createDocument)
247
+ throw new Error('Framework documents require the "createDocument" utility to be provided');
248
+ const snapshot = new FrameworkDocumentSnapshot(createDocument(filePath, text, currentText !== null));
249
+ return snapshot;
250
+ }
251
+ if ((0, utils_3.isAstroFilePath)(filePath)) {
252
+ if (!createDocument)
253
+ throw new Error('Astro documents require the "createDocument" utility to be provided');
254
+ const snapshot = new AstroDocumentSnapshot(createDocument(filePath, text, currentText !== null));
255
+ return snapshot;
256
+ }
257
+ return new TypeScriptDocumentSnapshot(0, filePath, text);
258
+ };
259
+ exports.createDocumentSnapshot = createDocumentSnapshot;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -74,10 +78,12 @@ class SnapshotManager {
74
78
  return this.documents.delete(fileName);
75
79
  }
76
80
  getFileNames() {
77
- return Array.from(this.documents.keys()).map((fileName) => (0, utils_1.toVirtualAstroFilePath)(fileName));
81
+ return Array.from(this.documents.keys()).map((fileName) => (0, utils_1.toVirtualFilePath)(fileName));
78
82
  }
79
83
  getProjectFileNames() {
80
- return [...this.projectFiles];
84
+ return this.projectFiles.map((file) => {
85
+ return (0, utils_1.toVirtualFilePath)(file);
86
+ });
81
87
  }
82
88
  logStatistics() {
83
89
  const date = new Date();
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -99,8 +103,8 @@ class TypeScriptPlugin {
99
103
  const result = await Promise.all(defs.definitions.map(async (def) => {
100
104
  const { fragment, snapshot } = await docs.retrieve(def.fileName);
101
105
  if ((0, utils_3.isNoTextSpanInGeneratedCode)(snapshot.getFullText(), def.textSpan)) {
102
- const fileName = (0, utils_1.ensureRealAstroFilePath)(def.fileName);
103
- const textSpan = (0, utils_1.isVirtualAstroFilePath)(tsFilePath) ? { start: 0, length: 0 } : def.textSpan;
106
+ const fileName = (0, utils_1.ensureRealFilePath)(def.fileName);
107
+ const textSpan = (0, utils_1.isVirtualFilePath)(tsFilePath) ? { start: 0, length: 0 } : def.textSpan;
104
108
  return vscode_languageserver_1.LocationLink.create((0, utils_2.pathToUrl)(fileName), (0, utils_1.convertToLocationRange)(fragment, textSpan), (0, utils_1.convertToLocationRange)(fragment, textSpan), (0, utils_1.convertToLocationRange)(mainFragment, defs.textSpan));
105
109
  }
106
110
  }));
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -2,7 +2,11 @@
2
2
  /* eslint-disable require-jsdoc */
3
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
6
10
  }) : (function(o, m, k, k2) {
7
11
  if (k2 === undefined) k2 = k;
8
12
  o[k2] = m[k];
@@ -13,16 +13,19 @@ export declare function convertRange(document: {
13
13
  length?: number;
14
14
  }): Range;
15
15
  export declare function convertToLocationRange(defDoc: SnapshotFragment, textSpan: ts.TextSpan): Range;
16
- declare type FrameworkExt = 'astro' | 'vue' | 'jsx' | 'tsx' | 'svelte';
16
+ declare type FrameworkExt = 'astro' | 'vue' | 'jsx' | 'tsx' | 'svelte' | 'ts';
17
17
  declare type FrameworkVirtualExt = 'ts' | 'tsx';
18
18
  export declare function isVirtualFrameworkFilePath(ext: FrameworkExt, virtualExt: FrameworkVirtualExt, filePath: string): boolean;
19
19
  export declare function isAstroFilePath(filePath: string): boolean;
20
+ export declare function isFrameworkFilePath(filePath: string): boolean;
20
21
  export declare function isVirtualAstroFilePath(filePath: string): boolean;
21
22
  export declare function isVirtualVueFilePath(filePath: string): boolean;
22
23
  export declare function isVirtualJsxFilePath(filePath: string): boolean;
23
24
  export declare function isVirtualSvelteFilePath(filePath: string): boolean;
25
+ export declare function isVirtualTsFilePath(filePath: string): boolean;
24
26
  export declare function isVirtualFilePath(filePath: string): boolean;
25
27
  export declare function toVirtualAstroFilePath(filePath: string): string;
28
+ export declare function toVirtualFilePath(filePath: string): string;
26
29
  export declare function toRealAstroFilePath(filePath: string): string;
27
30
  export declare function ensureRealAstroFilePath(filePath: string): string;
28
31
  export declare function ensureRealFilePath(filePath: string): string;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
23
  return result;
20
24
  };
21
25
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.substituteWithWhitespace = exports.isSubPath = exports.findTsConfigPath = exports.ensureRealFilePath = exports.ensureRealAstroFilePath = exports.toRealAstroFilePath = exports.toVirtualAstroFilePath = exports.isVirtualFilePath = exports.isVirtualSvelteFilePath = exports.isVirtualJsxFilePath = exports.isVirtualVueFilePath = exports.isVirtualAstroFilePath = exports.isAstroFilePath = exports.isVirtualFrameworkFilePath = exports.convertToLocationRange = exports.convertRange = exports.getExtensionFromScriptKind = exports.getScriptKindFromFileName = exports.mapSeverity = exports.getCommitCharactersForScriptElement = exports.scriptElementKindToCompletionItemKind = void 0;
26
+ exports.substituteWithWhitespace = exports.isSubPath = exports.findTsConfigPath = exports.ensureRealFilePath = exports.ensureRealAstroFilePath = exports.toRealAstroFilePath = exports.toVirtualFilePath = exports.toVirtualAstroFilePath = exports.isVirtualFilePath = exports.isVirtualTsFilePath = exports.isVirtualSvelteFilePath = exports.isVirtualJsxFilePath = exports.isVirtualVueFilePath = exports.isVirtualAstroFilePath = exports.isFrameworkFilePath = exports.isAstroFilePath = exports.isVirtualFrameworkFilePath = exports.convertToLocationRange = exports.convertRange = exports.getExtensionFromScriptKind = exports.getScriptKindFromFileName = exports.mapSeverity = exports.getCommitCharactersForScriptElement = exports.scriptElementKindToCompletionItemKind = void 0;
23
27
  const ts = __importStar(require("typescript"));
24
28
  const vscode_languageserver_1 = require("vscode-languageserver");
25
29
  const path_1 = require("path");
@@ -175,12 +179,16 @@ function isAstroFilePath(filePath) {
175
179
  return filePath.endsWith('.astro');
176
180
  }
177
181
  exports.isAstroFilePath = isAstroFilePath;
182
+ function isFrameworkFilePath(filePath) {
183
+ return filePath.endsWith('.svelte') || filePath.endsWith('.vue');
184
+ }
185
+ exports.isFrameworkFilePath = isFrameworkFilePath;
178
186
  function isVirtualAstroFilePath(filePath) {
179
187
  return isVirtualFrameworkFilePath('astro', VirtualExtension.tsx, filePath);
180
188
  }
181
189
  exports.isVirtualAstroFilePath = isVirtualAstroFilePath;
182
190
  function isVirtualVueFilePath(filePath) {
183
- return isVirtualFrameworkFilePath('vue', VirtualExtension.ts, filePath);
191
+ return isVirtualFrameworkFilePath('vue', VirtualExtension.tsx, filePath);
184
192
  }
185
193
  exports.isVirtualVueFilePath = isVirtualVueFilePath;
186
194
  function isVirtualJsxFilePath(filePath) {
@@ -188,11 +196,15 @@ function isVirtualJsxFilePath(filePath) {
188
196
  }
189
197
  exports.isVirtualJsxFilePath = isVirtualJsxFilePath;
190
198
  function isVirtualSvelteFilePath(filePath) {
191
- return isVirtualFrameworkFilePath('svelte', VirtualExtension.ts, filePath);
199
+ return isVirtualFrameworkFilePath('svelte', VirtualExtension.tsx, filePath);
192
200
  }
193
201
  exports.isVirtualSvelteFilePath = isVirtualSvelteFilePath;
202
+ function isVirtualTsFilePath(filePath) {
203
+ return isVirtualFrameworkFilePath('ts', VirtualExtension.tsx, filePath);
204
+ }
205
+ exports.isVirtualTsFilePath = isVirtualTsFilePath;
194
206
  function isVirtualFilePath(filePath) {
195
- return isVirtualAstroFilePath(filePath) || isVirtualVueFilePath(filePath) || isVirtualSvelteFilePath(filePath) || isVirtualJsxFilePath(filePath);
207
+ return isVirtualAstroFilePath(filePath) || isVirtualVueFilePath(filePath) || isVirtualSvelteFilePath(filePath) || isVirtualJsxFilePath(filePath) || isVirtualTsFilePath(filePath);
196
208
  }
197
209
  exports.isVirtualFilePath = isVirtualFilePath;
198
210
  function toVirtualAstroFilePath(filePath) {
@@ -207,6 +219,18 @@ function toVirtualAstroFilePath(filePath) {
207
219
  }
208
220
  }
209
221
  exports.toVirtualAstroFilePath = toVirtualAstroFilePath;
222
+ function toVirtualFilePath(filePath) {
223
+ if (isVirtualFilePath(filePath)) {
224
+ return filePath;
225
+ }
226
+ else if (isFrameworkFilePath(filePath) || isAstroFilePath(filePath) || filePath.endsWith('.ts')) {
227
+ return `${filePath}.tsx`;
228
+ }
229
+ else {
230
+ return filePath;
231
+ }
232
+ }
233
+ exports.toVirtualFilePath = toVirtualFilePath;
210
234
  function toRealAstroFilePath(filePath) {
211
235
  return filePath.slice(0, -'.tsx'.length);
212
236
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "0.9.3",
3
+ "version": "0.11.0",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -10,7 +10,6 @@
10
10
  },
11
11
  "files": [
12
12
  "dist",
13
- "astro.d.ts",
14
13
  "bin",
15
14
  "types"
16
15
  ],
@@ -20,6 +19,7 @@
20
19
  "test": "tap --no-coverage test/**"
21
20
  },
22
21
  "dependencies": {
22
+ "@astrojs/svelte-language-integration": "^0.1.0",
23
23
  "lodash": "^4.17.21",
24
24
  "source-map": "^0.7.3",
25
25
  "ts-morph": "^12.0.0",