@astrojs/language-server 0.20.1 → 0.21.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.
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createFromFrameworkFilePath = exports.createFromAstroFilePath = exports.createFromTSFilePath = exports.createFromNonAstroFilePath = exports.createFromFilePath = exports.createFromDocument = void 0;
6
+ exports.classNameFromFilename = exports.createFromFrameworkFilePath = exports.createFromAstroFilePath = exports.createFromTSFilePath = exports.createFromNonAstroFilePath = exports.createFromFilePath = exports.createFromDocument = void 0;
7
7
  const typescript_1 = __importDefault(require("typescript"));
8
8
  const astro2tsx_1 = __importDefault(require("../astro2tsx"));
9
9
  const vscode_uri_1 = require("vscode-uri");
@@ -106,3 +106,4 @@ function classNameFromFilename(filename) {
106
106
  const finalName = firstValidCharIdx === -1 ? `A${inPascalCase}` : inPascalCase;
107
107
  return finalName;
108
108
  }
109
+ exports.classNameFromFilename = classNameFromFilename;
package/dist/server.js CHANGED
@@ -37,6 +37,7 @@ const plugins_1 = require("./plugins");
37
37
  const utils_1 = require("./utils");
38
38
  const utils_2 = require("./plugins/typescript/utils");
39
39
  const CodeActionsProvider_1 = require("./plugins/typescript/features/CodeActionsProvider");
40
+ const LanguageServiceManager_1 = require("./plugins/typescript/LanguageServiceManager");
40
41
  const TagCloseRequest = new vscode.RequestType('html/tag');
41
42
  // Start the language server
42
43
  function startLanguageServer(connection) {
@@ -44,6 +45,7 @@ function startLanguageServer(connection) {
44
45
  const documentManager = new DocumentManager_1.DocumentManager();
45
46
  const pluginHost = new PluginHost_1.PluginHost(documentManager);
46
47
  const configManager = new ConfigManager_1.ConfigManager(connection);
48
+ let typescriptPlugin = undefined;
47
49
  let hasConfigurationCapability = false;
48
50
  connection.onInitialize((params) => {
49
51
  const workspaceUris = params.workspaceFolders?.map((folder) => folder.uri.toString()) ?? [params.rootUri ?? ''];
@@ -54,8 +56,8 @@ function startLanguageServer(connection) {
54
56
  if (!(0, utils_1.isAstroWorkspace)(uri) && uri !== '/' && uri !== '') {
55
57
  return;
56
58
  }
57
- const astroVersion = (0, utils_1.getUserAstroVersion)(uri);
58
- if (astroVersion.exist === false) {
59
+ const astroInstall = (0, utils_1.getAstroInstall)([uri]);
60
+ if (!astroInstall) {
59
61
  connection.sendNotification(vscode_languageserver_1.ShowMessageNotification.type, {
60
62
  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`,
61
63
  type: vscode_languageserver_1.MessageType.Warning,
@@ -72,8 +74,10 @@ function startLanguageServer(connection) {
72
74
  pluginHost.registerPlugin(new CSSPlugin_1.CSSPlugin(configManager));
73
75
  // We don't currently support running the TypeScript and Astro plugin in the browser
74
76
  if (params.initializationOptions.environment !== 'browser') {
75
- pluginHost.registerPlugin(new AstroPlugin_1.AstroPlugin(documentManager, configManager, workspaceUris));
76
- pluginHost.registerPlugin(new plugins_1.TypeScriptPlugin(documentManager, configManager, workspaceUris));
77
+ const languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(documentManager, workspaceUris.map(utils_1.normalizeUri), configManager);
78
+ typescriptPlugin = new plugins_1.TypeScriptPlugin(configManager, languageServiceManager);
79
+ pluginHost.registerPlugin(new AstroPlugin_1.AstroPlugin(configManager, languageServiceManager));
80
+ pluginHost.registerPlugin(typescriptPlugin);
77
81
  }
78
82
  return {
79
83
  capabilities: {
@@ -212,6 +216,16 @@ function startLanguageServer(connection) {
212
216
  }
213
217
  updateAllDiagnostics();
214
218
  });
219
+ connection.onRequest('$/getTSXOutput', async (uri) => {
220
+ const doc = documentManager.get(uri);
221
+ if (!doc) {
222
+ return undefined;
223
+ }
224
+ if (doc) {
225
+ const tsxOutput = typescriptPlugin.getTSXForDocument(doc);
226
+ return tsxOutput.code;
227
+ }
228
+ });
215
229
  documentManager.on('documentChange', (0, utils_1.debounceThrottle)(async (document) => diagnosticsManager.update(document), 1000));
216
230
  documentManager.on('documentClose', (document) => {
217
231
  diagnosticsManager.removeDiagnostics(document);
package/dist/utils.d.ts CHANGED
@@ -69,11 +69,13 @@ export declare function debounceThrottle<T extends (...args: any) => void>(fn: T
69
69
  * Try to determine if a workspace could be an Astro project based on the content of `package.json`
70
70
  */
71
71
  export declare function isAstroWorkspace(workspacePath: string): boolean;
72
- export interface AstroVersion {
73
- full: string;
74
- major: number;
75
- minor: number;
76
- patch: number;
77
- exist: boolean;
72
+ export interface AstroInstall {
73
+ path: string;
74
+ version: {
75
+ full: string;
76
+ major: number;
77
+ minor: number;
78
+ patch: number;
79
+ };
78
80
  }
79
- export declare function getUserAstroVersion(basePath: string): AstroVersion;
81
+ export declare function getAstroInstall(basePaths: string[]): AstroInstall | undefined;
package/dist/utils.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUserAstroVersion = exports.isAstroWorkspace = exports.debounceThrottle = exports.debounceSameArg = exports.getRegExpMatches = exports.regexLastIndexOf = exports.isBeforeOrEqualToPosition = exports.isInRange = exports.isNotNullOrUndefined = exports.clamp = exports.modifyLines = exports.toPascalCase = exports.mergeDeep = exports.get = exports.getLastPartOfPath = exports.pathToUrl = exports.urlToPath = exports.normalizePath = exports.normalizeUri = void 0;
3
+ exports.getAstroInstall = exports.isAstroWorkspace = exports.debounceThrottle = exports.debounceSameArg = exports.getRegExpMatches = exports.regexLastIndexOf = exports.isBeforeOrEqualToPosition = exports.isInRange = exports.isNotNullOrUndefined = exports.clamp = exports.modifyLines = exports.toPascalCase = exports.mergeDeep = exports.get = exports.getLastPartOfPath = exports.pathToUrl = exports.urlToPath = exports.normalizePath = exports.normalizeUri = void 0;
4
4
  const vscode_uri_1 = require("vscode-uri");
5
+ const importPackage_1 = require("./importPackage");
5
6
  /** Normalizes a document URI */
6
7
  function normalizeUri(uri) {
7
8
  return vscode_uri_1.URI.parse(uri).toString();
@@ -214,23 +215,29 @@ function isAstroWorkspace(workspacePath) {
214
215
  return false;
215
216
  }
216
217
  exports.isAstroWorkspace = isAstroWorkspace;
217
- function getUserAstroVersion(basePath) {
218
- let version = '0.0.0';
219
- let exist = true;
218
+ function getAstroInstall(basePaths) {
219
+ let path;
220
+ let version;
220
221
  try {
221
- const astroPackageJson = require.resolve('astro/package.json', { paths: [basePath] });
222
- version = require(astroPackageJson).version;
222
+ path = (0, importPackage_1.getPackagePath)('astro', basePaths);
223
+ if (!path) {
224
+ throw Error;
225
+ }
226
+ version = require(path + '/package.json').version;
223
227
  }
224
228
  catch {
225
229
  // If we couldn't find it inside the workspace's node_modules, it might means we're in the monorepo
226
230
  try {
227
- const monorepoPackageJson = require.resolve('./packages/astro/package.json', { paths: [basePath] });
228
- version = require(monorepoPackageJson).version;
231
+ path = (0, importPackage_1.getPackagePath)('./packages/astro', basePaths);
232
+ if (!path) {
233
+ throw Error;
234
+ }
235
+ version = require(path + '/package.json').version;
229
236
  }
230
237
  catch (e) {
231
238
  // If we still couldn't find it, it probably just doesn't exist
232
- exist = false;
233
- console.error(`${basePath} seems to be an Astro project, but we couldn't find Astro or Astro is not installed`);
239
+ console.error(`${basePaths[0]} seems to be an Astro project, but we couldn't find Astro or Astro is not installed`);
240
+ return undefined;
234
241
  }
235
242
  }
236
243
  let [major, minor, patch] = version.split('.');
@@ -239,11 +246,13 @@ function getUserAstroVersion(basePath) {
239
246
  patch = patchParts[0];
240
247
  }
241
248
  return {
242
- full: version,
243
- major: Number(major),
244
- minor: Number(minor),
245
- patch: Number(patch),
246
- exist,
249
+ path,
250
+ version: {
251
+ full: version,
252
+ major: Number(major),
253
+ minor: Number(minor),
254
+ patch: Number(patch),
255
+ },
247
256
  };
248
257
  }
249
- exports.getUserAstroVersion = getUserAstroVersion;
258
+ exports.getAstroInstall = getAstroInstall;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "0.20.1",
3
+ "version": "0.21.1",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -31,8 +31,8 @@
31
31
  "vscode-uri": "^3.0.3"
32
32
  },
33
33
  "devDependencies": {
34
- "@astrojs/svelte": "^0.2.1",
35
- "@astrojs/vue": "^0.2.1",
34
+ "@astrojs/svelte": "^0.5.0",
35
+ "@astrojs/vue": "^0.5.0",
36
36
  "@types/chai": "^4.3.0",
37
37
  "@types/mocha": "^9.1.0",
38
38
  "@types/sinon": "^10.0.11",
@@ -0,0 +1,5 @@
1
+ # Types
2
+
3
+ **Heads up!** `env.d.ts` and `astro-jsx.d.ts` in this folder are only used as fallback by the language server whenever we're not able to load the real types from the user's project. The types here should be in line with the types from Astro, but only loosely as not being able to load the real types from the user's project is an uncommon situation and some things are not necessarily possible without relying on Astro's internals
4
+
5
+ As such, if you're making a PR to fix/improve something related to types, you should probably make a PR to [Astro itself](https://github.com/withastro/astro), not this project!