@astrojs/language-server 0.16.0 → 0.18.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 (47) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/core/config/ConfigManager.d.ts +25 -16
  3. package/dist/core/config/ConfigManager.js +160 -46
  4. package/dist/core/config/interfaces.d.ts +4 -51
  5. package/dist/core/documents/AstroDocument.d.ts +1 -0
  6. package/dist/core/documents/AstroDocument.js +1 -0
  7. package/dist/core/documents/DocumentMapper.d.ts +2 -0
  8. package/dist/core/documents/DocumentMapper.js +7 -5
  9. package/dist/core/documents/utils.d.ts +1 -0
  10. package/dist/core/documents/utils.js +16 -1
  11. package/dist/plugins/PluginHost.d.ts +3 -1
  12. package/dist/plugins/PluginHost.js +8 -0
  13. package/dist/plugins/astro/AstroPlugin.d.ts +1 -6
  14. package/dist/plugins/astro/AstroPlugin.js +10 -85
  15. package/dist/plugins/astro/features/CompletionsProvider.d.ts +4 -5
  16. package/dist/plugins/astro/features/CompletionsProvider.js +53 -58
  17. package/dist/plugins/css/CSSPlugin.d.ts +5 -5
  18. package/dist/plugins/css/CSSPlugin.js +36 -31
  19. package/dist/plugins/html/HTMLPlugin.d.ts +6 -5
  20. package/dist/plugins/html/HTMLPlugin.js +38 -16
  21. package/dist/plugins/html/features/astro-attributes.js +1 -0
  22. package/dist/plugins/interfaces.d.ts +5 -2
  23. package/dist/plugins/typescript/TypeScriptPlugin.d.ts +7 -4
  24. package/dist/plugins/typescript/TypeScriptPlugin.js +34 -110
  25. package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +3 -1
  26. package/dist/plugins/typescript/features/CodeActionsProvider.js +82 -17
  27. package/dist/plugins/typescript/features/CompletionsProvider.d.ts +5 -3
  28. package/dist/plugins/typescript/features/CompletionsProvider.js +112 -56
  29. package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +9 -0
  30. package/dist/plugins/typescript/features/DefinitionsProvider.js +57 -0
  31. package/dist/plugins/typescript/features/DiagnosticsProvider.js +58 -15
  32. package/dist/plugins/typescript/features/FoldingRangesProvider.js +13 -6
  33. package/dist/plugins/typescript/features/FormattingProvider.d.ts +11 -0
  34. package/dist/plugins/typescript/features/FormattingProvider.js +132 -0
  35. package/dist/plugins/typescript/features/HoverProvider.js +14 -1
  36. package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +12 -0
  37. package/dist/plugins/typescript/features/InlayHintsProvider.js +36 -0
  38. package/dist/plugins/typescript/features/SignatureHelpProvider.js +9 -1
  39. package/dist/plugins/typescript/language-service.js +18 -0
  40. package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +22 -2
  41. package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +48 -1
  42. package/dist/plugins/typescript/snapshots/SnapshotManager.js +1 -0
  43. package/dist/plugins/typescript/snapshots/utils.js +3 -2
  44. package/dist/plugins/typescript/utils.d.ts +11 -1
  45. package/dist/plugins/typescript/utils.js +17 -1
  46. package/dist/server.js +27 -15
  47. package/package.json +7 -6
@@ -0,0 +1,12 @@
1
+ import { InlayHint } from 'vscode-languageserver';
2
+ import { AstroDocument } from '../../../core/documents';
3
+ import { InlayHintsProvider } from '../../interfaces';
4
+ import { LanguageServiceManager } from '../LanguageServiceManager';
5
+ import { Range } from 'vscode-languageserver-types';
6
+ import { ConfigManager } from '../../../core/config';
7
+ export declare class InlayHintsProviderImpl implements InlayHintsProvider {
8
+ private languageServiceManager;
9
+ private configManager;
10
+ constructor(languageServiceManager: LanguageServiceManager, configManager: ConfigManager);
11
+ getInlayHints(document: AstroDocument, range: Range): Promise<InlayHint[]>;
12
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.InlayHintsProviderImpl = void 0;
7
+ const vscode_languageserver_1 = require("vscode-languageserver");
8
+ const utils_1 = require("../utils");
9
+ const vscode_languageserver_types_1 = require("vscode-languageserver-types");
10
+ const typescript_1 = __importDefault(require("typescript"));
11
+ class InlayHintsProviderImpl {
12
+ constructor(languageServiceManager, configManager) {
13
+ this.languageServiceManager = languageServiceManager;
14
+ this.configManager = configManager;
15
+ }
16
+ async getInlayHints(document, range) {
17
+ const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
18
+ const filePath = (0, utils_1.toVirtualAstroFilePath)(tsDoc.filePath);
19
+ const fragment = await tsDoc.createFragment();
20
+ const start = fragment.offsetAt(fragment.getGeneratedPosition(range.start));
21
+ const end = fragment.offsetAt(fragment.getGeneratedPosition(range.end));
22
+ const tsPreferences = await this.configManager.getTSInlayHintsPreferences(document);
23
+ const inlayHints = lang.provideInlayHints(filePath, { start, length: end - start }, tsPreferences);
24
+ return inlayHints.map((hint) => {
25
+ const result = vscode_languageserver_1.InlayHint.create(fragment.getOriginalPosition(fragment.positionAt(hint.position)), hint.text, hint.kind === typescript_1.default.InlayHintKind.Type
26
+ ? vscode_languageserver_types_1.InlayHintKind.Type
27
+ : hint.kind === typescript_1.default.InlayHintKind.Parameter
28
+ ? vscode_languageserver_types_1.InlayHintKind.Parameter
29
+ : undefined);
30
+ result.paddingLeft = hint.whitespaceBefore;
31
+ result.paddingRight = hint.whitespaceAfter;
32
+ return result;
33
+ });
34
+ }
35
+ }
36
+ exports.InlayHintsProviderImpl = InlayHintsProviderImpl;
@@ -20,8 +20,16 @@ class SignatureHelpProviderImpl {
20
20
  }
21
21
  const filePath = (0, utils_1.toVirtualAstroFilePath)(tsDoc.filePath);
22
22
  const offset = fragment.offsetAt(fragment.getGeneratedPosition(position));
23
+ const node = document.html.findNodeAt(offset);
24
+ let info;
23
25
  const triggerReason = this.toTsTriggerReason(context);
24
- const info = lang.getSignatureHelpItems(filePath, offset, triggerReason ? { triggerReason } : undefined);
26
+ if (node.tag === 'script') {
27
+ const { filePath: scriptFilePath, offset: scriptOffset } = (0, utils_1.getScriptTagSnapshot)(tsDoc, document, node, position);
28
+ info = lang.getSignatureHelpItems(scriptFilePath, scriptOffset, triggerReason ? { triggerReason } : undefined);
29
+ }
30
+ else {
31
+ info = lang.getSignatureHelpItems(filePath, offset, triggerReason ? { triggerReason } : undefined);
32
+ }
25
33
  if (!info) {
26
34
  return null;
27
35
  }
@@ -33,6 +33,7 @@ const utils_1 = require("../../utils");
33
33
  const module_loader_1 = require("./module-loader");
34
34
  const SnapshotManager_1 = require("./snapshots/SnapshotManager");
35
35
  const utils_2 = require("./utils");
36
+ const DocumentSnapshot_1 = require("./snapshots/DocumentSnapshot");
36
37
  const DocumentSnapshotUtils = __importStar(require("./snapshots/utils"));
37
38
  const services = new Map();
38
39
  async function getLanguageService(path, workspaceUris, docContext) {
@@ -140,6 +141,12 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
140
141
  }
141
142
  const newSnapshot = DocumentSnapshotUtils.createFromDocument(document);
142
143
  snapshotManager.set(filePath, newSnapshot);
144
+ document.scriptTags.forEach((scriptTag, index) => {
145
+ const scriptFilePath = filePath + `.__script${index}.js`;
146
+ const scriptSnapshot = new DocumentSnapshot_1.ScriptTagDocumentSnapshot(scriptTag, document, scriptFilePath);
147
+ snapshotManager.set(scriptFilePath, scriptSnapshot);
148
+ newSnapshot.scriptTagSnapshots?.push(scriptSnapshot);
149
+ });
143
150
  if (prevSnapshot && prevSnapshot.scriptKind !== newSnapshot.scriptKind) {
144
151
  // Restart language service as it doesn't handle script kind changes.
145
152
  languageService.dispose();
@@ -166,6 +173,16 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
166
173
  astroModuleLoader.deleteUnresolvedResolutionsFromCache(fileName);
167
174
  doc = DocumentSnapshotUtils.createFromFilePath(fileName, docContext.createDocument);
168
175
  snapshotManager.set(fileName, doc);
176
+ // If we needed to create an Astro snapshot, also create its script tags snapshots
177
+ if ((0, utils_2.isAstroFilePath)(fileName)) {
178
+ const document = doc.parent;
179
+ document.scriptTags.forEach((scriptTag, index) => {
180
+ const scriptFilePath = fileName + `.__script${index}.js`;
181
+ const scriptSnapshot = new DocumentSnapshot_1.ScriptTagDocumentSnapshot(scriptTag, document, scriptFilePath);
182
+ snapshotManager.set(scriptFilePath, scriptSnapshot);
183
+ doc.scriptTagSnapshots?.push(scriptSnapshot);
184
+ });
185
+ }
169
186
  return doc;
170
187
  }
171
188
  function updateProjectFiles() {
@@ -214,6 +231,7 @@ async function createLanguageService(tsconfigPath, docContext, workspaceUris) {
214
231
  jsxFactory: 'astroHTML',
215
232
  module: typescript_1.default.ModuleKind.ESNext,
216
233
  target: typescript_1.default.ScriptTarget.ESNext,
234
+ isolatedModules: true,
217
235
  moduleResolution: typescript_1.default.ModuleResolutionKind.NodeJs,
218
236
  };
219
237
  const project = typescript_1.default.parseJsonConfigFileContent(configJson, typescript_1.default.sys, tsconfigRoot, forcedCompilerOptions, tsconfigPath, undefined, [
@@ -1,6 +1,6 @@
1
1
  import ts from 'typescript';
2
2
  import { Position, TextDocumentContentChangeEvent } from 'vscode-languageserver';
3
- import { AstroDocument, DocumentMapper, IdentityMapper } from '../../../core/documents';
3
+ import { AstroDocument, DocumentMapper, IdentityMapper, FragmentMapper, TagInformation } from '../../../core/documents';
4
4
  import { FrameworkExt } from '../utils';
5
5
  export interface DocumentSnapshot extends ts.IScriptSnapshot {
6
6
  version: number;
@@ -36,11 +36,12 @@ export interface SnapshotFragment extends DocumentMapper {
36
36
  * Snapshots used for Astro files
37
37
  */
38
38
  export declare class AstroSnapshot implements DocumentSnapshot {
39
- private readonly parent;
39
+ readonly parent: AstroDocument;
40
40
  private readonly text;
41
41
  readonly scriptKind: ts.ScriptKind;
42
42
  private fragment?;
43
43
  version: number;
44
+ scriptTagSnapshots: ScriptTagDocumentSnapshot[];
44
45
  constructor(parent: AstroDocument, text: string, scriptKind: ts.ScriptKind);
45
46
  createFragment(): Promise<AstroSnapshotFragment>;
46
47
  destroyFragment(): null;
@@ -65,6 +66,25 @@ export declare class AstroSnapshotFragment implements SnapshotFragment {
65
66
  isInGenerated(pos: Position): boolean;
66
67
  getURL(): string;
67
68
  }
69
+ export declare class ScriptTagDocumentSnapshot extends FragmentMapper implements DocumentSnapshot, SnapshotFragment {
70
+ scriptTag: TagInformation;
71
+ private readonly parent;
72
+ filePath: string;
73
+ readonly version: number;
74
+ private text;
75
+ scriptKind: ts.ScriptKind;
76
+ private lineOffsets?;
77
+ constructor(scriptTag: TagInformation, parent: AstroDocument, filePath: string);
78
+ positionAt(offset: number): Position;
79
+ offsetAt(position: Position): number;
80
+ createFragment(): Promise<SnapshotFragment>;
81
+ destroyFragment(): void;
82
+ getText(start: number, end: number): string;
83
+ getLength(): number;
84
+ getFullText(): string;
85
+ getChangeRange(): undefined;
86
+ private getLineOffsets;
87
+ }
68
88
  /**
69
89
  * Snapshot used for anything that is not an Astro file
70
90
  * It's both used for .js(x)/.ts(x) files and .svelte/.vue files
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeScriptDocumentSnapshot = exports.AstroSnapshotFragment = exports.AstroSnapshot = void 0;
6
+ exports.TypeScriptDocumentSnapshot = exports.ScriptTagDocumentSnapshot = exports.AstroSnapshotFragment = exports.AstroSnapshot = void 0;
7
+ const typescript_1 = __importDefault(require("typescript"));
4
8
  const documents_1 = require("../../../core/documents");
5
9
  const utils_1 = require("../../../utils");
6
10
  const utils_2 = require("../utils");
@@ -13,6 +17,7 @@ class AstroSnapshot {
13
17
  this.text = text;
14
18
  this.scriptKind = scriptKind;
15
19
  this.version = this.parent.version;
20
+ this.scriptTagSnapshots = [];
16
21
  }
17
22
  async createFragment() {
18
23
  if (!this.fragment) {
@@ -72,6 +77,48 @@ class AstroSnapshotFragment {
72
77
  }
73
78
  }
74
79
  exports.AstroSnapshotFragment = AstroSnapshotFragment;
80
+ class ScriptTagDocumentSnapshot extends documents_1.FragmentMapper {
81
+ constructor(scriptTag, parent, filePath) {
82
+ super(parent.getText(), scriptTag, filePath);
83
+ this.scriptTag = scriptTag;
84
+ this.parent = parent;
85
+ this.filePath = filePath;
86
+ this.version = this.parent.version;
87
+ this.text = this.parent.getText().slice(this.scriptTag.start, this.scriptTag.end) + '\nexport {}';
88
+ this.scriptKind = typescript_1.default.ScriptKind.JS;
89
+ }
90
+ positionAt(offset) {
91
+ return (0, documents_1.positionAt)(offset, this.text, this.getLineOffsets());
92
+ }
93
+ offsetAt(position) {
94
+ return (0, documents_1.offsetAt)(position, this.text, this.getLineOffsets());
95
+ }
96
+ async createFragment() {
97
+ return this;
98
+ }
99
+ destroyFragment() {
100
+ //
101
+ }
102
+ getText(start, end) {
103
+ return this.text.substring(start, end);
104
+ }
105
+ getLength() {
106
+ return this.text.length;
107
+ }
108
+ getFullText() {
109
+ return this.text;
110
+ }
111
+ getChangeRange() {
112
+ return undefined;
113
+ }
114
+ getLineOffsets() {
115
+ if (!this.lineOffsets) {
116
+ this.lineOffsets = (0, documents_1.getLineOffsets)(this.text);
117
+ }
118
+ return this.lineOffsets;
119
+ }
120
+ }
121
+ exports.ScriptTagDocumentSnapshot = ScriptTagDocumentSnapshot;
75
122
  /**
76
123
  * Snapshot used for anything that is not an Astro file
77
124
  * It's both used for .js(x)/.ts(x) files and .svelte/.vue files
@@ -187,6 +187,7 @@ class SnapshotManager {
187
187
  const projectFiles = this.getProjectFileNames();
188
188
  let allFiles = Array.from(new Set([...projectFiles, ...this.getFileNames()]));
189
189
  allFiles = allFiles.map((file) => (0, utils_2.ensureRealFilePath)(file));
190
+ // eslint-disable-next-line no-console
190
191
  console.log('SnapshotManager File Statistics:\n' +
191
192
  `Project files: ${projectFiles.length}\n` +
192
193
  `Astro files: ${allFiles.filter((name) => name.endsWith('.astro')).length}\n` +
@@ -10,6 +10,7 @@ const vscode_uri_1 = require("vscode-uri");
10
10
  const utils_1 = require("../utils");
11
11
  const DocumentSnapshot_1 = require("./DocumentSnapshot");
12
12
  const svelte_language_integration_1 = require("@astrojs/svelte-language-integration");
13
+ const vue_language_integration_1 = require("@astrojs/vue-language-integration");
13
14
  const utils_2 = require("../../../utils");
14
15
  // Utilities to create Snapshots from different contexts
15
16
  function createFromDocument(document) {
@@ -76,8 +77,8 @@ function createFromFrameworkFilePath(filePath, framework) {
76
77
  if (framework === 'svelte') {
77
78
  code = (0, svelte_language_integration_1.toTSX)(originalText, className);
78
79
  }
79
- else {
80
- code = `export default function ${className}__AstroComponent_(props: Record<string, any>): any {}`;
80
+ else if (framework === 'vue') {
81
+ code = (0, vue_language_integration_1.toTSX)(originalText, className);
81
82
  }
82
83
  return new DocumentSnapshot_1.TypeScriptDocumentSnapshot(0, filePath, code, typescript_1.default.ScriptKind.TSX);
83
84
  }
@@ -1,7 +1,8 @@
1
1
  import ts from 'typescript';
2
2
  import { CompletionItemKind, DiagnosticSeverity, Position, Range, SymbolKind, SemanticTokensLegend } from 'vscode-languageserver';
3
3
  import { AstroDocument } from '../../core/documents';
4
- import { SnapshotFragment } from './snapshots/DocumentSnapshot';
4
+ import { AstroSnapshot, ScriptTagDocumentSnapshot, SnapshotFragment } from './snapshots/DocumentSnapshot';
5
+ import { Node } from 'vscode-html-languageservice';
5
6
  export declare const enum TokenType {
6
7
  class = 0,
7
8
  enum = 1,
@@ -58,4 +59,13 @@ export declare function toVirtualFilePath(filePath: string): string;
58
59
  export declare function toRealAstroFilePath(filePath: string): string;
59
60
  export declare function ensureRealAstroFilePath(filePath: string): string;
60
61
  export declare function ensureRealFilePath(filePath: string): string;
62
+ export declare function getScriptTagSnapshot(snapshot: AstroSnapshot, document: AstroDocument, tagInfo: Node | {
63
+ start: number;
64
+ end: number;
65
+ }, position?: Position): {
66
+ snapshot: ScriptTagDocumentSnapshot;
67
+ filePath: string;
68
+ index: number;
69
+ offset: number;
70
+ };
61
71
  export {};
@@ -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.ensureRealFilePath = exports.ensureRealAstroFilePath = exports.toRealAstroFilePath = exports.toVirtualFilePath = exports.toVirtualAstroFilePath = exports.isVirtualFilePath = exports.isVirtualSvelteFilePath = exports.isVirtualVueFilePath = exports.isVirtualAstroFilePath = exports.isFrameworkFilePath = exports.isAstroFilePath = exports.isVirtualFrameworkFilePath = exports.getFrameworkFromFilePath = exports.removeAstroComponentSuffix = exports.checkEndOfFileCodeInsert = exports.ensureFrontmatterInsert = exports.convertToLocationRange = exports.convertRange = exports.mapSeverity = exports.getScriptKindFromFileName = exports.isSubPath = exports.findTsConfigPath = exports.getExtensionFromScriptKind = exports.getCommitCharactersForScriptElement = exports.scriptElementKindToCompletionItemKind = exports.symbolKindFromString = exports.getSemanticTokenLegend = void 0;
6
+ exports.getScriptTagSnapshot = exports.ensureRealFilePath = exports.ensureRealAstroFilePath = exports.toRealAstroFilePath = exports.toVirtualFilePath = exports.toVirtualAstroFilePath = exports.isVirtualFilePath = exports.isVirtualSvelteFilePath = exports.isVirtualVueFilePath = exports.isVirtualAstroFilePath = exports.isFrameworkFilePath = exports.isAstroFilePath = exports.isVirtualFrameworkFilePath = exports.getFrameworkFromFilePath = exports.removeAstroComponentSuffix = exports.checkEndOfFileCodeInsert = exports.ensureFrontmatterInsert = exports.convertToLocationRange = exports.convertRange = exports.mapSeverity = exports.getScriptKindFromFileName = exports.isSubPath = exports.findTsConfigPath = exports.getExtensionFromScriptKind = exports.getCommitCharactersForScriptElement = exports.scriptElementKindToCompletionItemKind = exports.symbolKindFromString = exports.getSemanticTokenLegend = void 0;
7
7
  const typescript_1 = __importDefault(require("typescript"));
8
8
  const path_1 = require("path");
9
9
  const utils_1 = require("../../utils");
@@ -346,3 +346,19 @@ function ensureRealFilePath(filePath) {
346
346
  }
347
347
  }
348
348
  exports.ensureRealFilePath = ensureRealFilePath;
349
+ function getScriptTagSnapshot(snapshot, document, tagInfo, position) {
350
+ const index = document.scriptTags.findIndex((value) => value.container.start == tagInfo.start);
351
+ const scriptFilePath = snapshot.filePath + `.__script${index}.js`;
352
+ const scriptTagSnapshot = snapshot.scriptTagSnapshots[index];
353
+ let offset = 0;
354
+ if (position) {
355
+ offset = scriptTagSnapshot.offsetAt(scriptTagSnapshot.getGeneratedPosition(position));
356
+ }
357
+ return {
358
+ snapshot: scriptTagSnapshot,
359
+ filePath: scriptFilePath,
360
+ index,
361
+ offset,
362
+ };
363
+ }
364
+ exports.getScriptTagSnapshot = getScriptTagSnapshot;
package/dist/server.js CHANGED
@@ -41,9 +41,10 @@ const TagCloseRequest = new vscode.RequestType('html/tag');
41
41
  // Start the language server
42
42
  function startLanguageServer(connection) {
43
43
  // Create our managers
44
- const configManager = new ConfigManager_1.ConfigManager();
45
44
  const documentManager = new DocumentManager_1.DocumentManager();
46
45
  const pluginHost = new PluginHost_1.PluginHost(documentManager);
46
+ const configManager = new ConfigManager_1.ConfigManager(connection);
47
+ let hasConfigurationCapability = false;
47
48
  connection.onInitialize((params) => {
48
49
  const workspaceUris = params.workspaceFolders?.map((folder) => folder.uri.toString()) ?? [params.rootUri ?? ''];
49
50
  workspaceUris.forEach((uri) => {
@@ -62,6 +63,7 @@ function startLanguageServer(connection) {
62
63
  });
63
64
  }
64
65
  });
66
+ hasConfigurationCapability = !!(params.capabilities.workspace && !!params.capabilities.workspace.configuration);
65
67
  pluginHost.initialize({
66
68
  filterIncompleteCompletions: !params.initializationOptions?.dontFilterIncompleteCompletions,
67
69
  definitionLinkSupport: !!params.capabilities.textDocument?.definition?.linkSupport,
@@ -74,15 +76,6 @@ function startLanguageServer(connection) {
74
76
  pluginHost.registerPlugin(new AstroPlugin_1.AstroPlugin(documentManager, configManager, workspaceUris));
75
77
  pluginHost.registerPlugin(new plugins_1.TypeScriptPlugin(documentManager, configManager, workspaceUris));
76
78
  }
77
- // Update language-server config with what the user supplied to us at launch
78
- let astroConfiguration = params.initializationOptions?.configuration?.astro;
79
- if (astroConfiguration) {
80
- configManager.updateConfig(astroConfiguration);
81
- }
82
- let emmetConfiguration = params.initializationOptions?.configuration?.emmet;
83
- if (emmetConfiguration) {
84
- configManager.updateEmmetConfig(emmetConfiguration);
85
- }
86
79
  return {
87
80
  capabilities: {
88
81
  textDocumentSync: {
@@ -95,6 +88,7 @@ function startLanguageServer(connection) {
95
88
  foldingRangeProvider: true,
96
89
  definitionProvider: true,
97
90
  renameProvider: true,
91
+ documentFormattingProvider: true,
98
92
  codeActionProvider: {
99
93
  codeActionKinds: [
100
94
  vscode_languageserver_1.CodeActionKind.QuickFix,
@@ -140,6 +134,7 @@ function startLanguageServer(connection) {
140
134
  range: true,
141
135
  full: true,
142
136
  },
137
+ inlayHintProvider: true,
143
138
  signatureHelpProvider: {
144
139
  triggerCharacters: ['(', ',', '<'],
145
140
  retriggerCharacters: [')'],
@@ -147,10 +142,18 @@ function startLanguageServer(connection) {
147
142
  },
148
143
  };
149
144
  });
150
- // On update of the user configuration of the language-server
151
- connection.onDidChangeConfiguration(({ settings }) => {
152
- configManager.updateConfig(settings.astro);
153
- configManager.updateEmmetConfig(settings.emmet);
145
+ // The params don't matter here because in "pull mode" it's always null, it's intended that when the config is updated
146
+ // you should just reset "your internal cache" and get the config again for relevant documents, weird API design
147
+ connection.onDidChangeConfiguration(async (change) => {
148
+ if (hasConfigurationCapability) {
149
+ configManager.updateConfig();
150
+ documentManager.getAllOpenedByClient().forEach(async (document) => {
151
+ await configManager.getConfig('astro', document[1].uri);
152
+ });
153
+ }
154
+ else {
155
+ configManager.updateGlobalConfig(change.settings.astro || ConfigManager_1.defaultLSConfig);
156
+ }
154
157
  });
155
158
  // Documents
156
159
  connection.onDidOpenTextDocument((params) => {
@@ -192,8 +195,10 @@ function startLanguageServer(connection) {
192
195
  connection.onDocumentSymbol((params, cancellationToken) => pluginHost.getDocumentSymbols(params.textDocument, cancellationToken));
193
196
  connection.onRequest(vscode_languageserver_1.SemanticTokensRequest.type, (evt, cancellationToken) => pluginHost.getSemanticTokens(evt.textDocument, undefined, cancellationToken));
194
197
  connection.onRequest(vscode_languageserver_1.SemanticTokensRangeRequest.type, (evt, cancellationToken) => pluginHost.getSemanticTokens(evt.textDocument, evt.range, cancellationToken));
198
+ connection.onDocumentFormatting((params) => pluginHost.formatDocument(params.textDocument, params.options));
195
199
  connection.onDocumentColor((params) => pluginHost.getDocumentColors(params.textDocument));
196
200
  connection.onColorPresentation((params) => pluginHost.getColorPresentations(params.textDocument, params.range, params.color));
201
+ connection.onRequest(vscode_languageserver_1.InlayHintRequest.type, (params, cancellationToken) => pluginHost.getInlayHints(params.textDocument, params.range, cancellationToken));
197
202
  connection.onRequest(TagCloseRequest, (evt) => pluginHost.doTagComplete(evt.textDocument, evt.position));
198
203
  connection.onSignatureHelp((evt, cancellationToken) => pluginHost.getSignatureHelp(evt.textDocument, evt.position, evt.context, cancellationToken));
199
204
  connection.onRenameRequest((evt) => pluginHost.rename(evt.textDocument, evt.position, evt.newName));
@@ -206,10 +211,17 @@ function startLanguageServer(connection) {
206
211
  updateAllDiagnostics();
207
212
  });
208
213
  documentManager.on('documentChange', (0, utils_1.debounceThrottle)(async (document) => diagnosticsManager.update(document), 1000));
209
- documentManager.on('documentClose', (document) => diagnosticsManager.removeDiagnostics(document));
214
+ documentManager.on('documentClose', (document) => {
215
+ diagnosticsManager.removeDiagnostics(document);
216
+ configManager.removeDocument(document.uri);
217
+ });
210
218
  // Taking off 🚀
211
219
  connection.onInitialized(() => {
212
220
  connection.console.log('Successfully initialized! 🚀');
221
+ // Register for all configuration changes.
222
+ if (hasConfigurationCapability) {
223
+ connection.client.register(vscode_languageserver_1.DidChangeConfigurationNotification.type);
224
+ }
213
225
  });
214
226
  connection.listen();
215
227
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -19,17 +19,18 @@
19
19
  "test": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --timeout 20000 --require ts-node/register \"test/**/*.ts\" --exclude \"test/**/*.d.ts\""
20
20
  },
21
21
  "dependencies": {
22
+ "@astrojs/vue-language-integration": "^0.1.0",
22
23
  "@astrojs/svelte-language-integration": "^0.1.4",
23
24
  "@vscode/emmet-helper": "^2.8.4",
24
25
  "lodash": "^4.17.21",
25
26
  "source-map": "^0.7.3",
26
- "typescript": "~4.6.2",
27
+ "typescript": "~4.6.4",
27
28
  "vscode-css-languageservice": "^5.1.13",
28
- "vscode-html-languageservice": "^4.2.2",
29
- "vscode-languageserver": "7.0.0",
30
- "vscode-languageserver-protocol": "^3.16.0",
29
+ "vscode-html-languageservice": "^4.2.5",
30
+ "vscode-languageserver": "^8.0.0",
31
+ "vscode-languageserver-protocol": "^3.17.0",
31
32
  "vscode-languageserver-textdocument": "^1.0.1",
32
- "vscode-languageserver-types": "^3.16.0",
33
+ "vscode-languageserver-types": "^3.17.0",
33
34
  "vscode-uri": "^3.0.2"
34
35
  },
35
36
  "devDependencies": {