@astrojs/language-server 0.13.1 → 0.13.4
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 +22 -0
- package/dist/core/documents/DocumentMapper.d.ts +2 -1
- package/dist/core/documents/DocumentMapper.js +8 -1
- package/dist/core/documents/utils.d.ts +1 -0
- package/dist/core/documents/utils.js +2 -0
- package/dist/plugins/PluginHost.d.ts +2 -1
- package/dist/plugins/PluginHost.js +4 -0
- package/dist/plugins/astro/AstroPlugin.d.ts +1 -1
- package/dist/plugins/astro/AstroPlugin.js +1 -1
- package/dist/plugins/astro/features/CompletionsProvider.d.ts +5 -6
- package/dist/plugins/astro/features/CompletionsProvider.js +50 -59
- package/dist/plugins/css/CSSPlugin.d.ts +2 -1
- package/dist/plugins/css/CSSPlugin.js +27 -28
- package/dist/plugins/css/features/astro-selectors.js +1 -2
- package/dist/plugins/html/HTMLPlugin.d.ts +1 -0
- package/dist/plugins/html/HTMLPlugin.js +8 -3
- package/dist/plugins/html/features/astro-attributes.d.ts +1 -0
- package/dist/plugins/html/features/astro-attributes.js +67 -3
- package/dist/plugins/html/utils.d.ts +6 -0
- package/dist/plugins/html/utils.js +11 -0
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +3 -1
- package/dist/plugins/typescript/TypeScriptPlugin.js +8 -0
- package/dist/plugins/typescript/features/DocumentSymbolsProvider.js +6 -3
- package/dist/plugins/typescript/features/SemanticTokenProvider.d.ts +15 -0
- package/dist/plugins/typescript/features/SemanticTokenProvider.js +81 -0
- package/dist/plugins/typescript/language-service.js +1 -1
- package/dist/plugins/typescript/snapshots/SnapshotManager.js +2 -1
- package/dist/plugins/typescript/utils.d.ts +24 -1
- package/dist/plugins/typescript/utils.js +32 -1
- package/dist/server.js +11 -2
- package/dist/utils.d.ts +0 -5
- package/dist/utils.js +1 -16
- package/package.json +3 -3
- package/types/astro-jsx.d.ts +112 -113
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeDataAttrCompletion = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The VS Code HTML language service provides a completion for data attributes that is independent from
|
|
6
|
+
* data providers, which mean that you can't disable it, so this function removes them from completions
|
|
7
|
+
*/
|
|
8
|
+
function removeDataAttrCompletion(items) {
|
|
9
|
+
return items.filter((item) => !item.label.startsWith('data-'));
|
|
10
|
+
}
|
|
11
|
+
exports.removeDataAttrCompletion = removeDataAttrCompletion;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CancellationToken, CompletionContext, DefinitionLink, Diagnostic, Hover, Position, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, WorkspaceEdit } from 'vscode-languageserver';
|
|
1
|
+
import { CancellationToken, CompletionContext, DefinitionLink, Diagnostic, Hover, Position, Range, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
2
|
import { ConfigManager } from '../../core/config';
|
|
3
3
|
import { AstroDocument, DocumentManager } from '../../core/documents';
|
|
4
4
|
import { AppCompletionItem, AppCompletionList, OnWatchFileChangesParam, Plugin } from '../interfaces';
|
|
@@ -12,9 +12,11 @@ export declare class TypeScriptPlugin implements Plugin {
|
|
|
12
12
|
private readonly signatureHelpProvider;
|
|
13
13
|
private readonly diagnosticsProvider;
|
|
14
14
|
private readonly documentSymbolsProvider;
|
|
15
|
+
private readonly semanticTokensProvider;
|
|
15
16
|
constructor(docManager: DocumentManager, configManager: ConfigManager, workspaceUris: string[]);
|
|
16
17
|
doHover(document: AstroDocument, position: Position): Promise<Hover | null>;
|
|
17
18
|
rename(document: AstroDocument, position: Position, newName: string): Promise<WorkspaceEdit | null>;
|
|
19
|
+
getSemanticTokens(textDocument: AstroDocument, range?: Range, cancellationToken?: CancellationToken): Promise<SemanticTokens | null>;
|
|
18
20
|
getDocumentSymbols(document: AstroDocument): Promise<SymbolInformation[]>;
|
|
19
21
|
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext): Promise<AppCompletionList<CompletionEntryWithIdentifer> | null>;
|
|
20
22
|
resolveCompletion(document: AstroDocument, completionItem: AppCompletionItem<CompletionEntryWithIdentifer>): Promise<AppCompletionItem<CompletionEntryWithIdentifer>>;
|
|
@@ -36,6 +36,7 @@ const utils_2 = require("./features/utils");
|
|
|
36
36
|
const LanguageServiceManager_1 = require("./LanguageServiceManager");
|
|
37
37
|
const utils_3 = require("./utils");
|
|
38
38
|
const DocumentSymbolsProvider_1 = require("./features/DocumentSymbolsProvider");
|
|
39
|
+
const SemanticTokenProvider_1 = require("./features/SemanticTokenProvider");
|
|
39
40
|
class TypeScriptPlugin {
|
|
40
41
|
constructor(docManager, configManager, workspaceUris) {
|
|
41
42
|
this.__name = 'typescript';
|
|
@@ -46,6 +47,7 @@ class TypeScriptPlugin {
|
|
|
46
47
|
this.signatureHelpProvider = new SignatureHelpProvider_1.SignatureHelpProviderImpl(this.languageServiceManager);
|
|
47
48
|
this.diagnosticsProvider = new DiagnosticsProvider_1.DiagnosticsProviderImpl(this.languageServiceManager);
|
|
48
49
|
this.documentSymbolsProvider = new DocumentSymbolsProvider_1.DocumentSymbolsProviderImpl(this.languageServiceManager);
|
|
50
|
+
this.semanticTokensProvider = new SemanticTokenProvider_1.SemanticTokensProviderImpl(this.languageServiceManager);
|
|
49
51
|
}
|
|
50
52
|
async doHover(document, position) {
|
|
51
53
|
if (!this.featureEnabled('hover')) {
|
|
@@ -76,6 +78,12 @@ class TypeScriptPlugin {
|
|
|
76
78
|
});
|
|
77
79
|
return edit;
|
|
78
80
|
}
|
|
81
|
+
async getSemanticTokens(textDocument, range, cancellationToken) {
|
|
82
|
+
if (!this.featureEnabled('semanticTokens')) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return this.semanticTokensProvider.getSemanticTokens(textDocument, range, cancellationToken);
|
|
86
|
+
}
|
|
79
87
|
async getDocumentSymbols(document) {
|
|
80
88
|
if (!this.featureEnabled('documentSymbols')) {
|
|
81
89
|
return [];
|
|
@@ -20,17 +20,20 @@ class DocumentSymbolsProviderImpl {
|
|
|
20
20
|
}
|
|
21
21
|
const symbols = [];
|
|
22
22
|
this.collectSymbols(navTree, fragment, undefined, (symbol) => symbols.push(symbol));
|
|
23
|
+
const originalContainerName = symbols[0].name;
|
|
23
24
|
const result = [];
|
|
24
25
|
// Add a "Frontmatter" namespace for the frontmatter if we have a closed one
|
|
25
26
|
if (document.astroMeta.frontmatter.state === 'closed') {
|
|
26
|
-
result.push(vscode_languageserver_types_1.SymbolInformation.create('Frontmatter', vscode_languageserver_types_1.SymbolKind.Namespace, vscode_languageserver_types_1.Range.create(document.positionAt(document.astroMeta.frontmatter.startOffset), document.positionAt(document.astroMeta.frontmatter.endOffset))));
|
|
27
|
+
result.push(vscode_languageserver_types_1.SymbolInformation.create('Frontmatter', vscode_languageserver_types_1.SymbolKind.Namespace, vscode_languageserver_types_1.Range.create(document.positionAt(document.astroMeta.frontmatter.startOffset), document.positionAt(document.astroMeta.frontmatter.endOffset)), document.getURL()));
|
|
27
28
|
}
|
|
28
29
|
// Add a "Template" namespace for everything under the frontmatter
|
|
29
|
-
result.push(vscode_languageserver_types_1.SymbolInformation.create('Template', vscode_languageserver_types_1.SymbolKind.Namespace, vscode_languageserver_types_1.Range.create(document.positionAt((_a = document.astroMeta.frontmatter.endOffset) !== null && _a !== void 0 ? _a : 0), document.positionAt(document.getTextLength()))));
|
|
30
|
+
result.push(vscode_languageserver_types_1.SymbolInformation.create('Template', vscode_languageserver_types_1.SymbolKind.Namespace, vscode_languageserver_types_1.Range.create(document.positionAt((_a = document.astroMeta.frontmatter.endOffset) !== null && _a !== void 0 ? _a : 0), document.positionAt(document.getTextLength())), document.getURL()));
|
|
30
31
|
for (let symbol of symbols.splice(1)) {
|
|
31
32
|
symbol = (0, documents_1.mapSymbolInformationToOriginal)(fragment, symbol);
|
|
32
33
|
if (document.offsetAt(symbol.location.range.end) >= ((_b = document.astroMeta.content.firstNonWhitespaceOffset) !== null && _b !== void 0 ? _b : 0)) {
|
|
33
|
-
symbol.containerName
|
|
34
|
+
if (symbol.containerName === originalContainerName) {
|
|
35
|
+
symbol.containerName = 'Template';
|
|
36
|
+
}
|
|
34
37
|
// For some reason, it seems like TypeScript thinks that the "class" attribute is a real class, weird
|
|
35
38
|
if (symbol.kind === vscode_languageserver_types_1.SymbolKind.Class && symbol.name === '<class>') {
|
|
36
39
|
const node = document.html.findNodeAt(document.offsetAt(symbol.location.range.start));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CancellationToken, Range, SemanticTokens } from 'vscode-languageserver';
|
|
2
|
+
import { AstroDocument } from '../../../core/documents';
|
|
3
|
+
import { SemanticTokensProvider } from '../../interfaces';
|
|
4
|
+
import { LanguageServiceManager } from '../LanguageServiceManager';
|
|
5
|
+
export declare class SemanticTokensProviderImpl implements SemanticTokensProvider {
|
|
6
|
+
private languageServiceManager;
|
|
7
|
+
constructor(languageServiceManager: LanguageServiceManager);
|
|
8
|
+
getSemanticTokens(document: AstroDocument, range?: Range, cancellationToken?: CancellationToken): Promise<SemanticTokens | null>;
|
|
9
|
+
private mapToOrigin;
|
|
10
|
+
/**
|
|
11
|
+
* TSClassification = (TokenType + 1) << TokenEncodingConsts.typeOffset + TokenModifier
|
|
12
|
+
*/
|
|
13
|
+
private getTokenTypeFromClassification;
|
|
14
|
+
private getTokenModifierFromClassification;
|
|
15
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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.SemanticTokensProviderImpl = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
9
|
+
const documents_1 = require("../../../core/documents");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
class SemanticTokensProviderImpl {
|
|
12
|
+
constructor(languageServiceManager) {
|
|
13
|
+
this.languageServiceManager = languageServiceManager;
|
|
14
|
+
}
|
|
15
|
+
async getSemanticTokens(document, range, cancellationToken) {
|
|
16
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
17
|
+
const fragment = (await tsDoc.createFragment());
|
|
18
|
+
if (cancellationToken === null || cancellationToken === void 0 ? void 0 : cancellationToken.isCancellationRequested) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const filePath = (0, utils_1.toVirtualAstroFilePath)(tsDoc.filePath);
|
|
22
|
+
const start = range ? fragment.offsetAt(fragment.getGeneratedPosition(range.start)) : 0;
|
|
23
|
+
const { spans } = lang.getEncodedSemanticClassifications(filePath, {
|
|
24
|
+
start,
|
|
25
|
+
length: range
|
|
26
|
+
? fragment.offsetAt(fragment.getGeneratedPosition(range.end)) - start
|
|
27
|
+
: // We don't want tokens for things added by astro2tsx
|
|
28
|
+
fragment.text.lastIndexOf('export default function (_props:') || fragment.text.length,
|
|
29
|
+
}, typescript_1.default.SemanticClassificationFormat.TwentyTwenty);
|
|
30
|
+
const tokens = [];
|
|
31
|
+
let i = 0;
|
|
32
|
+
while (i < spans.length) {
|
|
33
|
+
const offset = spans[i++];
|
|
34
|
+
const generatedLength = spans[i++];
|
|
35
|
+
const classification = spans[i++];
|
|
36
|
+
const originalPosition = this.mapToOrigin(document, fragment, offset, generatedLength);
|
|
37
|
+
if (!originalPosition) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const [line, character, length] = originalPosition;
|
|
41
|
+
const classificationType = this.getTokenTypeFromClassification(classification);
|
|
42
|
+
if (classificationType < 0) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const modifier = this.getTokenModifierFromClassification(classification);
|
|
46
|
+
tokens.push([line, character, length, classificationType, modifier]);
|
|
47
|
+
}
|
|
48
|
+
const sorted = tokens.sort((a, b) => {
|
|
49
|
+
const [lineA, charA] = a;
|
|
50
|
+
const [lineB, charB] = b;
|
|
51
|
+
return lineA - lineB || charA - charB;
|
|
52
|
+
});
|
|
53
|
+
const builder = new vscode_languageserver_1.SemanticTokensBuilder();
|
|
54
|
+
sorted.forEach((tokenData) => builder.push(...tokenData));
|
|
55
|
+
const build = builder.build();
|
|
56
|
+
return build;
|
|
57
|
+
}
|
|
58
|
+
mapToOrigin(document, fragment, generatedOffset, generatedLength) {
|
|
59
|
+
const range = {
|
|
60
|
+
start: fragment.positionAt(generatedOffset),
|
|
61
|
+
end: fragment.positionAt(generatedOffset + generatedLength),
|
|
62
|
+
};
|
|
63
|
+
const { start: startPosition, end: endPosition } = (0, documents_1.mapRangeToOriginal)(fragment, range);
|
|
64
|
+
if (startPosition.line < 0 || endPosition.line < 0) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const startOffset = document.offsetAt(startPosition);
|
|
68
|
+
const endOffset = document.offsetAt(endPosition);
|
|
69
|
+
return [startPosition.line, startPosition.character, endOffset - startOffset, startOffset];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* TSClassification = (TokenType + 1) << TokenEncodingConsts.typeOffset + TokenModifier
|
|
73
|
+
*/
|
|
74
|
+
getTokenTypeFromClassification(tsClassification) {
|
|
75
|
+
return (tsClassification >> 8 /* typeOffset */) - 1;
|
|
76
|
+
}
|
|
77
|
+
getTokenModifierFromClassification(tsClassification) {
|
|
78
|
+
return tsClassification & 255 /* modifierMask */;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.SemanticTokensProviderImpl = SemanticTokensProviderImpl;
|
|
@@ -64,7 +64,7 @@ async function getLanguageServiceForTsconfig(tsconfigPath, docContext) {
|
|
|
64
64
|
}
|
|
65
65
|
exports.getLanguageServiceForTsconfig = getLanguageServiceForTsconfig;
|
|
66
66
|
async function createLanguageService(tsconfigPath, docContext) {
|
|
67
|
-
const workspaceRoot = tsconfigPath ? (0, path_1.dirname)(tsconfigPath) :
|
|
67
|
+
const workspaceRoot = tsconfigPath ? (0, path_1.dirname)(tsconfigPath) : '';
|
|
68
68
|
// `raw` here represent the tsconfig merged with any extended config
|
|
69
69
|
const { compilerOptions, fileNames: files, raw: fullConfig } = getParsedTSConfig();
|
|
70
70
|
let projectVersion = 0;
|
|
@@ -185,7 +185,8 @@ class SnapshotManager {
|
|
|
185
185
|
if (date.getTime() - this.lastLogged.getTime() > 60000) {
|
|
186
186
|
this.lastLogged = date;
|
|
187
187
|
const projectFiles = this.getProjectFileNames();
|
|
188
|
-
|
|
188
|
+
let allFiles = Array.from(new Set([...projectFiles, ...this.getFileNames()]));
|
|
189
|
+
allFiles = allFiles.map((file) => (0, utils_2.ensureRealFilePath)(file));
|
|
189
190
|
console.log('SnapshotManager File Statistics:\n' +
|
|
190
191
|
`Project files: ${projectFiles.length}\n` +
|
|
191
192
|
`Astro files: ${allFiles.filter((name) => name.endsWith('.astro')).length}\n` +
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import { CompletionItemKind, DiagnosticSeverity, Position, Range, SymbolKind } from 'vscode-languageserver';
|
|
2
|
+
import { CompletionItemKind, DiagnosticSeverity, Position, Range, SymbolKind, SemanticTokensLegend } from 'vscode-languageserver';
|
|
3
3
|
import { SnapshotFragment } from './snapshots/DocumentSnapshot';
|
|
4
|
+
export declare const enum TokenType {
|
|
5
|
+
class = 0,
|
|
6
|
+
enum = 1,
|
|
7
|
+
interface = 2,
|
|
8
|
+
namespace = 3,
|
|
9
|
+
typeParameter = 4,
|
|
10
|
+
type = 5,
|
|
11
|
+
parameter = 6,
|
|
12
|
+
variable = 7,
|
|
13
|
+
enumMember = 8,
|
|
14
|
+
property = 9,
|
|
15
|
+
function = 10,
|
|
16
|
+
method = 11
|
|
17
|
+
}
|
|
18
|
+
export declare const enum TokenModifier {
|
|
19
|
+
declaration = 0,
|
|
20
|
+
static = 1,
|
|
21
|
+
async = 2,
|
|
22
|
+
readonly = 3,
|
|
23
|
+
defaultLibrary = 4,
|
|
24
|
+
local = 5
|
|
25
|
+
}
|
|
26
|
+
export declare function getSemanticTokenLegend(): SemanticTokensLegend;
|
|
4
27
|
export declare function symbolKindFromString(kind: string): SymbolKind;
|
|
5
28
|
export declare function scriptElementKindToCompletionItemKind(kind: ts.ScriptElementKind): CompletionItemKind;
|
|
6
29
|
export declare function getCommitCharactersForScriptElement(kind: ts.ScriptElementKind): string[] | undefined;
|
|
@@ -3,12 +3,43 @@ 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.convertToLocationRange = exports.convertRange = exports.mapSeverity = exports.getScriptKindFromFileName = exports.isSubPath = exports.findTsConfigPath = exports.getExtensionFromScriptKind = exports.getCommitCharactersForScriptElement = exports.scriptElementKindToCompletionItemKind = exports.symbolKindFromString = void 0;
|
|
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.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");
|
|
10
10
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
11
11
|
const documents_1 = require("../../core/documents");
|
|
12
|
+
function getSemanticTokenLegend() {
|
|
13
|
+
const tokenModifiers = [];
|
|
14
|
+
[
|
|
15
|
+
[0 /* declaration */, vscode_languageserver_1.SemanticTokenModifiers.declaration],
|
|
16
|
+
[1 /* static */, vscode_languageserver_1.SemanticTokenModifiers.static],
|
|
17
|
+
[2 /* async */, vscode_languageserver_1.SemanticTokenModifiers.async],
|
|
18
|
+
[3 /* readonly */, vscode_languageserver_1.SemanticTokenModifiers.readonly],
|
|
19
|
+
[4 /* defaultLibrary */, vscode_languageserver_1.SemanticTokenModifiers.defaultLibrary],
|
|
20
|
+
[5 /* local */, 'local'],
|
|
21
|
+
].forEach(([tsModifier, legend]) => (tokenModifiers[tsModifier] = legend));
|
|
22
|
+
const tokenTypes = [];
|
|
23
|
+
[
|
|
24
|
+
[0 /* class */, vscode_languageserver_1.SemanticTokenTypes.class],
|
|
25
|
+
[1 /* enum */, vscode_languageserver_1.SemanticTokenTypes.enum],
|
|
26
|
+
[2 /* interface */, vscode_languageserver_1.SemanticTokenTypes.interface],
|
|
27
|
+
[3 /* namespace */, vscode_languageserver_1.SemanticTokenTypes.namespace],
|
|
28
|
+
[4 /* typeParameter */, vscode_languageserver_1.SemanticTokenTypes.typeParameter],
|
|
29
|
+
[5 /* type */, vscode_languageserver_1.SemanticTokenTypes.type],
|
|
30
|
+
[6 /* parameter */, vscode_languageserver_1.SemanticTokenTypes.parameter],
|
|
31
|
+
[7 /* variable */, vscode_languageserver_1.SemanticTokenTypes.variable],
|
|
32
|
+
[8 /* enumMember */, vscode_languageserver_1.SemanticTokenTypes.enumMember],
|
|
33
|
+
[9 /* property */, vscode_languageserver_1.SemanticTokenTypes.property],
|
|
34
|
+
[10 /* function */, vscode_languageserver_1.SemanticTokenTypes.function],
|
|
35
|
+
[11 /* method */, vscode_languageserver_1.SemanticTokenTypes.method],
|
|
36
|
+
].forEach(([tokenType, legend]) => (tokenTypes[tokenType] = legend));
|
|
37
|
+
return {
|
|
38
|
+
tokenModifiers,
|
|
39
|
+
tokenTypes,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.getSemanticTokenLegend = getSemanticTokenLegend;
|
|
12
43
|
function symbolKindFromString(kind) {
|
|
13
44
|
switch (kind) {
|
|
14
45
|
case 'module':
|
package/dist/server.js
CHANGED
|
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.startLanguageServer = void 0;
|
|
27
27
|
const vscode = __importStar(require("vscode-languageserver"));
|
|
28
|
+
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
28
29
|
const ConfigManager_1 = require("./core/config/ConfigManager");
|
|
29
30
|
const DocumentManager_1 = require("./core/documents/DocumentManager");
|
|
30
31
|
const DiagnosticsManager_1 = require("./core/DiagnosticsManager");
|
|
@@ -32,8 +33,9 @@ const AstroPlugin_1 = require("./plugins/astro/AstroPlugin");
|
|
|
32
33
|
const CSSPlugin_1 = require("./plugins/css/CSSPlugin");
|
|
33
34
|
const HTMLPlugin_1 = require("./plugins/html/HTMLPlugin");
|
|
34
35
|
const PluginHost_1 = require("./plugins/PluginHost");
|
|
35
|
-
const
|
|
36
|
+
const plugins_1 = require("./plugins");
|
|
36
37
|
const utils_1 = require("./utils");
|
|
38
|
+
const utils_2 = require("./plugins/typescript/utils");
|
|
37
39
|
const TagCloseRequest = new vscode.RequestType('html/tag');
|
|
38
40
|
// Start the language server
|
|
39
41
|
function startLanguageServer(connection) {
|
|
@@ -54,7 +56,7 @@ function startLanguageServer(connection) {
|
|
|
54
56
|
// We don't currently support running the TypeScript and Astro plugin in the browser
|
|
55
57
|
if (params.initializationOptions.environment !== 'browser') {
|
|
56
58
|
pluginHost.registerPlugin(new AstroPlugin_1.AstroPlugin(documentManager, configManager, workspaceUris));
|
|
57
|
-
pluginHost.registerPlugin(new
|
|
59
|
+
pluginHost.registerPlugin(new plugins_1.TypeScriptPlugin(documentManager, configManager, workspaceUris));
|
|
58
60
|
}
|
|
59
61
|
// Update language-server config with what the user supplied to us at launch
|
|
60
62
|
configManager.updateConfig(params.initializationOptions.configuration.astro);
|
|
@@ -97,6 +99,11 @@ function startLanguageServer(connection) {
|
|
|
97
99
|
colorProvider: true,
|
|
98
100
|
hoverProvider: true,
|
|
99
101
|
documentSymbolProvider: true,
|
|
102
|
+
semanticTokensProvider: {
|
|
103
|
+
legend: (0, utils_2.getSemanticTokenLegend)(),
|
|
104
|
+
range: true,
|
|
105
|
+
full: true,
|
|
106
|
+
},
|
|
100
107
|
signatureHelpProvider: {
|
|
101
108
|
triggerCharacters: ['(', ',', '<'],
|
|
102
109
|
retriggerCharacters: [')'],
|
|
@@ -146,6 +153,8 @@ function startLanguageServer(connection) {
|
|
|
146
153
|
return pluginHost.resolveCompletion(data, completionItem);
|
|
147
154
|
});
|
|
148
155
|
connection.onDocumentSymbol((params, cancellationToken) => pluginHost.getDocumentSymbols(params.textDocument, cancellationToken));
|
|
156
|
+
connection.onRequest(vscode_languageserver_1.SemanticTokensRequest.type, (evt, cancellationToken) => pluginHost.getSemanticTokens(evt.textDocument, undefined, cancellationToken));
|
|
157
|
+
connection.onRequest(vscode_languageserver_1.SemanticTokensRangeRequest.type, (evt, cancellationToken) => pluginHost.getSemanticTokens(evt.textDocument, evt.range, cancellationToken));
|
|
149
158
|
connection.onDocumentColor((params) => pluginHost.getDocumentColors(params.textDocument));
|
|
150
159
|
connection.onColorPresentation((params) => pluginHost.getColorPresentations(params.textDocument, params.range, params.color));
|
|
151
160
|
connection.onRequest(TagCloseRequest, (evt) => pluginHost.doTagComplete(evt.textDocument, evt.position));
|
package/dist/utils.d.ts
CHANGED
|
@@ -21,11 +21,6 @@ export declare function getLastPartOfPath(path: string): string;
|
|
|
21
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
|
|
22
22
|
*/
|
|
23
23
|
export declare function isPossibleComponent(node: Node): boolean;
|
|
24
|
-
/**
|
|
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
|
|
27
|
-
*/
|
|
28
|
-
export declare function isPossibleClientComponent(node: Node): boolean;
|
|
29
24
|
/** Flattens an array */
|
|
30
25
|
export declare function flatten<T>(arr: T[][]): T[];
|
|
31
26
|
/** Clamps a number between min and max */
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.debounceThrottle = exports.debounceSameArg = exports.isBeforeOrEqualToPosition = exports.isInRange = exports.isNotNullOrUndefined = exports.clamp = exports.flatten = exports.
|
|
3
|
+
exports.debounceThrottle = exports.debounceSameArg = exports.isBeforeOrEqualToPosition = exports.isInRange = exports.isNotNullOrUndefined = exports.clamp = exports.flatten = exports.isPossibleComponent = exports.getLastPartOfPath = exports.pathToUrl = exports.urlToPath = exports.normalizePath = exports.normalizeUri = void 0;
|
|
4
4
|
const vscode_uri_1 = require("vscode-uri");
|
|
5
5
|
/** Normalizes a document URI */
|
|
6
6
|
function normalizeUri(uri) {
|
|
@@ -46,21 +46,6 @@ function isPossibleComponent(node) {
|
|
|
46
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]/));
|
|
47
47
|
}
|
|
48
48
|
exports.isPossibleComponent = isPossibleComponent;
|
|
49
|
-
/**
|
|
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
|
|
52
|
-
*/
|
|
53
|
-
function isPossibleClientComponent(node) {
|
|
54
|
-
if (isPossibleComponent(node) && node.attributes) {
|
|
55
|
-
for (let [name] of Object.entries(node.attributes)) {
|
|
56
|
-
if (name.startsWith('client:')) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
exports.isPossibleClientComponent = isPossibleClientComponent;
|
|
64
49
|
/** Flattens an array */
|
|
65
50
|
function flatten(arr) {
|
|
66
51
|
return arr.reduce((all, item) => [...all, ...item], []);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.4",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc",
|
|
18
18
|
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
|
19
|
-
"test": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --require ts-node/register \"test/**/*.ts\" --exclude \"test/**/*.d.ts\""
|
|
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/svelte-language-integration": "^0.1.
|
|
22
|
+
"@astrojs/svelte-language-integration": "^0.1.2",
|
|
23
23
|
"@vscode/emmet-helper": "^2.8.4",
|
|
24
24
|
"lodash": "^4.17.21",
|
|
25
25
|
"source-map": "^0.7.3",
|