@astrojs/language-server 0.11.0 → 0.13.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.
Files changed (103) hide show
  1. package/CHANGELOG.md +23 -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 +1 -0
  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 +42 -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 +1 -1
  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 +11 -9
  34. package/dist/plugins/PluginHost.js +34 -36
  35. package/dist/plugins/astro/AstroPlugin.d.ts +11 -12
  36. package/dist/plugins/astro/AstroPlugin.js +17 -42
  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 -58
  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 +31 -12
  42. package/dist/plugins/css/CSSPlugin.js +174 -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 +18 -17
  52. package/dist/plugins/html/HTMLPlugin.js +69 -41
  53. package/dist/plugins/html/features/astro-attributes.d.ts +2 -0
  54. package/dist/plugins/html/features/astro-attributes.js +126 -0
  55. package/dist/plugins/index.d.ts +2 -2
  56. package/dist/plugins/index.js +2 -2
  57. package/dist/plugins/interfaces.d.ts +35 -48
  58. package/dist/plugins/typescript/LanguageServiceManager.d.ts +33 -14
  59. package/dist/plugins/typescript/LanguageServiceManager.js +57 -32
  60. package/dist/plugins/typescript/TypeScriptPlugin.d.ts +18 -23
  61. package/dist/plugins/typescript/TypeScriptPlugin.js +58 -55
  62. package/dist/plugins/typescript/astro-sys.d.ts +5 -3
  63. package/dist/plugins/typescript/astro-sys.js +24 -45
  64. package/dist/plugins/typescript/features/CompletionsProvider.d.ts +6 -6
  65. package/dist/plugins/typescript/features/CompletionsProvider.js +18 -38
  66. package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +4 -4
  67. package/dist/plugins/typescript/features/DiagnosticsProvider.js +27 -87
  68. package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +10 -0
  69. package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +69 -0
  70. package/dist/plugins/typescript/features/HoverProvider.d.ts +4 -5
  71. package/dist/plugins/typescript/features/HoverProvider.js +9 -10
  72. package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +4 -5
  73. package/dist/plugins/typescript/features/SignatureHelpProvider.js +15 -11
  74. package/dist/plugins/typescript/features/utils.d.ts +1 -12
  75. package/dist/plugins/typescript/features/utils.js +2 -22
  76. package/dist/plugins/typescript/language-service.d.ts +38 -0
  77. package/dist/plugins/typescript/language-service.js +230 -0
  78. package/dist/plugins/typescript/module-loader.d.ts +5 -8
  79. package/dist/plugins/typescript/module-loader.js +43 -23
  80. package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +90 -0
  81. package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +135 -0
  82. package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +42 -0
  83. package/dist/plugins/typescript/snapshots/SnapshotManager.js +197 -0
  84. package/dist/plugins/typescript/snapshots/utils.d.ts +28 -0
  85. package/dist/plugins/typescript/snapshots/utils.js +84 -0
  86. package/dist/plugins/typescript/utils.d.ts +10 -13
  87. package/dist/plugins/typescript/utils.js +154 -158
  88. package/dist/server.d.ts +2 -4
  89. package/dist/server.js +93 -54
  90. package/dist/utils.d.ts +20 -16
  91. package/dist/utils.js +35 -24
  92. package/package.json +18 -12
  93. package/types/astro-jsx.d.ts +1077 -0
  94. package/bin/server.js +0 -7
  95. package/dist/core/documents/Document.d.ts +0 -51
  96. package/dist/core/documents/Document.js +0 -135
  97. package/dist/plugins/typescript/DocumentSnapshot.d.ts +0 -99
  98. package/dist/plugins/typescript/DocumentSnapshot.js +0 -259
  99. package/dist/plugins/typescript/SnapshotManager.d.ts +0 -24
  100. package/dist/plugins/typescript/SnapshotManager.js +0 -103
  101. package/dist/plugins/typescript/languageService.d.ts +0 -17
  102. package/dist/plugins/typescript/languageService.js +0 -173
  103. package/types/index.d.ts +0 -4
package/dist/server.js CHANGED
@@ -1,42 +1,67 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = 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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startServer = void 0;
4
- const vscode_languageserver_1 = require("vscode-languageserver");
5
- const documents_1 = require("./core/documents");
6
- const config_1 = require("./core/config");
7
- const plugins_1 = require("./plugins");
26
+ exports.startLanguageServer = void 0;
27
+ const vscode = __importStar(require("vscode-languageserver"));
28
+ const ConfigManager_1 = require("./core/config/ConfigManager");
29
+ const DocumentManager_1 = require("./core/documents/DocumentManager");
8
30
  const DiagnosticsManager_1 = require("./core/DiagnosticsManager");
31
+ const AstroPlugin_1 = require("./plugins/astro/AstroPlugin");
32
+ const CSSPlugin_1 = require("./plugins/css/CSSPlugin");
33
+ const HTMLPlugin_1 = require("./plugins/html/HTMLPlugin");
34
+ const PluginHost_1 = require("./plugins/PluginHost");
35
+ const TypeScriptPlugin_1 = require("./plugins/typescript/TypeScriptPlugin");
9
36
  const utils_1 = require("./utils");
10
- const TagCloseRequest = new vscode_languageserver_1.RequestType('html/tag');
11
- /**
12
- * Starts `astro-languageservice`
13
- */
14
- function startServer() {
15
- let connection = (0, vscode_languageserver_1.createConnection)(vscode_languageserver_1.ProposedFeatures.all);
16
- const docManager = documents_1.DocumentManager.newInstance();
17
- const configManager = new config_1.ConfigManager();
18
- const pluginHost = new plugins_1.PluginHost(docManager);
19
- connection.onInitialize((evt) => {
20
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
21
- const workspaceUris = (_b = (_a = evt.workspaceFolders) === null || _a === void 0 ? void 0 : _a.map((folder) => folder.uri.toString())) !== null && _b !== void 0 ? _b : [(_c = evt.rootUri) !== null && _c !== void 0 ? _c : ''];
37
+ const TagCloseRequest = new vscode.RequestType('html/tag');
38
+ // Start the language server
39
+ function startLanguageServer(connection) {
40
+ // Create our managers
41
+ const configManager = new ConfigManager_1.ConfigManager();
42
+ const documentManager = new DocumentManager_1.DocumentManager();
43
+ const pluginHost = new PluginHost_1.PluginHost(documentManager);
44
+ connection.onInitialize((params) => {
45
+ var _a, _b, _c, _d, _e, _f;
46
+ 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 : ''];
22
47
  pluginHost.initialize({
23
- filterIncompleteCompletions: !((_d = evt.initializationOptions) === null || _d === void 0 ? void 0 : _d.dontFilterIncompleteCompletions),
24
- definitionLinkSupport: !!((_f = (_e = evt.capabilities.textDocument) === null || _e === void 0 ? void 0 : _e.definition) === null || _f === void 0 ? void 0 : _f.linkSupport),
48
+ filterIncompleteCompletions: !((_d = params.initializationOptions) === null || _d === void 0 ? void 0 : _d.dontFilterIncompleteCompletions),
49
+ definitionLinkSupport: !!((_f = (_e = params.capabilities.textDocument) === null || _e === void 0 ? void 0 : _e.definition) === null || _f === void 0 ? void 0 : _f.linkSupport),
25
50
  });
26
- pluginHost.register(new plugins_1.HTMLPlugin(docManager, configManager));
27
- pluginHost.register(new plugins_1.CSSPlugin(docManager, configManager));
28
- pluginHost.register(new plugins_1.TypeScriptPlugin(docManager, configManager, workspaceUris));
29
- pluginHost.register(new plugins_1.AstroPlugin(docManager, configManager, workspaceUris));
30
- configManager.update(((_j = (_h = (_g = evt.initializationOptions) === null || _g === void 0 ? void 0 : _g.configuration) === null || _h === void 0 ? void 0 : _h.astro) === null || _j === void 0 ? void 0 : _j.plugin) ||
31
- ((_k = evt.initializationOptions) === null || _k === void 0 ? void 0 : _k.config) ||
32
- {});
33
- configManager.updateTsJsUserPreferences(((_l = evt.initializationOptions) === null || _l === void 0 ? void 0 : _l.configuration) ||
34
- ((_m = evt.initializationOptions) === null || _m === void 0 ? void 0 : _m.typescriptConfig) ||
35
- {});
36
- configManager.updateEmmetConfig(((_p = (_o = evt.initializationOptions) === null || _o === void 0 ? void 0 : _o.configuration) === null || _p === void 0 ? void 0 : _p.emmet) || ((_q = evt.initializationOptions) === null || _q === void 0 ? void 0 : _q.emmetConfig) || {});
51
+ // Register plugins
52
+ pluginHost.registerPlugin(new HTMLPlugin_1.HTMLPlugin(configManager));
53
+ pluginHost.registerPlugin(new CSSPlugin_1.CSSPlugin(configManager));
54
+ // We don't currently support running the TypeScript and Astro plugin in the browser
55
+ if (params.initializationOptions.environment !== 'browser') {
56
+ pluginHost.registerPlugin(new AstroPlugin_1.AstroPlugin(documentManager, configManager, workspaceUris));
57
+ pluginHost.registerPlugin(new TypeScriptPlugin_1.TypeScriptPlugin(documentManager, configManager, workspaceUris));
58
+ }
59
+ // Update language-server config with what the user supplied to us at launch
60
+ configManager.updateConfig(params.initializationOptions.configuration.astro);
61
+ configManager.updateEmmetConfig(params.initializationOptions.configuration.emmet);
37
62
  return {
38
63
  capabilities: {
39
- textDocumentSync: vscode_languageserver_1.TextDocumentSyncKind.Incremental,
64
+ textDocumentSync: vscode.TextDocumentSyncKind.Incremental,
40
65
  foldingRangeProvider: true,
41
66
  definitionProvider: true,
42
67
  renameProvider: true,
@@ -69,7 +94,9 @@ function startServer() {
69
94
  ':',
70
95
  ],
71
96
  },
97
+ colorProvider: true,
72
98
  hoverProvider: true,
99
+ documentSymbolProvider: true,
73
100
  signatureHelpProvider: {
74
101
  triggerCharacters: ['(', ',', '<'],
75
102
  retriggerCharacters: [')'],
@@ -77,17 +104,22 @@ function startServer() {
77
104
  },
78
105
  };
79
106
  });
107
+ // On update of the user configuration of the language-server
108
+ connection.onDidChangeConfiguration(({ settings }) => {
109
+ configManager.updateConfig(settings.astro);
110
+ configManager.updateEmmetConfig(settings.emmet);
111
+ });
80
112
  // Documents
81
- connection.onDidOpenTextDocument((evt) => {
82
- docManager.openDocument(Object.assign({ overrideText: true }, evt.textDocument));
83
- docManager.markAsOpenedInClient(evt.textDocument.uri);
113
+ connection.onDidOpenTextDocument((params) => {
114
+ documentManager.openDocument(params.textDocument);
115
+ documentManager.markAsOpenedInClient(params.textDocument.uri);
84
116
  });
85
- connection.onDidCloseTextDocument((evt) => docManager.closeDocument(evt.textDocument.uri));
86
- const diagnosticsManager = new DiagnosticsManager_1.DiagnosticsManager(connection.sendDiagnostics, docManager, pluginHost.getDiagnostics.bind(pluginHost));
87
- const updateAllDiagnostics = (0, utils_1.debounceThrottle)(() => diagnosticsManager.updateAll(), 1000);
88
- connection.onDidChangeTextDocument((evt) => {
89
- docManager.updateDocument(evt.textDocument.uri, evt.contentChanges);
117
+ connection.onDidCloseTextDocument((params) => documentManager.closeDocument(params.textDocument.uri));
118
+ connection.onDidChangeTextDocument((params) => {
119
+ documentManager.updateDocument(params.textDocument, params.contentChanges);
90
120
  });
121
+ const diagnosticsManager = new DiagnosticsManager_1.DiagnosticsManager(connection.sendDiagnostics, documentManager, pluginHost.getDiagnostics.bind(pluginHost));
122
+ const updateAllDiagnostics = (0, utils_1.debounceThrottle)(() => diagnosticsManager.updateAll(), 1000);
91
123
  connection.onDidChangeWatchedFiles((evt) => {
92
124
  const params = evt.changes
93
125
  .map((change) => ({
@@ -98,15 +130,10 @@ function startServer() {
98
130
  pluginHost.onWatchFileChanges(params);
99
131
  updateAllDiagnostics();
100
132
  });
101
- //connection.onDidChangeTextDocument(updateAllDiagnostics);
102
- // Config
103
- connection.onDidChangeConfiguration(({ settings }) => {
104
- var _a;
105
- configManager.update((_a = settings.astro) === null || _a === void 0 ? void 0 : _a.plugin);
106
- configManager.updateEmmetConfig(settings.emmet);
107
- configManager.updateTsJsUserPreferences(settings);
108
- });
109
133
  // Features
134
+ connection.onHover((params) => pluginHost.doHover(params.textDocument, params.position));
135
+ connection.onDefinition((evt) => pluginHost.getDefinitions(evt.textDocument, evt.position));
136
+ connection.onFoldingRanges((evt) => pluginHost.getFoldingRanges(evt.textDocument));
110
137
  connection.onCompletion(async (evt) => {
111
138
  const promise = pluginHost.getCompletions(evt.textDocument, evt.position, evt.context);
112
139
  return promise;
@@ -118,14 +145,26 @@ function startServer() {
118
145
  }
119
146
  return pluginHost.resolveCompletion(data, completionItem);
120
147
  });
121
- connection.onHover((evt) => pluginHost.doHover(evt.textDocument, evt.position));
122
- connection.onDefinition((evt) => pluginHost.getDefinitions(evt.textDocument, evt.position));
123
- connection.onFoldingRanges((evt) => pluginHost.getFoldingRanges(evt.textDocument));
148
+ connection.onDocumentSymbol((params, cancellationToken) => pluginHost.getDocumentSymbols(params.textDocument, cancellationToken));
149
+ connection.onDocumentColor((params) => pluginHost.getDocumentColors(params.textDocument));
150
+ connection.onColorPresentation((params) => pluginHost.getColorPresentations(params.textDocument, params.range, params.color));
124
151
  connection.onRequest(TagCloseRequest, (evt) => pluginHost.doTagComplete(evt.textDocument, evt.position));
125
152
  connection.onSignatureHelp((evt, cancellationToken) => pluginHost.getSignatureHelp(evt.textDocument, evt.position, evt.context, cancellationToken));
126
- connection.onRenameRequest(evt => pluginHost.rename(evt.textDocument, evt.position, evt.newName));
127
- docManager.on('documentChange', (0, utils_1.debounceThrottle)(async (document) => diagnosticsManager.update(document), 1000));
128
- docManager.on('documentClose', (document) => diagnosticsManager.removeDiagnostics(document));
153
+ connection.onRenameRequest((evt) => pluginHost.rename(evt.textDocument, evt.position, evt.newName));
154
+ connection.onDidSaveTextDocument(updateAllDiagnostics);
155
+ connection.onNotification('$/onDidChangeNonAstroFile', async (e) => {
156
+ const path = (0, utils_1.urlToPath)(e.uri);
157
+ if (path) {
158
+ pluginHost.updateNonAstroFile(path, e.changes);
159
+ }
160
+ updateAllDiagnostics();
161
+ });
162
+ documentManager.on('documentChange', (0, utils_1.debounceThrottle)(async (document) => diagnosticsManager.update(document), 1000));
163
+ documentManager.on('documentClose', (document) => diagnosticsManager.removeDiagnostics(document));
164
+ // Taking off 🚀
165
+ connection.onInitialized(() => {
166
+ connection.console.log('Successfully initialized! 🚀');
167
+ });
129
168
  connection.listen();
130
169
  }
131
- exports.startServer = startServer;
170
+ exports.startLanguageServer = startLanguageServer;
package/dist/utils.d.ts CHANGED
@@ -2,22 +2,28 @@ import { Position, Range } from 'vscode-languageserver';
2
2
  import { Node } from 'vscode-html-languageservice';
3
3
  /** Normalizes a document URI */
4
4
  export declare function normalizeUri(uri: string): string;
5
+ /**
6
+ * Some paths (on windows) start with a upper case driver letter, some don't.
7
+ * This is normalized here.
8
+ */
9
+ export declare function normalizePath(path: string): string;
5
10
  /** Turns a URL into a normalized FS Path */
6
11
  export declare function urlToPath(stringUrl: string): string | null;
7
12
  /** Converts a path to a URL */
8
13
  export declare function pathToUrl(path: string): string;
9
14
  /**
10
- *
11
- * The language service is case insensitive, and would provide
12
- * hover info for Svelte components like `Option` which have
13
- * the same name like a html tag.
15
+ * Given a path like foo/bar or foo/bar.astro , returns its last path
16
+ * (bar or bar.astro in this example).
17
+ */
18
+ export declare function getLastPartOfPath(path: string): string;
19
+ /**
20
+ * Return true if a specific node could be a component.
21
+ * This is not a 100% sure test as it'll return false for any component that does not match the standard format for a component
14
22
  */
15
23
  export declare function isPossibleComponent(node: Node): boolean;
16
24
  /**
17
- *
18
- * The language service is case insensitive, and would provide
19
- * hover info for Svelte components like `Option` which have
20
- * the same name like a html tag.
25
+ * Return true if a specific node could be a component with a client directive on it.
26
+ * This is not a 100% sure test as it'll return false for any component that does not match the standard format for a component
21
27
  */
22
28
  export declare function isPossibleClientComponent(node: Node): boolean;
23
29
  /** Flattens an array */
@@ -25,9 +31,7 @@ export declare function flatten<T>(arr: T[][]): T[];
25
31
  /** Clamps a number between min and max */
26
32
  export declare function clamp(num: number, min: number, max: number): number;
27
33
  export declare function isNotNullOrUndefined<T>(val: T | undefined | null): val is T;
28
- /** Checks if a position is inside range */
29
- export declare function isInRange(positionToTest: Position, range: Range): boolean;
30
- /** */
34
+ export declare function isInRange(range: Range, positionToTest: Position): boolean;
31
35
  export declare function isBeforeOrEqualToPosition(position: Position, positionToTest: Position): boolean;
32
36
  /**
33
37
  * Debounces a function but cancels previous invocation only if
@@ -35,15 +39,15 @@ export declare function isBeforeOrEqualToPosition(position: Position, positionTo
35
39
  *
36
40
  * @param fn The function with it's argument
37
41
  * @param determineIfSame The function which determines if the previous invocation should be canceld or not
38
- * @param miliseconds Number of miliseconds to debounce
42
+ * @param milliseconds Number of miliseconds to debounce
39
43
  */
40
- export declare function debounceSameArg<T>(fn: (arg: T) => void, shouldCancelPrevious: (newArg: T, prevArg?: T) => boolean, miliseconds: number): (arg: T) => void;
44
+ export declare function debounceSameArg<T>(fn: (arg: T) => void, shouldCancelPrevious: (newArg: T, prevArg?: T) => boolean, milliseconds: number): (arg: T) => void;
41
45
  /**
42
- * Debounces a function but also waits at minimum the specified number of miliseconds until
46
+ * Debounces a function but also waits at minimum the specified number of milliseconds until
43
47
  * the next invocation. This avoids needless calls when a synchronous call (like diagnostics)
44
48
  * took too long and the whole timeout of the next call was eaten up already.
45
49
  *
46
50
  * @param fn The function with it's argument
47
- * @param miliseconds Number of miliseconds to debounce/throttle
51
+ * @param milliseconds Number of milliseconds to debounce/throttle
48
52
  */
49
- export declare function debounceThrottle<T extends (...args: any) => void>(fn: T, miliseconds: number): T;
53
+ export declare function debounceThrottle<T extends (...args: any) => void>(fn: T, milliseconds: number): T;
package/dist/utils.js CHANGED
@@ -1,12 +1,20 @@
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.isPossibleClientComponent = exports.isPossibleComponent = exports.pathToUrl = exports.urlToPath = exports.normalizeUri = void 0;
3
+ exports.debounceThrottle = exports.debounceSameArg = exports.isBeforeOrEqualToPosition = exports.isInRange = exports.isNotNullOrUndefined = exports.clamp = exports.flatten = exports.isPossibleClientComponent = 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) {
7
7
  return vscode_uri_1.URI.parse(uri).toString();
8
8
  }
9
9
  exports.normalizeUri = normalizeUri;
10
+ /**
11
+ * Some paths (on windows) start with a upper case driver letter, some don't.
12
+ * This is normalized here.
13
+ */
14
+ function normalizePath(path) {
15
+ return vscode_uri_1.URI.file(path).fsPath.replace(/\\/g, '/');
16
+ }
17
+ exports.normalizePath = normalizePath;
10
18
  /** Turns a URL into a normalized FS Path */
11
19
  function urlToPath(stringUrl) {
12
20
  const url = vscode_uri_1.URI.parse(stringUrl);
@@ -22,21 +30,25 @@ function pathToUrl(path) {
22
30
  }
23
31
  exports.pathToUrl = pathToUrl;
24
32
  /**
25
- *
26
- * The language service is case insensitive, and would provide
27
- * hover info for Svelte components like `Option` which have
28
- * the same name like a html tag.
33
+ * Given a path like foo/bar or foo/bar.astro , returns its last path
34
+ * (bar or bar.astro in this example).
35
+ */
36
+ function getLastPartOfPath(path) {
37
+ return path.replace(/\\/g, '/').split('/').pop() || '';
38
+ }
39
+ exports.getLastPartOfPath = getLastPartOfPath;
40
+ /**
41
+ * Return true if a specific node could be a component.
42
+ * This is not a 100% sure test as it'll return false for any component that does not match the standard format for a component
29
43
  */
30
44
  function isPossibleComponent(node) {
31
- var _a;
32
- return !!((_a = node.tag) === null || _a === void 0 ? void 0 : _a[0].match(/[A-Z]/));
45
+ var _a, _b;
46
+ return !!((_a = node.tag) === null || _a === void 0 ? void 0 : _a[0].match(/[A-Z]/)) || !!((_b = node.tag) === null || _b === void 0 ? void 0 : _b.match(/.+[.][A-Z]/));
33
47
  }
34
48
  exports.isPossibleComponent = isPossibleComponent;
35
49
  /**
36
- *
37
- * The language service is case insensitive, and would provide
38
- * hover info for Svelte components like `Option` which have
39
- * the same name like a html tag.
50
+ * Return true if a specific node could be a component with a client directive on it.
51
+ * This is not a 100% sure test as it'll return false for any component that does not match the standard format for a component
40
52
  */
41
53
  function isPossibleClientComponent(node) {
42
54
  if (isPossibleComponent(node) && node.attributes) {
@@ -63,14 +75,13 @@ function isNotNullOrUndefined(val) {
63
75
  return val !== undefined && val !== null;
64
76
  }
65
77
  exports.isNotNullOrUndefined = isNotNullOrUndefined;
66
- /** Checks if a position is inside range */
67
- function isInRange(positionToTest, range) {
78
+ function isInRange(range, positionToTest) {
68
79
  return isBeforeOrEqualToPosition(range.end, positionToTest) && isBeforeOrEqualToPosition(positionToTest, range.start);
69
80
  }
70
81
  exports.isInRange = isInRange;
71
- /** */
72
82
  function isBeforeOrEqualToPosition(position, positionToTest) {
73
- return positionToTest.line < position.line || (positionToTest.line === position.line && positionToTest.character <= position.character);
83
+ return (positionToTest.line < position.line ||
84
+ (positionToTest.line === position.line && positionToTest.character <= position.character));
74
85
  }
75
86
  exports.isBeforeOrEqualToPosition = isBeforeOrEqualToPosition;
76
87
  /**
@@ -79,9 +90,9 @@ exports.isBeforeOrEqualToPosition = isBeforeOrEqualToPosition;
79
90
  *
80
91
  * @param fn The function with it's argument
81
92
  * @param determineIfSame The function which determines if the previous invocation should be canceld or not
82
- * @param miliseconds Number of miliseconds to debounce
93
+ * @param milliseconds Number of miliseconds to debounce
83
94
  */
84
- function debounceSameArg(fn, shouldCancelPrevious, miliseconds) {
95
+ function debounceSameArg(fn, shouldCancelPrevious, milliseconds) {
85
96
  let timeout;
86
97
  let prevArg;
87
98
  return (arg) => {
@@ -92,31 +103,31 @@ function debounceSameArg(fn, shouldCancelPrevious, miliseconds) {
92
103
  timeout = setTimeout(() => {
93
104
  fn(arg);
94
105
  prevArg = undefined;
95
- }, miliseconds);
106
+ }, milliseconds);
96
107
  };
97
108
  }
98
109
  exports.debounceSameArg = debounceSameArg;
99
110
  /**
100
- * Debounces a function but also waits at minimum the specified number of miliseconds until
111
+ * Debounces a function but also waits at minimum the specified number of milliseconds until
101
112
  * the next invocation. This avoids needless calls when a synchronous call (like diagnostics)
102
113
  * took too long and the whole timeout of the next call was eaten up already.
103
114
  *
104
115
  * @param fn The function with it's argument
105
- * @param miliseconds Number of miliseconds to debounce/throttle
116
+ * @param milliseconds Number of milliseconds to debounce/throttle
106
117
  */
107
- function debounceThrottle(fn, miliseconds) {
118
+ function debounceThrottle(fn, milliseconds) {
108
119
  let timeout;
109
- let lastInvocation = Date.now() - miliseconds;
120
+ let lastInvocation = Date.now() - milliseconds;
110
121
  function maybeCall(...args) {
111
122
  clearTimeout(timeout);
112
123
  timeout = setTimeout(() => {
113
- if (Date.now() - lastInvocation < miliseconds) {
124
+ if (Date.now() - lastInvocation < milliseconds) {
114
125
  maybeCall(...args);
115
126
  return;
116
127
  }
117
128
  fn(...args);
118
129
  lastInvocation = Date.now();
119
- }, miliseconds);
130
+ }, milliseconds);
120
131
  }
121
132
  return maybeCall;
122
133
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
7
7
  "main": "dist/index.js",
8
8
  "bin": {
9
- "astro-ls": "./bin/server.js"
9
+ "astro-ls": "./bin/nodeServer.js"
10
10
  },
11
11
  "files": [
12
12
  "dist",
@@ -16,27 +16,33 @@
16
16
  "scripts": {
17
17
  "build": "tsc",
18
18
  "dev": "astro-scripts dev \"src/**/*.ts\"",
19
- "test": "tap --no-coverage test/**"
19
+ "test": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --require ts-node/register \"test/**/*.ts\" --exclude \"test/**/*.d.ts\""
20
20
  },
21
21
  "dependencies": {
22
22
  "@astrojs/svelte-language-integration": "^0.1.0",
23
+ "@vscode/emmet-helper": "^2.8.4",
23
24
  "lodash": "^4.17.21",
24
25
  "source-map": "^0.7.3",
25
- "ts-morph": "^12.0.0",
26
- "typescript": "^4.5.4",
27
- "vscode-css-languageservice": "^5.1.1",
28
- "@vscode/emmet-helper": "^2.8.4",
29
- "vscode-html-languageservice": "^3.0.3",
30
- "vscode-languageserver": "6.1.1",
26
+ "typescript": "~4.6.2",
27
+ "vscode-css-languageservice": "^5.1.13",
28
+ "vscode-html-languageservice": "^4.2.2",
29
+ "vscode-languageserver": "7.0.0",
31
30
  "vscode-languageserver-protocol": "^3.16.0",
32
31
  "vscode-languageserver-textdocument": "^1.0.1",
33
32
  "vscode-languageserver-types": "^3.16.0",
34
33
  "vscode-uri": "^3.0.2"
35
34
  },
36
35
  "devDependencies": {
37
- "@types/lodash": "^4.14.116",
38
- "astro": "^0.23.5",
36
+ "@types/chai": "^4.3.0",
37
+ "@types/lodash": "^4.14.179",
38
+ "@types/mocha": "^9.1.0",
39
+ "@types/sinon": "^10.0.11",
40
+ "astro": "^0.23.7",
39
41
  "astro-scripts": "0.0.1",
40
- "tap": "^15.0.9"
42
+ "chai": "^4.3.6",
43
+ "cross-env": "^7.0.3",
44
+ "mocha": "^9.2.2",
45
+ "sinon": "^13.0.1",
46
+ "ts-node": "^10.7.0"
41
47
  }
42
48
  }