@astrojs/language-server 0.13.4 → 0.14.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,16 @@
1
1
  # @astrojs/language-server
2
2
 
3
+ ## 0.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9118c46: Add support for loading type definitions from Astro itself
8
+
9
+ ### Patch Changes
10
+
11
+ - 9ea5b97: Make TypeScript ignore content of Markdown tags
12
+ - dbf624a: Fix error when returning a response from the frontmatter
13
+
3
14
  ## 0.13.4
4
15
 
5
16
  ### Patch Changes
@@ -38,9 +38,13 @@ function default_1(content) {
38
38
  .replace(/<\s*!--([^-->]*)(.*?)-->/gs, (whole) => {
39
39
  return `{/*${whole}*/}`;
40
40
  })
41
- // Turn styles into internal strings
41
+ // Turn styles tags into internal strings
42
42
  .replace(/<\s*style([^>]*)>(.*?)<\s*\/\s*style>/gs, (_whole, attrs, children) => {
43
43
  return `<style${attrs}>{\`${escapeTemplateLiteralContent(children)}\`}</style>`;
44
+ })
45
+ // Turn Markdown tags into internal strings
46
+ .replace(/<\s*Markdown([^>]*)>(.*?)<\s*\/\s*Markdown>/gs, (_whole, attrs, children) => {
47
+ return `<Markdown${attrs}>{\`${escapeTemplateLiteralContent(children)}\`}</Markdown>`;
44
48
  })
45
49
  // Turn scripts into function calls
46
50
  .replace(/<\s*script([^\/>]*)>(.*?)<\s*\/\s*script>/gs, (_whole, attrs, children, offset) => {
@@ -13,7 +13,7 @@ class DiagnosticsProviderImpl {
13
13
  this.languageServiceManager = languageServiceManager;
14
14
  }
15
15
  async getDiagnostics(document, _cancellationToken) {
16
- var _a, _b, _c;
16
+ var _a, _b;
17
17
  // Don't return diagnostics for files inside node_modules. These are considered read-only
18
18
  // and they would pollute the output for astro check
19
19
  if (((_a = document.getFilePath()) === null || _a === void 0 ? void 0 : _a.includes('/node_modules/')) || ((_b = document.getFilePath()) === null || _b === void 0 ? void 0 : _b.includes('\\node_modules\\'))) {
@@ -21,16 +21,14 @@ class DiagnosticsProviderImpl {
21
21
  }
22
22
  const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
23
23
  const filePath = (0, utils_1.toVirtualAstroFilePath)(tsDoc.filePath);
24
- const { script: scriptBoundaries, markdown: markdownBoundaries } = this.getTagBoundaries(lang, filePath);
24
+ const { script: scriptBoundaries } = this.getTagBoundaries(lang, filePath);
25
25
  const syntaxDiagnostics = lang.getSyntacticDiagnostics(filePath);
26
26
  const suggestionDiagnostics = lang.getSuggestionDiagnostics(filePath);
27
27
  const semanticDiagnostics = lang.getSemanticDiagnostics(filePath).filter((d) => {
28
- return isNoWithinScript(scriptBoundaries, d);
28
+ return isNoWithinBoundary(scriptBoundaries, d);
29
29
  });
30
30
  const diagnostics = [...syntaxDiagnostics, ...suggestionDiagnostics, ...semanticDiagnostics];
31
31
  const fragment = await tsDoc.createFragment();
32
- const sourceFile = (_c = lang.getProgram()) === null || _c === void 0 ? void 0 : _c.getSourceFile(filePath);
33
- const isNoFalsePositiveInst = isNoFalsePositive();
34
32
  return diagnostics
35
33
  .map((diagnostic) => ({
36
34
  range: (0, utils_1.convertRange)(tsDoc, diagnostic),
@@ -43,14 +41,13 @@ class DiagnosticsProviderImpl {
43
41
  .map(mapRange(fragment, document))
44
42
  .filter((diag) => {
45
43
  return (hasNoNegativeLines(diag) &&
46
- isNoFalsePositiveInst(diag) &&
47
44
  isNoJSXImplicitRuntimeWarning(diag) &&
48
45
  isNoJSXMustHaveOneParent(diag) &&
49
- isNoCantUseJSX(diag) &&
50
46
  isNoCantEndWithTS(diag) &&
51
47
  isNoSpreadExpected(diag) &&
52
48
  isNoCantResolveJSONModule(diag) &&
53
- isNoMarkdownBlockQuoteWithinMarkdown(sourceFile, markdownBoundaries, diag));
49
+ isNoCantReturnOutsideFunction(diag) &&
50
+ isNoJsxCannotHaveMultipleAttrsError(diag));
54
51
  })
55
52
  .map(enhanceIfNecessary);
56
53
  }
@@ -64,7 +61,7 @@ class DiagnosticsProviderImpl {
64
61
  if (!sourceFile) {
65
62
  return boundaries;
66
63
  }
67
- function findScript(parent) {
64
+ function findTags(parent) {
68
65
  typescript_1.default.forEachChild(parent, (node) => {
69
66
  if (typescript_1.default.isJsxElement(node)) {
70
67
  let tagName = node.openingElement.tagName.getText();
@@ -80,10 +77,10 @@ class DiagnosticsProviderImpl {
80
77
  }
81
78
  }
82
79
  }
83
- findScript(node);
80
+ findTags(node);
84
81
  });
85
82
  }
86
- findScript(sourceFile);
83
+ findTags(sourceFile);
87
84
  return boundaries;
88
85
  }
89
86
  }
@@ -116,33 +113,55 @@ function mapRange(fragment, _document) {
116
113
  function hasNoNegativeLines(diagnostic) {
117
114
  return diagnostic.range.start.line >= 0 && diagnostic.range.end.line >= 0;
118
115
  }
119
- function isNoFalsePositive() {
120
- return (diagnostic) => {
121
- return isNoJsxCannotHaveMultipleAttrsError(diagnostic);
122
- };
123
- }
124
116
  /**
125
- * Jsx cannot have multiple attributes with same name,
126
- * but that's allowed for svelte
117
+ * Astro allows multiple attributes to have the same name
127
118
  */
128
119
  function isNoJsxCannotHaveMultipleAttrsError(diagnostic) {
129
120
  return diagnostic.code !== 17001;
130
121
  }
131
- function isNoJSXImplicitRuntimeWarning(diagnostic) {
132
- return diagnostic.code !== 7016 && diagnostic.code !== 2792;
133
- }
122
+ /** Astro allows component with multiple root elements */
134
123
  function isNoJSXMustHaveOneParent(diagnostic) {
135
124
  return diagnostic.code !== 2657;
136
125
  }
137
- function isNoCantUseJSX(diagnostic) {
138
- return diagnostic.code !== 17004 && diagnostic.code !== 6142;
139
- }
126
+ /** Astro allows `.ts` ending for imports, unlike TypeScript */
140
127
  function isNoCantEndWithTS(diagnostic) {
141
128
  return diagnostic.code !== 2691;
142
129
  }
143
130
  function isNoSpreadExpected(diagnostic) {
144
131
  return diagnostic.code !== 1005;
145
132
  }
133
+ function isNoJSXImplicitRuntimeWarning(diagnostic) {
134
+ return diagnostic.code !== 7016 && diagnostic.code !== 2792;
135
+ }
136
+ /**
137
+ * Ignore "Can't return outside of function body"
138
+ * This is technically a valid diagnostic, but due to how we format our TSX, the frontmatter is at top-level so we have
139
+ * to ignore this. It wasn't a problem before because users didn't need to return things but they can now with SSR
140
+ */
141
+ function isNoCantReturnOutsideFunction(diagnostic) {
142
+ return diagnostic.code !== 1108;
143
+ }
144
+ /**
145
+ * Astro allows users to import JSON modules
146
+ */
147
+ function isNoCantResolveJSONModule(diagnostic) {
148
+ return diagnostic.code !== 2732;
149
+ }
150
+ /**
151
+ * Some diagnostics have JSX-specific nomenclature or unclear description. Enhance them for more clarity.
152
+ */
153
+ function enhanceIfNecessary(diagnostic) {
154
+ if (diagnostic.code === 2322) {
155
+ // For the rare case where an user might try to put a client directive on something that is not a component
156
+ if (diagnostic.message.includes("Property 'client:") && diagnostic.message.includes("to type 'HTMLProps")) {
157
+ return {
158
+ ...diagnostic,
159
+ message: 'Client directives are only available on framework components',
160
+ };
161
+ }
162
+ }
163
+ return diagnostic;
164
+ }
146
165
  function isWithinBoundaries(boundaries, start) {
147
166
  for (let [bstart, bend] of boundaries) {
148
167
  if (start > bstart && start < bend) {
@@ -163,39 +182,6 @@ function diagnosticIsWithinBoundaries(sourceFile, boundaries, diagnostic) {
163
182
  let pos = typescript_1.default.getPositionOfLineAndCharacter(sourceFile, startRange.line, startRange.character);
164
183
  return isWithinBoundaries(boundaries, pos);
165
184
  }
166
- function isNoWithinScript(boundaries, diagnostic) {
185
+ function isNoWithinBoundary(boundaries, diagnostic) {
167
186
  return !diagnosticIsWithinBoundaries(undefined, boundaries, diagnostic);
168
187
  }
169
- /**
170
- * This allows us to have JSON module imports.
171
- */
172
- function isNoCantResolveJSONModule(diagnostic) {
173
- return diagnostic.code !== 2732;
174
- }
175
- /**
176
- * This is for using > within a markdown component like:
177
- * <Markdown>
178
- * > Blockquote here.
179
- * </Markdown>
180
- */
181
- function isNoMarkdownBlockQuoteWithinMarkdown(sourceFile, boundaries, diagnostic) {
182
- if (diagnostic.code !== 1382) {
183
- return true;
184
- }
185
- return !diagnosticIsWithinBoundaries(sourceFile, boundaries, diagnostic);
186
- }
187
- /**
188
- * Some diagnostics have JSX-specific nomenclature. Enhance them for more clarity.
189
- */
190
- function enhanceIfNecessary(diagnostic) {
191
- if (diagnostic.code === 2322) {
192
- // For the rare case where an user might try to put a client directive on something that is not a component
193
- if (diagnostic.message.includes("Property 'client:") && diagnostic.message.includes("to type 'HTMLProps")) {
194
- return {
195
- ...diagnostic,
196
- message: 'Client directives are only available on framework components',
197
- };
198
- }
199
- }
200
- return diagnostic;
201
- }
@@ -35,4 +35,4 @@ export declare function forAllLanguageServices(cb: (service: LanguageServiceCont
35
35
  * @param tsconfigPath has to be absolute
36
36
  * @param docContext
37
37
  */
38
- export declare function getLanguageServiceForTsconfig(tsconfigPath: string, docContext: LanguageServiceDocumentContext): Promise<LanguageServiceContainer>;
38
+ export declare function getLanguageServiceForTsconfig(tsconfigPath: string, docContext: LanguageServiceDocumentContext, workspaceUris: string[]): Promise<LanguageServiceContainer>;
@@ -37,7 +37,7 @@ const DocumentSnapshotUtils = __importStar(require("./snapshots/utils"));
37
37
  const services = new Map();
38
38
  async function getLanguageService(path, workspaceUris, docContext) {
39
39
  const tsconfigPath = (0, utils_2.findTsConfigPath)(path, workspaceUris);
40
- return getLanguageServiceForTsconfig(tsconfigPath, docContext);
40
+ return getLanguageServiceForTsconfig(tsconfigPath, docContext, workspaceUris);
41
41
  }
42
42
  exports.getLanguageService = getLanguageService;
43
43
  async function forAllLanguageServices(cb) {
@@ -50,34 +50,44 @@ exports.forAllLanguageServices = forAllLanguageServices;
50
50
  * @param tsconfigPath has to be absolute
51
51
  * @param docContext
52
52
  */
53
- async function getLanguageServiceForTsconfig(tsconfigPath, docContext) {
53
+ async function getLanguageServiceForTsconfig(tsconfigPath, docContext, workspaceUris) {
54
54
  let service;
55
55
  if (services.has(tsconfigPath)) {
56
56
  service = await services.get(tsconfigPath);
57
57
  }
58
58
  else {
59
- const newService = createLanguageService(tsconfigPath, docContext);
59
+ const newService = createLanguageService(tsconfigPath, docContext, workspaceUris);
60
60
  services.set(tsconfigPath, newService);
61
61
  service = await newService;
62
62
  }
63
63
  return service;
64
64
  }
65
65
  exports.getLanguageServiceForTsconfig = getLanguageServiceForTsconfig;
66
- async function createLanguageService(tsconfigPath, docContext) {
67
- const workspaceRoot = tsconfigPath ? (0, path_1.dirname)(tsconfigPath) : '';
66
+ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
67
+ const tsconfigRoot = tsconfigPath ? (0, path_1.dirname)(tsconfigPath) : process.cwd();
68
+ const workspacePaths = workspaceUris.map((uri) => (0, utils_1.urlToPath)(uri));
69
+ const workspacePath = workspacePaths.find((uri) => tsconfigRoot.startsWith(uri)) || workspacePaths[0];
70
+ const astroVersion = (0, utils_1.getUserAstroVersion)(workspacePath);
68
71
  // `raw` here represent the tsconfig merged with any extended config
69
72
  const { compilerOptions, fileNames: files, raw: fullConfig } = getParsedTSConfig();
70
73
  let projectVersion = 0;
71
- const snapshotManager = new SnapshotManager_1.SnapshotManager(docContext.globalSnapshotManager, files, fullConfig, workspaceRoot || process.cwd());
74
+ const snapshotManager = new SnapshotManager_1.SnapshotManager(docContext.globalSnapshotManager, files, fullConfig, tsconfigRoot || process.cwd());
72
75
  const astroModuleLoader = (0, module_loader_1.createAstroModuleLoader)(getScriptSnapshot, compilerOptions);
73
- let languageServerDirectory;
74
- try {
75
- languageServerDirectory = (0, path_1.dirname)(require.resolve('@astrojs/language-server'));
76
- }
77
- catch (e) {
78
- languageServerDirectory = __dirname;
76
+ const scriptFileNames = [];
77
+ // Before Astro 1.0, JSX definitions were inside of the language-server instead of inside Astro
78
+ // TODO: Remove this and astro-jsx.d.ts in types when we consider having support for Astro < 1.0 unnecessary
79
+ if (astroVersion.major === 0 || astroVersion.full === '1.0.0-beta.0') {
80
+ let languageServerDirectory;
81
+ try {
82
+ languageServerDirectory = (0, path_1.dirname)(require.resolve('@astrojs/language-server'));
83
+ }
84
+ catch (e) {
85
+ languageServerDirectory = __dirname;
86
+ }
87
+ const astroTSXFile = typescript_1.default.sys.resolvePath((0, path_1.resolve)(languageServerDirectory, '../types/astro-jsx.d.ts'));
88
+ scriptFileNames.push(astroTSXFile);
89
+ console.warn("Version lower than 1.0 detected, using internal types instead of Astro's");
79
90
  }
80
- const astroTSXFile = typescript_1.default.sys.resolvePath((0, path_1.resolve)(languageServerDirectory, '../types/astro-jsx.d.ts'));
81
91
  const host = {
82
92
  getNewLine: () => typescript_1.default.sys.newLine,
83
93
  useCaseSensitiveFileNames: () => typescript_1.default.sys.useCaseSensitiveFileNames,
@@ -87,10 +97,10 @@ async function createLanguageService(tsconfigPath, docContext) {
87
97
  fileExists: astroModuleLoader.fileExists,
88
98
  readDirectory: astroModuleLoader.readDirectory,
89
99
  getCompilationSettings: () => compilerOptions,
90
- getCurrentDirectory: () => workspaceRoot,
100
+ getCurrentDirectory: () => tsconfigRoot,
91
101
  getDefaultLibFileName: typescript_1.default.getDefaultLibFilePath,
92
102
  getProjectVersion: () => projectVersion.toString(),
93
- getScriptFileNames: () => Array.from(new Set([...snapshotManager.getProjectFileNames(), ...snapshotManager.getFileNames(), astroTSXFile])),
103
+ getScriptFileNames: () => Array.from(new Set([...snapshotManager.getProjectFileNames(), ...snapshotManager.getFileNames(), ...scriptFileNames])),
94
104
  getScriptSnapshot,
95
105
  getScriptVersion: (fileName) => getScriptSnapshot(fileName).version.toString(),
96
106
  };
@@ -176,17 +186,24 @@ async function createLanguageService(tsconfigPath, docContext) {
176
186
  snapshotManager.updateNonAstroFile(fileName, changes);
177
187
  }
178
188
  function getParsedTSConfig() {
179
- var _a, _b, _c;
189
+ var _a, _b, _c, _d;
180
190
  let configJson = (tsconfigPath && typescript_1.default.readConfigFile(tsconfigPath, typescript_1.default.sys.readFile).config) || {};
181
191
  // If our user has types in their config but it doesn't include the types needed for Astro, add them to the config
182
- if (((_a = configJson.compilerOptions) === null || _a === void 0 ? void 0 : _a.types) && !((_b = configJson.compilerOptions) === null || _b === void 0 ? void 0 : _b.types.includes('astro/env'))) {
183
- configJson.compilerOptions.types.push('astro/env');
192
+ if ((_a = configJson.compilerOptions) === null || _a === void 0 ? void 0 : _a.types) {
193
+ if (!((_b = configJson.compilerOptions) === null || _b === void 0 ? void 0 : _b.types.includes('astro/env'))) {
194
+ configJson.compilerOptions.types.push('astro/env');
195
+ }
196
+ if (astroVersion.major >= 1 &&
197
+ astroVersion.full !== '1.0.0-beta.0' &&
198
+ !((_c = configJson.compilerOptions) === null || _c === void 0 ? void 0 : _c.types.includes('astro/astro-jsx'))) {
199
+ configJson.compilerOptions.types.push('astro/astro-jsx');
200
+ }
184
201
  }
185
- configJson.compilerOptions = Object.assign(getDefaultCompilerOptions(), configJson.compilerOptions);
202
+ configJson.compilerOptions = Object.assign(getDefaultCompilerOptions(astroVersion), configJson.compilerOptions);
186
203
  // Delete include so that .astro files don't get mistakenly excluded by the user
187
204
  delete configJson.include;
188
205
  // If the user supplied exclude, let's use theirs otherwise, use ours
189
- (_c = configJson.exclude) !== null && _c !== void 0 ? _c : (configJson.exclude = getDefaultExclude());
206
+ (_d = configJson.exclude) !== null && _d !== void 0 ? _d : (configJson.exclude = getDefaultExclude());
190
207
  // Everything here will always, unconditionally, be in the resulting config
191
208
  const forcedCompilerOptions = {
192
209
  noEmit: true,
@@ -200,7 +217,7 @@ async function createLanguageService(tsconfigPath, docContext) {
200
217
  target: typescript_1.default.ScriptTarget.ESNext,
201
218
  moduleResolution: typescript_1.default.ModuleResolutionKind.NodeJs,
202
219
  };
203
- const project = typescript_1.default.parseJsonConfigFileContent(configJson, typescript_1.default.sys, workspaceRoot, forcedCompilerOptions, tsconfigPath, undefined, [
220
+ const project = typescript_1.default.parseJsonConfigFileContent(configJson, typescript_1.default.sys, tsconfigRoot, forcedCompilerOptions, tsconfigPath, undefined, [
204
221
  { extension: '.vue', isMixedContent: true, scriptKind: typescript_1.default.ScriptKind.Deferred },
205
222
  { extension: '.svelte', isMixedContent: true, scriptKind: typescript_1.default.ScriptKind.Deferred },
206
223
  { extension: '.astro', isMixedContent: true, scriptKind: typescript_1.default.ScriptKind.Deferred },
@@ -218,11 +235,15 @@ async function createLanguageService(tsconfigPath, docContext) {
218
235
  /**
219
236
  * Default configuration used as a base and when the user doesn't have any
220
237
  */
221
- function getDefaultCompilerOptions() {
238
+ function getDefaultCompilerOptions(astroVersion) {
239
+ const types = ['astro/env'];
240
+ if (astroVersion.major >= 1 && astroVersion.full !== '1.0.0-beta.0') {
241
+ types.push('astro/astro-jsx');
242
+ }
222
243
  return {
223
244
  maxNodeModuleJsDepth: 2,
224
245
  allowSyntheticDefaultImports: true,
225
- types: ['astro/env'],
246
+ types: types,
226
247
  };
227
248
  }
228
249
  function getDefaultExclude() {
package/dist/server.js CHANGED
@@ -46,6 +46,22 @@ function startLanguageServer(connection) {
46
46
  connection.onInitialize((params) => {
47
47
  var _a, _b, _c, _d, _e, _f;
48
48
  const workspaceUris = (_b = (_a = params.workspaceFolders) === null || _a === void 0 ? void 0 : _a.map((folder) => folder.uri.toString())) !== null && _b !== void 0 ? _b : [(_c = params.rootUri) !== null && _c !== void 0 ? _c : ''];
49
+ workspaceUris.forEach((uri) => {
50
+ uri = (0, utils_1.urlToPath)(uri);
51
+ const astroVersion = (0, utils_1.getUserAstroVersion)(uri);
52
+ if (astroVersion.exist === false) {
53
+ connection.sendNotification(vscode_languageserver_1.ShowMessageNotification.type, {
54
+ message: `Couldn't find Astro in workspace "${uri}". Experience might be degraded. For the best experience, please make sure Astro is installed and then restart the language server`,
55
+ type: vscode_languageserver_1.MessageType.Warning,
56
+ });
57
+ }
58
+ if (astroVersion.exist && astroVersion.major === 0 && astroVersion.minor < 24 && astroVersion.patch < 5) {
59
+ connection.sendNotification(vscode_languageserver_1.ShowMessageNotification.type, {
60
+ message: `The version of Astro you're using (${astroVersion.full}) is not supported by this version of the Astro language server. Please upgrade Astro to any version higher than 0.23.4 or if using the VS Code extension, downgrade the extension to 0.8.10`,
61
+ type: vscode_languageserver_1.MessageType.Error,
62
+ });
63
+ }
64
+ });
49
65
  pluginHost.initialize({
50
66
  filterIncompleteCompletions: !((_d = params.initializationOptions) === null || _d === void 0 ? void 0 : _d.dontFilterIncompleteCompletions),
51
67
  definitionLinkSupport: !!((_f = (_e = params.capabilities.textDocument) === null || _e === void 0 ? void 0 : _e.definition) === null || _f === void 0 ? void 0 : _f.linkSupport),
package/dist/utils.d.ts CHANGED
@@ -46,3 +46,11 @@ export declare function debounceSameArg<T>(fn: (arg: T) => void, shouldCancelPre
46
46
  * @param milliseconds Number of milliseconds to debounce/throttle
47
47
  */
48
48
  export declare function debounceThrottle<T extends (...args: any) => void>(fn: T, milliseconds: number): T;
49
+ export interface AstroVersion {
50
+ full: string;
51
+ major: number;
52
+ minor: number;
53
+ patch: number;
54
+ exist: boolean;
55
+ }
56
+ export declare function getUserAstroVersion(basePath: string): AstroVersion;
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debounceThrottle = exports.debounceSameArg = exports.isBeforeOrEqualToPosition = exports.isInRange = exports.isNotNullOrUndefined = exports.clamp = exports.flatten = exports.isPossibleComponent = exports.getLastPartOfPath = exports.pathToUrl = exports.urlToPath = exports.normalizePath = exports.normalizeUri = void 0;
3
+ exports.getUserAstroVersion = exports.debounceThrottle = exports.debounceSameArg = exports.isBeforeOrEqualToPosition = exports.isInRange = exports.isNotNullOrUndefined = exports.clamp = exports.flatten = exports.isPossibleComponent = exports.getLastPartOfPath = exports.pathToUrl = exports.urlToPath = exports.normalizePath = exports.normalizeUri = void 0;
4
4
  const vscode_uri_1 = require("vscode-uri");
5
5
  /** Normalizes a document URI */
6
6
  function normalizeUri(uri) {
@@ -117,3 +117,36 @@ function debounceThrottle(fn, milliseconds) {
117
117
  return maybeCall;
118
118
  }
119
119
  exports.debounceThrottle = debounceThrottle;
120
+ function getUserAstroVersion(basePath) {
121
+ let version = '0.0.0';
122
+ let exist = true;
123
+ try {
124
+ const astroPackageJson = require.resolve('astro/package.json', { paths: [basePath] });
125
+ version = require(astroPackageJson).version;
126
+ }
127
+ catch {
128
+ // If we couldn't find it inside the workspace's node_modules, it might means we're in the monorepo
129
+ try {
130
+ const monorepoPackageJson = require.resolve('./packages/astro/package.json', { paths: [basePath] });
131
+ version = require(monorepoPackageJson).version;
132
+ }
133
+ catch (e) {
134
+ // If we still couldn't find it, it probably just doesn't exist
135
+ exist = false;
136
+ console.error(e);
137
+ }
138
+ }
139
+ let [major, minor, patch] = version.split('.');
140
+ if (patch.includes('-')) {
141
+ const patchParts = patch.split('-');
142
+ patch = patchParts[0];
143
+ }
144
+ return {
145
+ full: version,
146
+ major: Number(major),
147
+ minor: Number(minor),
148
+ patch: Number(patch),
149
+ exist,
150
+ };
151
+ }
152
+ exports.getUserAstroVersion = getUserAstroVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "0.13.4",
3
+ "version": "0.14.0",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -37,7 +37,7 @@
37
37
  "@types/lodash": "^4.14.179",
38
38
  "@types/mocha": "^9.1.0",
39
39
  "@types/sinon": "^10.0.11",
40
- "astro": "^0.23.7",
40
+ "astro": "^1.0.0-beta.1",
41
41
  "astro-scripts": "0.0.1",
42
42
  "chai": "^4.3.6",
43
43
  "cross-env": "^7.0.3",