@astrojs/language-server 0.23.1 → 0.24.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 +23 -0
- package/dist/browser.js +8 -1
- package/dist/check.d.ts +2 -1
- package/dist/check.js +8 -2
- package/dist/core/DiagnosticsManager.d.ts +2 -2
- package/dist/core/config/ConfigManager.d.ts +8 -8
- package/dist/core/config/ConfigManager.js +6 -12
- package/dist/core/documents/AstroDocument.d.ts +1 -1
- package/dist/core/documents/AstroDocument.js +1 -1
- package/dist/core/documents/DocumentBase.d.ts +2 -2
- package/dist/core/documents/DocumentManager.d.ts +1 -1
- package/dist/core/documents/DocumentManager.js +1 -1
- package/dist/core/documents/DocumentMapper.d.ts +2 -2
- package/dist/core/documents/parseHtml.d.ts +3 -2
- package/dist/core/documents/parseHtml.js +12 -5
- package/dist/core/documents/utils.d.ts +3 -3
- package/dist/core/documents/utils.js +1 -2
- package/dist/node.js +15 -1
- package/dist/plugins/PluginHost.d.ts +2 -2
- package/dist/plugins/PluginHost.js +1 -1
- package/dist/plugins/astro/AstroPlugin.d.ts +6 -5
- package/dist/plugins/astro/AstroPlugin.js +1 -0
- package/dist/plugins/astro/features/CompletionsProvider.d.ts +4 -3
- package/dist/plugins/astro/features/CompletionsProvider.js +12 -15
- package/dist/plugins/css/CSSDocument.d.ts +2 -2
- package/dist/plugins/css/CSSDocument.js +1 -1
- package/dist/plugins/css/CSSPlugin.d.ts +1 -1
- package/dist/plugins/css/CSSPlugin.js +3 -3
- package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
- package/dist/plugins/css/StyleAttributeDocument.js +1 -1
- package/dist/plugins/css/features/astro-selectors.d.ts +1 -1
- package/dist/plugins/css/features/getIdClassCompletions.d.ts +2 -2
- package/dist/plugins/html/HTMLPlugin.d.ts +3 -3
- package/dist/plugins/html/HTMLPlugin.js +1 -1
- package/dist/plugins/html/utils.d.ts +1 -1
- package/dist/plugins/index.d.ts +4 -4
- package/dist/plugins/index.js +4 -4
- package/dist/plugins/interfaces.d.ts +2 -2
- package/dist/plugins/typescript/LanguageServiceManager.d.ts +8 -9
- package/dist/plugins/typescript/LanguageServiceManager.js +5 -3
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +7 -6
- package/dist/plugins/typescript/TypeScriptPlugin.js +15 -15
- package/dist/plugins/typescript/astro-sys.d.ts +2 -3
- package/dist/plugins/typescript/astro-sys.js +7 -11
- package/dist/plugins/typescript/astro2tsx.js +3 -4
- package/dist/plugins/typescript/features/CodeActionsProvider.d.ts +5 -4
- package/dist/plugins/typescript/features/CodeActionsProvider.js +6 -9
- package/dist/plugins/typescript/features/CompletionsProvider.d.ts +9 -7
- package/dist/plugins/typescript/features/CompletionsProvider.js +56 -80
- package/dist/plugins/typescript/features/DefinitionsProvider.d.ts +4 -4
- package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +6 -4
- package/dist/plugins/typescript/features/DiagnosticsProvider.js +29 -19
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.d.ts +3 -2
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +3 -4
- package/dist/plugins/typescript/features/FoldingRangesProvider.d.ts +7 -4
- package/dist/plugins/typescript/features/FoldingRangesProvider.js +12 -15
- package/dist/plugins/typescript/features/HoverProvider.d.ts +5 -4
- package/dist/plugins/typescript/features/HoverProvider.js +3 -6
- package/dist/plugins/typescript/features/InlayHintsProvider.d.ts +5 -4
- package/dist/plugins/typescript/features/InlayHintsProvider.js +5 -8
- package/dist/plugins/typescript/features/SemanticTokenProvider.d.ts +3 -2
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +4 -7
- package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +5 -4
- package/dist/plugins/typescript/features/SignatureHelpProvider.js +7 -10
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +3 -3
- package/dist/plugins/typescript/features/utils.d.ts +3 -3
- package/dist/plugins/typescript/language-service.d.ts +7 -6
- package/dist/plugins/typescript/language-service.js +29 -30
- package/dist/plugins/typescript/module-loader.d.ts +2 -2
- package/dist/plugins/typescript/module-loader.js +12 -16
- package/dist/plugins/typescript/previewer.d.ts +3 -7
- package/dist/plugins/typescript/previewer.js +13 -17
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +4 -5
- package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +2 -7
- package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +5 -2
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +15 -17
- package/dist/plugins/typescript/snapshots/utils.d.ts +7 -7
- package/dist/plugins/typescript/snapshots/utils.js +28 -29
- package/dist/plugins/typescript/utils.d.ts +8 -10
- package/dist/plugins/typescript/utils.js +90 -107
- package/dist/server.d.ts +5 -1
- package/dist/server.js +29 -18
- package/dist/utils.d.ts +1 -1
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @astrojs/language-server
|
|
2
2
|
|
|
3
|
+
## 0.24.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b66ae70: Update the VS Code extension to use a bundled version of the language server for better performance and compatibility with running the extension in the web
|
|
8
|
+
- 5a583d3: TypeScript will now be loaded from VS Code / the workspace instead of being bundled inside the language server
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 5146422: Fix <> inside the frontmatter preventing certain HTML features from working inside the template
|
|
13
|
+
|
|
14
|
+
## 0.23.3
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 150946c: Publish failed
|
|
19
|
+
|
|
20
|
+
## 0.23.2
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- b13fb51: Don't use `workspace/configuration` on clients that don't support it
|
|
25
|
+
|
|
3
26
|
## 0.23.1
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/dist/browser.js
CHANGED
|
@@ -5,4 +5,11 @@ const server_1 = require("./server");
|
|
|
5
5
|
const messageReader = new browser_1.BrowserMessageReader(self);
|
|
6
6
|
const messageWriter = new browser_1.BrowserMessageWriter(self);
|
|
7
7
|
const connection = (0, browser_1.createConnection)(messageReader, messageWriter);
|
|
8
|
-
(0, server_1.startLanguageServer)(connection
|
|
8
|
+
(0, server_1.startLanguageServer)(connection, {
|
|
9
|
+
loadTypescript(options) {
|
|
10
|
+
return undefined; // TODO: Full browser support
|
|
11
|
+
},
|
|
12
|
+
loadTypescriptLocalized(options) {
|
|
13
|
+
return undefined;
|
|
14
|
+
},
|
|
15
|
+
});
|
package/dist/check.d.ts
CHANGED
|
@@ -11,7 +11,8 @@ export declare class AstroCheck {
|
|
|
11
11
|
private docManager;
|
|
12
12
|
private configManager;
|
|
13
13
|
private pluginHost;
|
|
14
|
-
|
|
14
|
+
private ts;
|
|
15
|
+
constructor(workspacePath: string, typescriptPath: string, options?: LSConfig);
|
|
15
16
|
upsertDocument(doc: {
|
|
16
17
|
text: string;
|
|
17
18
|
uri: string;
|
package/dist/check.js
CHANGED
|
@@ -9,11 +9,17 @@ const utils_1 = require("./utils");
|
|
|
9
9
|
var vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
10
10
|
Object.defineProperty(exports, "DiagnosticSeverity", { enumerable: true, get: function () { return vscode_languageserver_types_1.DiagnosticSeverity; } });
|
|
11
11
|
class AstroCheck {
|
|
12
|
-
constructor(workspacePath, options) {
|
|
12
|
+
constructor(workspacePath, typescriptPath, options) {
|
|
13
13
|
this.docManager = documents_1.DocumentManager.newInstance();
|
|
14
14
|
this.configManager = new config_1.ConfigManager();
|
|
15
15
|
this.pluginHost = new plugins_1.PluginHost(this.docManager);
|
|
16
16
|
this.initialize(workspacePath);
|
|
17
|
+
try {
|
|
18
|
+
this.ts = require(typescriptPath);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
throw new Error(`Couldn't load TypeScript from path ${typescriptPath}`);
|
|
22
|
+
}
|
|
17
23
|
if (options) {
|
|
18
24
|
this.configManager.updateGlobalConfig(options);
|
|
19
25
|
}
|
|
@@ -39,7 +45,7 @@ class AstroCheck {
|
|
|
39
45
|
}));
|
|
40
46
|
}
|
|
41
47
|
initialize(workspacePath) {
|
|
42
|
-
const languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(this.docManager, [(0, utils_1.normalizeUri)(workspacePath)], this.configManager);
|
|
48
|
+
const languageServiceManager = new LanguageServiceManager_1.LanguageServiceManager(this.docManager, [(0, utils_1.normalizeUri)(workspacePath)], this.configManager, this.ts);
|
|
43
49
|
this.pluginHost.registerPlugin(new plugins_1.TypeScriptPlugin(this.configManager, languageServiceManager));
|
|
44
50
|
}
|
|
45
51
|
async getDiagnosticsForFile(uri) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Connection,
|
|
2
|
-
import {
|
|
1
|
+
import type { Connection, Diagnostic, TextDocumentIdentifier } from 'vscode-languageserver';
|
|
2
|
+
import type { AstroDocument, DocumentManager } from './documents';
|
|
3
3
|
export declare type SendDiagnostics = Connection['sendDiagnostics'];
|
|
4
4
|
export declare type GetDiagnostics = (doc: TextDocumentIdentifier) => Thenable<Diagnostic[]>;
|
|
5
5
|
export declare class DiagnosticsManager {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { VSCodeEmmetConfig } from '@vscode/emmet-helper';
|
|
2
|
-
import {
|
|
3
|
-
import { Connection, FormattingOptions } from 'vscode-languageserver';
|
|
4
|
-
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
5
|
-
import {
|
|
1
|
+
import type { VSCodeEmmetConfig } from '@vscode/emmet-helper';
|
|
2
|
+
import type { FormatCodeSettings, UserPreferences } from 'typescript';
|
|
3
|
+
import type { Connection, FormattingOptions } from 'vscode-languageserver';
|
|
4
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
5
|
+
import type { LSConfig, LSCSSConfig, LSHTMLConfig, LSTypescriptConfig } from './interfaces';
|
|
6
6
|
export declare const defaultLSConfig: LSConfig;
|
|
7
7
|
declare type DeepPartial<T> = T extends Record<string, unknown> ? {
|
|
8
8
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
@@ -13,12 +13,13 @@ declare type DeepPartial<T> = T extends Record<string, unknown> ? {
|
|
|
13
13
|
* For more info on this, see the [internal docs](../../../../../docs/internal/language-server/config.md)
|
|
14
14
|
*/
|
|
15
15
|
export declare class ConfigManager {
|
|
16
|
+
private connection?;
|
|
17
|
+
private hasConfigurationCapability?;
|
|
16
18
|
private globalConfig;
|
|
17
19
|
private documentSettings;
|
|
18
20
|
shouldRefreshTSServices: boolean;
|
|
19
21
|
private isTrusted;
|
|
20
|
-
|
|
21
|
-
constructor(connection?: Connection);
|
|
22
|
+
constructor(connection?: Connection | undefined, hasConfigurationCapability?: boolean | undefined);
|
|
22
23
|
updateConfig(): void;
|
|
23
24
|
removeDocument(scopeUri: string): void;
|
|
24
25
|
getConfig<T>(section: string, scopeUri: string): Promise<T | Record<string, any>>;
|
|
@@ -26,7 +27,6 @@ export declare class ConfigManager {
|
|
|
26
27
|
getPrettierVSConfig(document: TextDocument): Promise<Record<string, any>>;
|
|
27
28
|
getTSFormatConfig(document: TextDocument, vscodeOptions?: FormattingOptions): Promise<FormatCodeSettings>;
|
|
28
29
|
getTSPreferences(document: TextDocument): Promise<UserPreferences>;
|
|
29
|
-
getTSInlayHintsPreferences(document: TextDocument): Promise<InlayHintsOptions>;
|
|
30
30
|
/**
|
|
31
31
|
* Return true if a plugin and an optional feature is enabled
|
|
32
32
|
*/
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConfigManager = exports.defaultLSConfig = void 0;
|
|
4
|
-
const typescript_1 = require("typescript");
|
|
5
4
|
const utils_1 = require("../../utils");
|
|
6
5
|
// The default language server configuration is used only in two cases:
|
|
7
6
|
// 1. When the client does not support `workspace/configuration` requests and as such, needs a global config
|
|
@@ -46,13 +45,14 @@ exports.defaultLSConfig = {
|
|
|
46
45
|
* For more info on this, see the [internal docs](../../../../../docs/internal/language-server/config.md)
|
|
47
46
|
*/
|
|
48
47
|
class ConfigManager {
|
|
49
|
-
constructor(connection) {
|
|
48
|
+
constructor(connection, hasConfigurationCapability) {
|
|
49
|
+
this.connection = connection;
|
|
50
|
+
this.hasConfigurationCapability = hasConfigurationCapability;
|
|
50
51
|
this.globalConfig = { astro: exports.defaultLSConfig };
|
|
51
52
|
this.documentSettings = {};
|
|
52
53
|
// If set to true, the next time we need a TypeScript language service, we'll rebuild it so it gets the new config
|
|
53
54
|
this.shouldRefreshTSServices = false;
|
|
54
55
|
this.isTrusted = true;
|
|
55
|
-
this.connection = connection;
|
|
56
56
|
}
|
|
57
57
|
updateConfig() {
|
|
58
58
|
// Reset all cached document settings
|
|
@@ -63,7 +63,7 @@ class ConfigManager {
|
|
|
63
63
|
delete this.documentSettings[scopeUri];
|
|
64
64
|
}
|
|
65
65
|
async getConfig(section, scopeUri) {
|
|
66
|
-
if (!this.connection) {
|
|
66
|
+
if (!this.connection || !this.hasConfigurationCapability) {
|
|
67
67
|
return (0, utils_1.get)(this.globalConfig, section) ?? {};
|
|
68
68
|
}
|
|
69
69
|
if (!this.documentSettings[scopeUri]) {
|
|
@@ -118,7 +118,7 @@ class ConfigManager {
|
|
|
118
118
|
insertSpaceAfterTypeAssertion: formatConfig.insertSpaceAfterTypeAssertion ?? false,
|
|
119
119
|
placeOpenBraceOnNewLineForFunctions: formatConfig.placeOpenBraceOnNewLineForFunctions ?? false,
|
|
120
120
|
placeOpenBraceOnNewLineForControlBlocks: formatConfig.placeOpenBraceOnNewLineForControlBlocks ?? false,
|
|
121
|
-
semicolons: formatConfig.semicolons ??
|
|
121
|
+
semicolons: formatConfig.semicolons ?? 'ignore',
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
async getTSPreferences(document) {
|
|
@@ -136,13 +136,7 @@ class ConfigManager {
|
|
|
136
136
|
includeCompletionsForModuleExports: config.suggest?.autoImports ?? true,
|
|
137
137
|
allowIncompleteCompletions: true,
|
|
138
138
|
includeCompletionsWithInsertText: true,
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
async getTSInlayHintsPreferences(document) {
|
|
142
|
-
const config = (await this.getConfig('typescript', document.uri)) ?? {};
|
|
143
|
-
const tsPreferences = this.getTSPreferences(document);
|
|
144
|
-
return {
|
|
145
|
-
...tsPreferences,
|
|
139
|
+
// Inlay Hints
|
|
146
140
|
includeInlayParameterNameHints: getInlayParameterNameHintsPreference(config),
|
|
147
141
|
includeInlayParameterNameHintsWhenArgumentMatchesName: !(config.inlayHints?.parameterNames?.suppressWhenArgumentMatchesName ?? true),
|
|
148
142
|
includeInlayFunctionParameterTypeHints: config.inlayHints?.parameterTypes?.enabled ?? false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HTMLDocument, Range } from 'vscode-html-languageservice';
|
|
1
|
+
import type { HTMLDocument, Range } from 'vscode-html-languageservice';
|
|
2
2
|
import { WritableDocument } from './DocumentBase';
|
|
3
3
|
import { AstroMetadata } from './parseAstro';
|
|
4
4
|
import { TagInformation } from './utils';
|
|
@@ -16,7 +16,7 @@ class AstroDocument extends DocumentBase_1.WritableDocument {
|
|
|
16
16
|
}
|
|
17
17
|
updateDocInfo() {
|
|
18
18
|
this.astroMeta = (0, parseAstro_1.parseAstro)(this.content);
|
|
19
|
-
this.html = (0, parseHtml_1.parseHtml)(this.content);
|
|
19
|
+
this.html = (0, parseHtml_1.parseHtml)(this.content, this.astroMeta);
|
|
20
20
|
this.styleTags = (0, utils_2.extractStyleTags)(this.content, this.html);
|
|
21
21
|
this.scriptTags = (0, utils_2.extractScriptTags)(this.content, this.html);
|
|
22
22
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Position } from 'vscode-languageserver';
|
|
2
|
-
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
1
|
+
import type { Position } from 'vscode-languageserver';
|
|
2
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
3
|
/**
|
|
4
4
|
* Represents a textual document.
|
|
5
5
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TextDocumentContentChangeEvent, TextDocumentItem, VersionedTextDocumentIdentifier } from 'vscode-languageserver';
|
|
1
|
+
import type { TextDocumentContentChangeEvent, TextDocumentItem, VersionedTextDocumentIdentifier } from 'vscode-languageserver';
|
|
2
2
|
import { AstroDocument } from './AstroDocument';
|
|
3
3
|
export declare type DocumentEvent = 'documentOpen' | 'documentChange' | 'documentClose';
|
|
4
4
|
export declare class DocumentManager {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DocumentManager = void 0;
|
|
4
4
|
const events_1 = require("events");
|
|
5
|
-
const AstroDocument_1 = require("./AstroDocument");
|
|
6
5
|
const utils_1 = require("../../utils");
|
|
6
|
+
const AstroDocument_1 = require("./AstroDocument");
|
|
7
7
|
class DocumentManager {
|
|
8
8
|
constructor(createDocument) {
|
|
9
9
|
this.createDocument = createDocument;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SourceMapConsumer } from 'source-map';
|
|
2
|
+
import { CodeAction, ColorPresentation, CompletionItem, Diagnostic, FoldingRange, Hover, InsertReplaceEdit, LocationLink, Position, Range, SelectionRange, SymbolInformation, TextDocumentEdit, TextEdit } from 'vscode-languageserver';
|
|
2
3
|
import { TagInformation } from './utils';
|
|
3
|
-
import { SourceMapConsumer } from 'source-map';
|
|
4
4
|
export interface DocumentMapper {
|
|
5
5
|
/**
|
|
6
6
|
* Map the generated position to the original position
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { HTMLDocument, Position } from 'vscode-html-languageservice';
|
|
2
|
-
import { AstroDocument } from './AstroDocument';
|
|
2
|
+
import type { AstroDocument } from './AstroDocument';
|
|
3
|
+
import { AstroMetadata } from './parseAstro';
|
|
3
4
|
/**
|
|
4
5
|
* Parses text as HTML
|
|
5
6
|
*/
|
|
6
|
-
export declare function parseHtml(text: string): HTMLDocument;
|
|
7
|
+
export declare function parseHtml(text: string, frontmatter: AstroMetadata): HTMLDocument;
|
|
7
8
|
export interface AttributeContext {
|
|
8
9
|
name: string;
|
|
9
10
|
inValue: boolean;
|
|
@@ -7,8 +7,8 @@ const parser = (0, vscode_html_languageservice_1.getLanguageService)();
|
|
|
7
7
|
/**
|
|
8
8
|
* Parses text as HTML
|
|
9
9
|
*/
|
|
10
|
-
function parseHtml(text) {
|
|
11
|
-
const preprocessed = preprocess(text);
|
|
10
|
+
function parseHtml(text, frontmatter) {
|
|
11
|
+
const preprocessed = preprocess(text, frontmatter);
|
|
12
12
|
// We can safely only set getText because only this is used for parsing
|
|
13
13
|
const parsedDoc = parser.parseHTMLDocument({ getText: () => preprocessed });
|
|
14
14
|
return parsedDoc;
|
|
@@ -18,12 +18,18 @@ const createScanner = parser.createScanner;
|
|
|
18
18
|
/**
|
|
19
19
|
* scan the text and remove any `>` or `<` that cause the tag to end short,
|
|
20
20
|
*/
|
|
21
|
-
function preprocess(text) {
|
|
21
|
+
function preprocess(text, frontmatter) {
|
|
22
22
|
let scanner = createScanner(text);
|
|
23
23
|
let token = scanner.scan();
|
|
24
24
|
let currentStartTagStart = null;
|
|
25
|
+
const hasFrontmatter = frontmatter !== undefined;
|
|
25
26
|
while (token !== vscode_html_languageservice_1.TokenType.EOS) {
|
|
26
27
|
const offset = scanner.getTokenOffset();
|
|
28
|
+
if (hasFrontmatter &&
|
|
29
|
+
(scanner.getTokenText() === '>' || scanner.getTokenText() === '<') &&
|
|
30
|
+
offset < (frontmatter.content.firstNonWhitespaceOffset ?? 0)) {
|
|
31
|
+
blankStartOrEndTagLike(offset, vscode_html_languageservice_1.ScannerState.WithinContent);
|
|
32
|
+
}
|
|
27
33
|
if (token === vscode_html_languageservice_1.TokenType.StartTagOpen) {
|
|
28
34
|
currentStartTagStart = offset;
|
|
29
35
|
}
|
|
@@ -46,6 +52,7 @@ function preprocess(text) {
|
|
|
46
52
|
shouldBlankStartOrEndTagLike(offset)) {
|
|
47
53
|
blankStartOrEndTagLike(offset);
|
|
48
54
|
}
|
|
55
|
+
// TODO: Handle TypeScript generics inside expressions / Use the compiler to parse HTML instead?
|
|
49
56
|
token = scanner.scan();
|
|
50
57
|
}
|
|
51
58
|
return text;
|
|
@@ -53,9 +60,9 @@ function preprocess(text) {
|
|
|
53
60
|
// not null rather than falsy, otherwise it won't work on first tag(0)
|
|
54
61
|
return currentStartTagStart !== null && (0, utils_1.isInsideExpression)(text, currentStartTagStart, offset);
|
|
55
62
|
}
|
|
56
|
-
function blankStartOrEndTagLike(offset) {
|
|
63
|
+
function blankStartOrEndTagLike(offset, state) {
|
|
57
64
|
text = text.substring(0, offset) + ' ' + text.substring(offset + 1);
|
|
58
|
-
scanner = createScanner(text, offset, vscode_html_languageservice_1.ScannerState.WithinTag);
|
|
65
|
+
scanner = createScanner(text, offset, state ?? vscode_html_languageservice_1.ScannerState.WithinTag);
|
|
59
66
|
}
|
|
60
67
|
}
|
|
61
68
|
function getAttributeContextAtPosition(document, position) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { HTMLDocument, Node } from 'vscode-html-languageservice';
|
|
1
2
|
import { Position } from 'vscode-languageserver';
|
|
2
|
-
import { HTMLDocument, Node } from 'vscode-html-languageservice';
|
|
3
3
|
export interface TagInformation {
|
|
4
4
|
content: string;
|
|
5
5
|
attributes: Record<string, string>;
|
|
@@ -14,8 +14,8 @@ export interface TagInformation {
|
|
|
14
14
|
closed: boolean;
|
|
15
15
|
}
|
|
16
16
|
export declare function walk(node: Node): Generator<Node, void, unknown>;
|
|
17
|
-
export declare function extractStyleTags(source: string, html
|
|
18
|
-
export declare function extractScriptTags(source: string, html
|
|
17
|
+
export declare function extractStyleTags(source: string, html: HTMLDocument): TagInformation[];
|
|
18
|
+
export declare function extractScriptTags(source: string, html: HTMLDocument): TagInformation[];
|
|
19
19
|
export declare function getLineAtPosition(position: Position, text: string): string;
|
|
20
20
|
/**
|
|
21
21
|
* Return if a given offset is inside the start tag of a component
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getFirstNonWhitespaceIndex = exports.getLineOffsets = exports.offsetAt = exports.positionAt = exports.isInsideFrontmatter = exports.isInsideExpression = exports.isInTag = exports.isPossibleComponent = exports.isInTagName = exports.isInComponentStartTag = exports.getLineAtPosition = exports.extractScriptTags = exports.extractStyleTags = exports.walk = void 0;
|
|
4
4
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
|
-
const parseHtml_1 = require("./parseHtml");
|
|
7
6
|
function* walk(node) {
|
|
8
7
|
for (let child of node.children) {
|
|
9
8
|
yield* walk(child);
|
|
@@ -19,7 +18,7 @@ exports.walk = walk;
|
|
|
19
18
|
* @param tag the tag to extract
|
|
20
19
|
*/
|
|
21
20
|
function extractTags(text, tag, html) {
|
|
22
|
-
const rootNodes = html
|
|
21
|
+
const rootNodes = html.roots;
|
|
23
22
|
const matchedNodes = rootNodes.filter((node) => node.tag === tag);
|
|
24
23
|
if (tag === 'style' && !matchedNodes.length && rootNodes.length) {
|
|
25
24
|
for (let child of walk(rootNodes[0])) {
|
package/dist/node.js
CHANGED
|
@@ -26,4 +26,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
const vscode = __importStar(require("vscode-languageserver/node"));
|
|
27
27
|
const server_1 = require("./server");
|
|
28
28
|
const connection = vscode.createConnection(vscode.ProposedFeatures.all);
|
|
29
|
-
(0, server_1.startLanguageServer)(connection
|
|
29
|
+
(0, server_1.startLanguageServer)(connection, {
|
|
30
|
+
loadTypescript(options) {
|
|
31
|
+
if (options?.typescript?.serverPath) {
|
|
32
|
+
return require(options?.typescript?.serverPath);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
loadTypescriptLocalized(options) {
|
|
36
|
+
if (options?.typescript?.localizedPath) {
|
|
37
|
+
try {
|
|
38
|
+
return require(options?.typescript?.localizedPath);
|
|
39
|
+
}
|
|
40
|
+
catch { }
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CancellationToken, Color, ColorInformation, ColorPresentation, CompletionContext, CompletionItem, CompletionList, DefinitionLink, Diagnostic, FoldingRange, Hover,
|
|
1
|
+
import { CancellationToken, CodeAction, CodeActionContext, Color, ColorInformation, ColorPresentation, CompletionContext, CompletionItem, CompletionList, DefinitionLink, Diagnostic, FoldingRange, FormattingOptions, Hover, InlayHint, LinkedEditingRanges, Location, Position, Range, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, TextDocumentIdentifier, TextEdit, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
|
+
import type { DocumentManager } from '../core/documents/DocumentManager';
|
|
2
3
|
import type { AppCompletionItem, Plugin } from './interfaces';
|
|
3
|
-
import { DocumentManager } from '../core/documents/DocumentManager';
|
|
4
4
|
export interface PluginHostConfig {
|
|
5
5
|
filterIncompleteCompletions: boolean;
|
|
6
6
|
definitionLinkSupport: boolean;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PluginHost = void 0;
|
|
4
4
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
5
|
const documents_1 = require("../core/documents");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
7
|
var ExecuteMode;
|
|
8
8
|
(function (ExecuteMode) {
|
|
9
9
|
ExecuteMode[ExecuteMode["None"] = 0] = "None";
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { CompletionContext, FoldingRange, Position, TextEdit
|
|
2
|
-
import { ConfigManager } from '../../core/config';
|
|
3
|
-
import { AstroDocument } from '../../core/documents';
|
|
4
|
-
import { AppCompletionList, Plugin } from '../interfaces';
|
|
5
|
-
import { LanguageServiceManager } from '../typescript/LanguageServiceManager';
|
|
1
|
+
import { CompletionContext, FoldingRange, FormattingOptions, Position, TextEdit } from 'vscode-languageserver';
|
|
2
|
+
import type { ConfigManager } from '../../core/config';
|
|
3
|
+
import type { AstroDocument } from '../../core/documents';
|
|
4
|
+
import type { AppCompletionList, Plugin } from '../interfaces';
|
|
5
|
+
import type { LanguageServiceManager } from '../typescript/LanguageServiceManager';
|
|
6
6
|
export declare class AstroPlugin implements Plugin {
|
|
7
7
|
__name: string;
|
|
8
8
|
private configManager;
|
|
9
9
|
private readonly languageServiceManager;
|
|
10
|
+
private readonly ts;
|
|
10
11
|
private readonly completionProvider;
|
|
11
12
|
constructor(configManager: ConfigManager, languageServiceManager: LanguageServiceManager);
|
|
12
13
|
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList | null>;
|
|
@@ -9,6 +9,7 @@ class AstroPlugin {
|
|
|
9
9
|
this.__name = 'astro';
|
|
10
10
|
this.configManager = configManager;
|
|
11
11
|
this.languageServiceManager = languageServiceManager;
|
|
12
|
+
this.ts = languageServiceManager.docContext.ts;
|
|
12
13
|
this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(this.languageServiceManager);
|
|
13
14
|
}
|
|
14
15
|
async getCompletions(document, position, completionContext) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { AppCompletionList, CompletionsProvider } from '../../interfaces';
|
|
2
|
-
import type { AstroDocument } from '../../../core/documents';
|
|
3
1
|
import { CompletionContext, Position } from 'vscode-languageserver';
|
|
4
|
-
import {
|
|
2
|
+
import type { AstroDocument } from '../../../core/documents';
|
|
3
|
+
import type { AppCompletionList, CompletionsProvider } from '../../interfaces';
|
|
4
|
+
import type { LanguageServiceManager as TypeScriptLanguageServiceManager } from '../../typescript/LanguageServiceManager';
|
|
5
5
|
export declare class CompletionsProviderImpl implements CompletionsProvider {
|
|
6
6
|
private readonly languageServiceManager;
|
|
7
|
+
private readonly ts;
|
|
7
8
|
private lastCompletion;
|
|
8
9
|
directivesHTMLLang: import("vscode-html-languageservice").LanguageService;
|
|
9
10
|
constructor(languageServiceManager: TypeScriptLanguageServiceManager);
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.CompletionsProviderImpl = void 0;
|
|
4
|
+
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
7
5
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
8
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
9
6
|
const utils_1 = require("../../../core/documents/utils");
|
|
10
|
-
const utils_2 = require("../../typescript/utils");
|
|
11
|
-
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
12
7
|
const astro_attributes_1 = require("../../html/features/astro-attributes");
|
|
13
|
-
const
|
|
8
|
+
const utils_2 = require("../../html/utils");
|
|
9
|
+
const utils_3 = require("../../typescript/utils");
|
|
14
10
|
class CompletionsProviderImpl {
|
|
15
11
|
constructor(languageServiceManager) {
|
|
16
12
|
this.lastCompletion = null;
|
|
@@ -19,6 +15,7 @@ class CompletionsProviderImpl {
|
|
|
19
15
|
useDefaultDataProvider: false,
|
|
20
16
|
});
|
|
21
17
|
this.languageServiceManager = languageServiceManager;
|
|
18
|
+
this.ts = languageServiceManager.docContext.ts;
|
|
22
19
|
}
|
|
23
20
|
async getCompletions(document, position, completionContext) {
|
|
24
21
|
let items = [];
|
|
@@ -38,7 +35,7 @@ class CompletionsProviderImpl {
|
|
|
38
35
|
}
|
|
39
36
|
const isAstro = componentFilePath?.endsWith('.astro');
|
|
40
37
|
if (!isAstro) {
|
|
41
|
-
const directives = (0,
|
|
38
|
+
const directives = (0, utils_2.removeDataAttrCompletion)(this.directivesHTMLLang.doComplete(document, position, html).items);
|
|
42
39
|
items.push(...directives);
|
|
43
40
|
}
|
|
44
41
|
}
|
|
@@ -105,7 +102,7 @@ class CompletionsProviderImpl {
|
|
|
105
102
|
const componentName = node.tag;
|
|
106
103
|
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
107
104
|
// Get the source file
|
|
108
|
-
const tsFilePath = (0,
|
|
105
|
+
const tsFilePath = (0, utils_3.toVirtualAstroFilePath)(tsDoc.filePath);
|
|
109
106
|
const program = lang.getProgram();
|
|
110
107
|
const sourceFile = program?.getSourceFile(tsFilePath);
|
|
111
108
|
const typeChecker = program?.getTypeChecker();
|
|
@@ -157,12 +154,12 @@ class CompletionsProviderImpl {
|
|
|
157
154
|
getImportedSymbol(sourceFile, identifier) {
|
|
158
155
|
for (let list of sourceFile.getChildren()) {
|
|
159
156
|
for (let node of list.getChildren()) {
|
|
160
|
-
if (
|
|
157
|
+
if (this.ts.isImportDeclaration(node)) {
|
|
161
158
|
let clauses = node.importClause;
|
|
162
159
|
if (!clauses)
|
|
163
160
|
return null;
|
|
164
161
|
let namedImport = clauses.getChildAt(0);
|
|
165
|
-
if (
|
|
162
|
+
if (this.ts.isNamedImports(namedImport)) {
|
|
166
163
|
for (let imp of namedImport.elements) {
|
|
167
164
|
// Iterate the named imports
|
|
168
165
|
if (imp.name.getText() === identifier) {
|
|
@@ -170,7 +167,7 @@ class CompletionsProviderImpl {
|
|
|
170
167
|
}
|
|
171
168
|
}
|
|
172
169
|
}
|
|
173
|
-
else if (
|
|
170
|
+
else if (this.ts.isIdentifier(namedImport)) {
|
|
174
171
|
if (namedImport.getText() === identifier) {
|
|
175
172
|
return namedImport;
|
|
176
173
|
}
|
|
@@ -182,9 +179,9 @@ class CompletionsProviderImpl {
|
|
|
182
179
|
}
|
|
183
180
|
getPropType(declarations, typeChecker) {
|
|
184
181
|
for (const decl of declarations) {
|
|
185
|
-
const fileName = (0,
|
|
182
|
+
const fileName = (0, utils_3.toVirtualFilePath)(decl.getSourceFile().fileName);
|
|
186
183
|
if (fileName.endsWith('.tsx') || fileName.endsWith('.jsx') || fileName.endsWith('.d.ts')) {
|
|
187
|
-
if (!
|
|
184
|
+
if (!this.ts.isFunctionDeclaration(decl) && !this.ts.isFunctionTypeNode(decl)) {
|
|
188
185
|
console.error(`We only support functions declarations at the moment`);
|
|
189
186
|
continue;
|
|
190
187
|
}
|
|
@@ -221,7 +218,7 @@ class CompletionsProviderImpl {
|
|
|
221
218
|
// Ensure that props shows up first as a completion, despite this plugin being ran after the HTML one
|
|
222
219
|
sortText: '\0',
|
|
223
220
|
};
|
|
224
|
-
if (mem.flags &
|
|
221
|
+
if (mem.flags & this.ts.SymbolFlags.Optional) {
|
|
225
222
|
item.filterText = item.label;
|
|
226
223
|
item.label += '?';
|
|
227
224
|
// Put optional props at a lower priority
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Stylesheet, TextDocument } from 'vscode-css-languageservice';
|
|
2
|
-
import { Position } from 'vscode-languageserver';
|
|
1
|
+
import type { Stylesheet, TextDocument } from 'vscode-css-languageservice';
|
|
2
|
+
import type { Position } from 'vscode-languageserver';
|
|
3
3
|
import { AstroDocument, DocumentMapper, ReadableDocument, TagInformation } from '../../core/documents';
|
|
4
4
|
export interface CSSDocumentBase extends DocumentMapper, TextDocument {
|
|
5
5
|
languageId: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CSSDocument = void 0;
|
|
4
|
-
const language_service_1 = require("./language-service");
|
|
5
4
|
const documents_1 = require("../../core/documents");
|
|
5
|
+
const language_service_1 = require("./language-service");
|
|
6
6
|
class CSSDocument extends documents_1.ReadableDocument {
|
|
7
7
|
constructor(parent, styleInfo) {
|
|
8
8
|
super();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Color, ColorInformation, ColorPresentation, CompletionContext, CompletionList, FoldingRange, Hover, Position, Range, SymbolInformation } from 'vscode-languageserver';
|
|
2
|
-
import { ConfigManager } from '../../core/config/ConfigManager';
|
|
2
|
+
import type { ConfigManager } from '../../core/config/ConfigManager';
|
|
3
3
|
import { AstroDocument } from '../../core/documents';
|
|
4
4
|
import type { Plugin } from '../interfaces';
|
|
5
5
|
export declare class CSSPlugin implements Plugin {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CSSPlugin = void 0;
|
|
4
|
+
const emmet_helper_1 = require("@vscode/emmet-helper");
|
|
4
5
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
5
6
|
const documents_1 = require("../../core/documents");
|
|
6
|
-
const
|
|
7
|
+
const parseHtml_1 = require("../../core/documents/parseHtml");
|
|
7
8
|
const CSSDocument_1 = require("./CSSDocument");
|
|
9
|
+
const getIdClassCompletions_1 = require("./features/getIdClassCompletions");
|
|
8
10
|
const language_service_1 = require("./language-service");
|
|
9
|
-
const parseHtml_1 = require("../../core/documents/parseHtml");
|
|
10
11
|
const StyleAttributeDocument_1 = require("./StyleAttributeDocument");
|
|
11
|
-
const getIdClassCompletions_1 = require("./features/getIdClassCompletions");
|
|
12
12
|
class CSSPlugin {
|
|
13
13
|
constructor(configManager) {
|
|
14
14
|
this.__name = 'css';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Stylesheet } from 'vscode-css-languageservice';
|
|
2
|
-
import { Position } from 'vscode-languageserver';
|
|
1
|
+
import type { Stylesheet } from 'vscode-css-languageservice';
|
|
2
|
+
import type { Position } from 'vscode-languageserver';
|
|
3
3
|
import { AstroDocument, DocumentMapper, ReadableDocument } from '../../core/documents';
|
|
4
4
|
export declare class StyleAttributeDocument extends ReadableDocument implements DocumentMapper {
|
|
5
5
|
private readonly parent;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StyleAttributeDocument = void 0;
|
|
4
|
-
const language_service_1 = require("./language-service");
|
|
5
4
|
const documents_1 = require("../../core/documents");
|
|
5
|
+
const language_service_1 = require("./language-service");
|
|
6
6
|
const PREFIX = '__ {';
|
|
7
7
|
const SUFFIX = '}';
|
|
8
8
|
class StyleAttributeDocument extends documents_1.ReadableDocument {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IPseudoClassData } from 'vscode-css-languageservice';
|
|
1
|
+
import type { IPseudoClassData } from 'vscode-css-languageservice';
|
|
2
2
|
export declare const pseudoClass: IPseudoClassData[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { Stylesheet } from 'vscode-css-languageservice';
|
|
1
2
|
import { CompletionItem, CompletionList } from 'vscode-languageserver';
|
|
2
|
-
import { AttributeContext } from '../../../core/documents/parseHtml';
|
|
3
|
-
import { Stylesheet } from 'vscode-css-languageservice';
|
|
3
|
+
import type { AttributeContext } from '../../../core/documents/parseHtml';
|
|
4
4
|
export declare function getIdClassCompletion(stylesheets: Stylesheet[], attributeContext: AttributeContext): CompletionList | null;
|
|
5
5
|
/**
|
|
6
6
|
* incomplete see
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CompletionList,
|
|
1
|
+
import { CompletionList, FoldingRange, Hover, LinkedEditingRanges, Position, SymbolInformation } from 'vscode-languageserver';
|
|
2
|
+
import type { ConfigManager } from '../../core/config/ConfigManager';
|
|
3
|
+
import type { AstroDocument } from '../../core/documents/AstroDocument';
|
|
2
4
|
import type { Plugin } from '../interfaces';
|
|
3
|
-
import { ConfigManager } from '../../core/config/ConfigManager';
|
|
4
|
-
import { AstroDocument } from '../../core/documents/AstroDocument';
|
|
5
5
|
export declare class HTMLPlugin implements Plugin {
|
|
6
6
|
__name: string;
|
|
7
7
|
private lang;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HTMLPlugin = void 0;
|
|
4
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
5
4
|
const emmet_helper_1 = require("@vscode/emmet-helper");
|
|
6
5
|
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
6
|
+
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
7
7
|
const utils_1 = require("../../core/documents/utils");
|
|
8
8
|
const astro_attributes_1 = require("./features/astro-attributes");
|
|
9
9
|
const utils_2 = require("./utils");
|