@astrojs/language-server 0.26.2 → 0.27.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/dist/plugins/PluginHost.d.ts +5 -2
- package/dist/plugins/PluginHost.js +13 -1
- package/dist/plugins/astro/features/CompletionsProvider.js +1 -1
- package/dist/plugins/html/HTMLPlugin.js +1 -1
- package/dist/plugins/html/features/astro-attributes.js +3 -0
- package/dist/plugins/interfaces.d.ts +8 -2
- package/dist/plugins/typescript/TypeScriptPlugin.d.ts +8 -2
- package/dist/plugins/typescript/TypeScriptPlugin.js +16 -1
- package/dist/plugins/typescript/features/FileReferencesProvider.d.ts +9 -0
- package/dist/plugins/typescript/features/FileReferencesProvider.js +28 -0
- package/dist/plugins/typescript/features/ImplementationsProvider.d.ts +9 -0
- package/dist/plugins/typescript/features/ImplementationsProvider.js +51 -0
- package/dist/plugins/typescript/features/ReferencesProvider.d.ts +9 -0
- package/dist/plugins/typescript/features/ReferencesProvider.js +54 -0
- package/dist/plugins/typescript/features/TypeDefinitionsProvider.d.ts +2 -2
- package/dist/server.js +8 -1
- package/package.json +3 -2
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
1
|
+
import { CancellationToken, CodeAction, CodeActionContext, Color, ColorInformation, ColorPresentation, CompletionContext, CompletionItem, CompletionList, DefinitionLink, Diagnostic, FoldingRange, FormattingOptions, Hover, InlayHint, LinkedEditingRanges, Location, Position, Range, ReferenceContext, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, TextDocumentIdentifier, TextEdit, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
2
|
import type { DocumentManager } from '../core/documents/DocumentManager';
|
|
3
3
|
import type { AppCompletionItem, Plugin } from './interfaces';
|
|
4
4
|
export interface PluginHostConfig {
|
|
@@ -23,8 +23,11 @@ export declare class PluginHost {
|
|
|
23
23
|
getDocumentSymbols(textDocument: TextDocumentIdentifier, cancellationToken?: CancellationToken): Promise<SymbolInformation[]>;
|
|
24
24
|
getSemanticTokens(textDocument: TextDocumentIdentifier, range?: Range, cancellationToken?: CancellationToken): Promise<SemanticTokens | null>;
|
|
25
25
|
getLinkedEditingRanges(textDocument: TextDocumentIdentifier, position: Position): Promise<LinkedEditingRanges | null>;
|
|
26
|
+
fileReferences(textDocument: TextDocumentIdentifier): Promise<Location[] | null>;
|
|
26
27
|
getDefinitions(textDocument: TextDocumentIdentifier, position: Position): Promise<DefinitionLink[] | Location[]>;
|
|
27
|
-
|
|
28
|
+
getTypeDefinitions(textDocument: TextDocumentIdentifier, position: Position): Promise<Location[] | null>;
|
|
29
|
+
getImplementations(textDocument: TextDocumentIdentifier, position: Position): Promise<Location[] | null>;
|
|
30
|
+
getReferences(textdocument: TextDocumentIdentifier, position: Position, context: ReferenceContext): Promise<Location[] | null>;
|
|
28
31
|
rename(textDocument: TextDocumentIdentifier, position: Position, newName: string): Promise<WorkspaceEdit | null>;
|
|
29
32
|
getDocumentColors(textDocument: TextDocumentIdentifier): Promise<ColorInformation[]>;
|
|
30
33
|
getColorPresentations(textDocument: TextDocumentIdentifier, range: Range, color: Color): Promise<ColorPresentation[]>;
|
|
@@ -105,6 +105,10 @@ class PluginHost {
|
|
|
105
105
|
const document = this.getDocument(textDocument.uri);
|
|
106
106
|
return await this.execute('getLinkedEditingRanges', [document, position], ExecuteMode.FirstNonNull);
|
|
107
107
|
}
|
|
108
|
+
async fileReferences(textDocument) {
|
|
109
|
+
const document = this.getDocument(textDocument.uri);
|
|
110
|
+
return await this.execute('fileReferences', [document], ExecuteMode.FirstNonNull);
|
|
111
|
+
}
|
|
108
112
|
async getDefinitions(textDocument, position) {
|
|
109
113
|
const document = this.getDocument(textDocument.uri);
|
|
110
114
|
const definitions = await this.execute('getDefinitions', [document, position], ExecuteMode.Collect);
|
|
@@ -115,10 +119,18 @@ class PluginHost {
|
|
|
115
119
|
return definitions.map((def) => ({ range: def.targetSelectionRange, uri: def.targetUri }));
|
|
116
120
|
}
|
|
117
121
|
}
|
|
118
|
-
|
|
122
|
+
getTypeDefinitions(textDocument, position) {
|
|
119
123
|
const document = this.getDocument(textDocument.uri);
|
|
120
124
|
return this.execute('getTypeDefinitions', [document, position], ExecuteMode.FirstNonNull);
|
|
121
125
|
}
|
|
126
|
+
getImplementations(textDocument, position) {
|
|
127
|
+
const document = this.getDocument(textDocument.uri);
|
|
128
|
+
return this.execute('getImplementation', [document, position], ExecuteMode.FirstNonNull);
|
|
129
|
+
}
|
|
130
|
+
getReferences(textdocument, position, context) {
|
|
131
|
+
const document = this.getDocument(textdocument.uri);
|
|
132
|
+
return this.execute('findReferences', [document, position, context], ExecuteMode.FirstNonNull);
|
|
133
|
+
}
|
|
122
134
|
async rename(textDocument, position, newName) {
|
|
123
135
|
const document = this.getDocument(textDocument.uri);
|
|
124
136
|
return this.execute('rename', [document, position, newName], ExecuteMode.FirstNonNull);
|
|
@@ -34,7 +34,7 @@ class CompletionsProviderImpl {
|
|
|
34
34
|
items.push(...props);
|
|
35
35
|
}
|
|
36
36
|
const isAstro = componentFilePath?.endsWith('.astro');
|
|
37
|
-
if (!isAstro) {
|
|
37
|
+
if (!isAstro && node.tag !== 'Fragment') {
|
|
38
38
|
const directives = (0, utils_2.removeDataAttrCompletion)(this.directivesHTMLLang.doComplete(document, position, html).items);
|
|
39
39
|
items.push(...directives);
|
|
40
40
|
}
|
|
@@ -37,7 +37,7 @@ class HTMLPlugin {
|
|
|
37
37
|
return null;
|
|
38
38
|
}
|
|
39
39
|
// If the node we're hovering on is a component, instead only provide astro-specific hover info
|
|
40
|
-
if ((0, utils_1.isPossibleComponent)(node)) {
|
|
40
|
+
if ((0, utils_1.isPossibleComponent)(node) && node.tag !== 'Fragment') {
|
|
41
41
|
return this.componentLang.doHover(document, position, html);
|
|
42
42
|
}
|
|
43
43
|
return this.lang.doHover(document, position, html);
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.astroDirectives = exports.astroAttributes = exports.astroElements = exports.classListAttribute = void 0;
|
|
4
4
|
const vscode_html_languageservice_1 = require("vscode-html-languageservice");
|
|
5
|
+
const defaultProvider = (0, vscode_html_languageservice_1.getDefaultHTMLDataProvider)();
|
|
6
|
+
const slotAttr = defaultProvider.provideAttributes('div').find((attr) => attr.name === 'slot');
|
|
5
7
|
exports.classListAttribute = (0, vscode_html_languageservice_1.newHTMLDataProvider)('class-list', {
|
|
6
8
|
version: 1,
|
|
7
9
|
globalAttributes: [
|
|
@@ -169,6 +171,7 @@ exports.astroAttributes = (0, vscode_html_languageservice_1.newHTMLDataProvider)
|
|
|
169
171
|
},
|
|
170
172
|
],
|
|
171
173
|
},
|
|
174
|
+
slotAttr,
|
|
172
175
|
],
|
|
173
176
|
});
|
|
174
177
|
exports.astroDirectives = (0, vscode_html_languageservice_1.newHTMLDataProvider)('astro-directives', {
|
|
@@ -35,6 +35,9 @@ export interface ColorPresentationsProvider {
|
|
|
35
35
|
export interface DocumentSymbolsProvider {
|
|
36
36
|
getDocumentSymbols(document: TextDocument): Resolvable<SymbolInformation[]>;
|
|
37
37
|
}
|
|
38
|
+
export interface FileReferencesProvider {
|
|
39
|
+
fileReferences(document: TextDocument): Promise<Location[] | null>;
|
|
40
|
+
}
|
|
38
41
|
export interface DefinitionsProvider {
|
|
39
42
|
getDefinitions(document: TextDocument, position: Position): Resolvable<DefinitionLink[]>;
|
|
40
43
|
}
|
|
@@ -74,7 +77,10 @@ export interface SemanticTokensProvider {
|
|
|
74
77
|
export interface LinkedEditingRangesProvider {
|
|
75
78
|
getLinkedEditingRanges(document: TextDocument, position: Position): Resolvable<LinkedEditingRanges | null>;
|
|
76
79
|
}
|
|
77
|
-
export interface
|
|
80
|
+
export interface ImplementationProvider {
|
|
81
|
+
getImplementation(document: TextDocument, position: Position): Resolvable<Location[] | null>;
|
|
82
|
+
}
|
|
83
|
+
export interface TypeDefinitionsProvider {
|
|
78
84
|
getTypeDefinitions(document: TextDocument, position: Position): Resolvable<Location[] | null>;
|
|
79
85
|
}
|
|
80
86
|
export interface OnWatchFileChangesParam {
|
|
@@ -87,7 +93,7 @@ export interface OnWatchFileChangesProvider {
|
|
|
87
93
|
export interface UpdateNonAstroFile {
|
|
88
94
|
updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): void;
|
|
89
95
|
}
|
|
90
|
-
declare type ProviderBase = DiagnosticsProvider & HoverProvider & CompletionsProvider & DefinitionsProvider &
|
|
96
|
+
declare type ProviderBase = DiagnosticsProvider & HoverProvider & CompletionsProvider & FileReferencesProvider & DefinitionsProvider & TypeDefinitionsProvider & ImplementationProvider & FormattingProvider & FoldingRangesProvider & TagCompleteProvider & DocumentColorsProvider & ColorPresentationsProvider & DocumentSymbolsProvider & UpdateImportsProvider & CodeActionsProvider & FindReferencesProvider & RenameProvider & SignatureHelpProvider & SemanticTokensProvider & SelectionRangeProvider & OnWatchFileChangesProvider & LinkedEditingRangesProvider & InlayHintsProvider & UpdateNonAstroFile;
|
|
91
97
|
export declare type LSProvider = ProviderBase;
|
|
92
98
|
export declare type Plugin = Partial<ProviderBase> & {
|
|
93
99
|
__name: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CancellationToken, CodeAction, CodeActionContext, CompletionContext, DefinitionLink, Diagnostic, FoldingRange, Hover, InlayHint, Location, Position, Range, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, WorkspaceEdit } from 'vscode-languageserver';
|
|
1
|
+
import { CancellationToken, CodeAction, CodeActionContext, CompletionContext, DefinitionLink, Diagnostic, FoldingRange, Hover, InlayHint, Location, Position, Range, ReferenceContext, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, WorkspaceEdit } from 'vscode-languageserver';
|
|
2
2
|
import type { ConfigManager } from '../../core/config';
|
|
3
3
|
import type { AstroDocument } from '../../core/documents';
|
|
4
4
|
import type { AppCompletionItem, AppCompletionList, OnWatchFileChangesParam, Plugin } from '../interfaces';
|
|
@@ -12,8 +12,11 @@ export declare class TypeScriptPlugin implements Plugin {
|
|
|
12
12
|
private readonly codeActionsProvider;
|
|
13
13
|
private readonly completionProvider;
|
|
14
14
|
private readonly hoverProvider;
|
|
15
|
+
private readonly fileReferencesProvider;
|
|
15
16
|
private readonly definitionsProvider;
|
|
16
17
|
private readonly typeDefinitionsProvider;
|
|
18
|
+
private readonly implementationsProvider;
|
|
19
|
+
private readonly referencesProvider;
|
|
17
20
|
private readonly signatureHelpProvider;
|
|
18
21
|
private readonly diagnosticsProvider;
|
|
19
22
|
private readonly documentSymbolsProvider;
|
|
@@ -31,8 +34,11 @@ export declare class TypeScriptPlugin implements Plugin {
|
|
|
31
34
|
getCompletions(document: AstroDocument, position: Position, completionContext?: CompletionContext, cancellationToken?: CancellationToken): Promise<AppCompletionList<CompletionItemData> | null>;
|
|
32
35
|
resolveCompletion(document: AstroDocument, completionItem: AppCompletionItem<CompletionItemData>, cancellationToken?: CancellationToken): Promise<AppCompletionItem<CompletionItemData>>;
|
|
33
36
|
getInlayHints(document: AstroDocument, range: Range): Promise<InlayHint[]>;
|
|
37
|
+
fileReferences(document: AstroDocument): Promise<Location[] | null>;
|
|
34
38
|
getDefinitions(document: AstroDocument, position: Position): Promise<DefinitionLink[]>;
|
|
35
|
-
|
|
39
|
+
getTypeDefinitions(document: AstroDocument, position: Position): Promise<Location[] | null>;
|
|
40
|
+
getImplementation(document: AstroDocument, position: Position): Promise<Location[] | null>;
|
|
41
|
+
findReferences(document: AstroDocument, position: Position, context: ReferenceContext): Promise<Location[] | null>;
|
|
36
42
|
getDiagnostics(document: AstroDocument, cancellationToken?: CancellationToken): Promise<Diagnostic[]>;
|
|
37
43
|
onWatchFileChanges(onWatchFileChangesParas: OnWatchFileChangesParam[]): Promise<void>;
|
|
38
44
|
updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[]): Promise<void>;
|
|
@@ -11,9 +11,12 @@ const CompletionsProvider_1 = require("./features/CompletionsProvider");
|
|
|
11
11
|
const DefinitionsProvider_1 = require("./features/DefinitionsProvider");
|
|
12
12
|
const DiagnosticsProvider_1 = require("./features/DiagnosticsProvider");
|
|
13
13
|
const DocumentSymbolsProvider_1 = require("./features/DocumentSymbolsProvider");
|
|
14
|
+
const FileReferencesProvider_1 = require("./features/FileReferencesProvider");
|
|
14
15
|
const FoldingRangesProvider_1 = require("./features/FoldingRangesProvider");
|
|
15
16
|
const HoverProvider_1 = require("./features/HoverProvider");
|
|
17
|
+
const ImplementationsProvider_1 = require("./features/ImplementationsProvider");
|
|
16
18
|
const InlayHintsProvider_1 = require("./features/InlayHintsProvider");
|
|
19
|
+
const ReferencesProvider_1 = require("./features/ReferencesProvider");
|
|
17
20
|
const SemanticTokenProvider_1 = require("./features/SemanticTokenProvider");
|
|
18
21
|
const SignatureHelpProvider_1 = require("./features/SignatureHelpProvider");
|
|
19
22
|
const TypeDefinitionsProvider_1 = require("./features/TypeDefinitionsProvider");
|
|
@@ -28,8 +31,11 @@ class TypeScriptPlugin {
|
|
|
28
31
|
this.codeActionsProvider = new CodeActionsProvider_1.CodeActionsProviderImpl(this.languageServiceManager, this.configManager);
|
|
29
32
|
this.completionProvider = new CompletionsProvider_1.CompletionsProviderImpl(this.languageServiceManager, this.configManager);
|
|
30
33
|
this.hoverProvider = new HoverProvider_1.HoverProviderImpl(this.languageServiceManager);
|
|
34
|
+
this.fileReferencesProvider = new FileReferencesProvider_1.FileReferencesProviderImpl(this.languageServiceManager);
|
|
31
35
|
this.definitionsProvider = new DefinitionsProvider_1.DefinitionsProviderImpl(this.languageServiceManager);
|
|
32
36
|
this.typeDefinitionsProvider = new TypeDefinitionsProvider_1.TypeDefinitionsProviderImpl(this.languageServiceManager);
|
|
37
|
+
this.implementationsProvider = new ImplementationsProvider_1.ImplementationsProviderImpl(this.languageServiceManager);
|
|
38
|
+
this.referencesProvider = new ReferencesProvider_1.FindReferencesProviderImpl(this.languageServiceManager);
|
|
33
39
|
this.signatureHelpProvider = new SignatureHelpProvider_1.SignatureHelpProviderImpl(this.languageServiceManager);
|
|
34
40
|
this.diagnosticsProvider = new DiagnosticsProvider_1.DiagnosticsProviderImpl(this.languageServiceManager);
|
|
35
41
|
this.documentSymbolsProvider = new DocumentSymbolsProvider_1.DocumentSymbolsProviderImpl(this.languageServiceManager);
|
|
@@ -101,12 +107,21 @@ class TypeScriptPlugin {
|
|
|
101
107
|
async getInlayHints(document, range) {
|
|
102
108
|
return this.inlayHintsProvider.getInlayHints(document, range);
|
|
103
109
|
}
|
|
110
|
+
async fileReferences(document) {
|
|
111
|
+
return this.fileReferencesProvider.fileReferences(document);
|
|
112
|
+
}
|
|
104
113
|
async getDefinitions(document, position) {
|
|
105
114
|
return this.definitionsProvider.getDefinitions(document, position);
|
|
106
115
|
}
|
|
107
|
-
async
|
|
116
|
+
async getTypeDefinitions(document, position) {
|
|
108
117
|
return this.typeDefinitionsProvider.getTypeDefinitions(document, position);
|
|
109
118
|
}
|
|
119
|
+
async getImplementation(document, position) {
|
|
120
|
+
return this.implementationsProvider.getImplementation(document, position);
|
|
121
|
+
}
|
|
122
|
+
async findReferences(document, position, context) {
|
|
123
|
+
return this.referencesProvider.findReferences(document, position, context);
|
|
124
|
+
}
|
|
110
125
|
async getDiagnostics(document, cancellationToken) {
|
|
111
126
|
if (!(await this.featureEnabled(document, 'diagnostics'))) {
|
|
112
127
|
return [];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Location } from 'vscode-languageserver';
|
|
2
|
+
import { AstroDocument } from '../../../core/documents';
|
|
3
|
+
import { FileReferencesProvider } from '../../interfaces';
|
|
4
|
+
import { LanguageServiceManager } from '../LanguageServiceManager';
|
|
5
|
+
export declare class FileReferencesProviderImpl implements FileReferencesProvider {
|
|
6
|
+
private languageServiceManager;
|
|
7
|
+
constructor(languageServiceManager: LanguageServiceManager);
|
|
8
|
+
fileReferences(document: AstroDocument): Promise<Location[] | null>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileReferencesProviderImpl = void 0;
|
|
4
|
+
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
const utils_2 = require("../utils");
|
|
7
|
+
const utils_3 = require("./utils");
|
|
8
|
+
class FileReferencesProviderImpl {
|
|
9
|
+
constructor(languageServiceManager) {
|
|
10
|
+
this.languageServiceManager = languageServiceManager;
|
|
11
|
+
}
|
|
12
|
+
async fileReferences(document) {
|
|
13
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
14
|
+
const mainFragment = await tsDoc.createFragment();
|
|
15
|
+
const references = lang.getFileReferences(tsDoc.filePath);
|
|
16
|
+
if (!references) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const docs = new utils_3.SnapshotFragmentMap(this.languageServiceManager);
|
|
20
|
+
docs.set(tsDoc.filePath, { fragment: mainFragment, snapshot: tsDoc });
|
|
21
|
+
const locations = await Promise.all(references.map(async (ref) => {
|
|
22
|
+
const defDoc = await docs.retrieveFragment(ref.fileName);
|
|
23
|
+
return vscode_languageserver_1.Location.create((0, utils_1.pathToUrl)(ref.fileName), (0, utils_2.convertToLocationRange)(defDoc, ref.textSpan));
|
|
24
|
+
}));
|
|
25
|
+
return locations;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.FileReferencesProviderImpl = FileReferencesProviderImpl;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Location, Position } from 'vscode-languageserver-types';
|
|
2
|
+
import { AstroDocument } from '../../../core/documents';
|
|
3
|
+
import { ImplementationProvider } from '../../interfaces';
|
|
4
|
+
import { LanguageServiceManager } from '../LanguageServiceManager';
|
|
5
|
+
export declare class ImplementationsProviderImpl implements ImplementationProvider {
|
|
6
|
+
private languageServiceManager;
|
|
7
|
+
constructor(languageServiceManager: LanguageServiceManager);
|
|
8
|
+
getImplementation(document: AstroDocument, position: Position): Promise<Location[] | null>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImplementationsProviderImpl = void 0;
|
|
4
|
+
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
5
|
+
const documents_1 = require("../../../core/documents");
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const utils_2 = require("../utils");
|
|
8
|
+
const utils_3 = require("./utils");
|
|
9
|
+
class ImplementationsProviderImpl {
|
|
10
|
+
constructor(languageServiceManager) {
|
|
11
|
+
this.languageServiceManager = languageServiceManager;
|
|
12
|
+
}
|
|
13
|
+
async getImplementation(document, position) {
|
|
14
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
15
|
+
const mainFragment = await tsDoc.createFragment();
|
|
16
|
+
const offset = mainFragment.offsetAt(mainFragment.getGeneratedPosition(position));
|
|
17
|
+
const node = document.html.findNodeAt(offset);
|
|
18
|
+
let implementations;
|
|
19
|
+
if (node.tag === 'script') {
|
|
20
|
+
const { snapshot: scriptTagSnapshot, filePath: scriptFilePath, offset: scriptOffset, } = (0, utils_2.getScriptTagSnapshot)(tsDoc, document, node, position);
|
|
21
|
+
implementations = lang.getImplementationAtPosition(scriptFilePath, scriptOffset);
|
|
22
|
+
if (implementations) {
|
|
23
|
+
implementations = implementations.map((impl) => {
|
|
24
|
+
const isInSameFile = impl.fileName === scriptFilePath;
|
|
25
|
+
impl.fileName = isInSameFile ? tsDoc.filePath : impl.fileName;
|
|
26
|
+
if (isInSameFile) {
|
|
27
|
+
impl.textSpan.start = mainFragment.offsetAt(scriptTagSnapshot.getOriginalPosition(scriptTagSnapshot.positionAt(impl.textSpan.start)));
|
|
28
|
+
}
|
|
29
|
+
return impl;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
implementations = lang.getImplementationAtPosition(tsDoc.filePath, offset);
|
|
35
|
+
}
|
|
36
|
+
const docs = new utils_3.SnapshotFragmentMap(this.languageServiceManager);
|
|
37
|
+
docs.set(tsDoc.filePath, { fragment: mainFragment, snapshot: tsDoc });
|
|
38
|
+
if (!implementations) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const result = await Promise.all(implementations.map(async (implementation) => {
|
|
42
|
+
const { fragment } = await docs.retrieve(implementation.fileName);
|
|
43
|
+
const range = (0, documents_1.mapRangeToOriginal)(fragment, (0, utils_2.convertRange)(fragment, implementation.textSpan));
|
|
44
|
+
if (range.start.line >= 0 && range.end.line >= 0) {
|
|
45
|
+
return vscode_languageserver_types_1.Location.create((0, utils_1.pathToUrl)(implementation.fileName), range);
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
return result.filter(utils_1.isNotNullOrUndefined);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ImplementationsProviderImpl = ImplementationsProviderImpl;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Location, Position, ReferenceContext } from 'vscode-languageserver-types';
|
|
2
|
+
import { AstroDocument } from '../../../core/documents';
|
|
3
|
+
import type { FindReferencesProvider } from '../../interfaces';
|
|
4
|
+
import type { LanguageServiceManager } from '../LanguageServiceManager';
|
|
5
|
+
export declare class FindReferencesProviderImpl implements FindReferencesProvider {
|
|
6
|
+
private languageServiceManager;
|
|
7
|
+
constructor(languageServiceManager: LanguageServiceManager);
|
|
8
|
+
findReferences(document: AstroDocument, position: Position, context: ReferenceContext): Promise<Location[] | null>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FindReferencesProviderImpl = void 0;
|
|
4
|
+
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
|
|
5
|
+
const documents_1 = require("../../../core/documents");
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const utils_2 = require("../utils");
|
|
8
|
+
const utils_3 = require("./utils");
|
|
9
|
+
class FindReferencesProviderImpl {
|
|
10
|
+
constructor(languageServiceManager) {
|
|
11
|
+
this.languageServiceManager = languageServiceManager;
|
|
12
|
+
}
|
|
13
|
+
async findReferences(document, position, context) {
|
|
14
|
+
const { lang, tsDoc } = await this.languageServiceManager.getLSAndTSDoc(document);
|
|
15
|
+
const mainFragment = await tsDoc.createFragment();
|
|
16
|
+
const offset = mainFragment.offsetAt(mainFragment.getGeneratedPosition(position));
|
|
17
|
+
const node = document.html.findNodeAt(offset);
|
|
18
|
+
let references;
|
|
19
|
+
if (node.tag === 'script') {
|
|
20
|
+
const { snapshot: scriptTagSnapshot, filePath: scriptFilePath, offset: scriptOffset, } = (0, utils_2.getScriptTagSnapshot)(tsDoc, document, node, position);
|
|
21
|
+
references = lang.getReferencesAtPosition(scriptFilePath, scriptOffset);
|
|
22
|
+
if (references) {
|
|
23
|
+
references = references.map((ref) => {
|
|
24
|
+
const isInSameFile = ref.fileName === scriptFilePath;
|
|
25
|
+
ref.fileName = isInSameFile ? tsDoc.filePath : ref.fileName;
|
|
26
|
+
if (isInSameFile) {
|
|
27
|
+
ref.textSpan.start = mainFragment.offsetAt(scriptTagSnapshot.getOriginalPosition(scriptTagSnapshot.positionAt(ref.textSpan.start)));
|
|
28
|
+
}
|
|
29
|
+
return ref;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
references = lang.getReferencesAtPosition(tsDoc.filePath, offset);
|
|
35
|
+
}
|
|
36
|
+
if (!references) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const docs = new utils_3.SnapshotFragmentMap(this.languageServiceManager);
|
|
40
|
+
docs.set(tsDoc.filePath, { fragment: mainFragment, snapshot: tsDoc });
|
|
41
|
+
const result = await Promise.all(references.map(async (reference) => {
|
|
42
|
+
if (!context.includeDeclaration) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const { fragment } = await docs.retrieve(reference.fileName);
|
|
46
|
+
const range = (0, documents_1.mapRangeToOriginal)(fragment, (0, utils_2.convertRange)(fragment, reference.textSpan));
|
|
47
|
+
if (range.start.line >= 0 && range.end.line >= 0) {
|
|
48
|
+
return vscode_languageserver_types_1.Location.create((0, utils_1.pathToUrl)(reference.fileName), range);
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
return result.filter(utils_1.isNotNullOrUndefined);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.FindReferencesProviderImpl = FindReferencesProviderImpl;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Location, Position } from 'vscode-languageserver-protocol';
|
|
2
2
|
import { AstroDocument } from '../../../core/documents';
|
|
3
|
-
import type {
|
|
3
|
+
import type { TypeDefinitionsProvider } from '../../interfaces';
|
|
4
4
|
import type { LanguageServiceManager } from '../LanguageServiceManager';
|
|
5
|
-
export declare class TypeDefinitionsProviderImpl implements
|
|
5
|
+
export declare class TypeDefinitionsProviderImpl implements TypeDefinitionsProvider {
|
|
6
6
|
private languageServiceManager;
|
|
7
7
|
constructor(languageServiceManager: LanguageServiceManager);
|
|
8
8
|
getTypeDefinitions(document: AstroDocument, position: Position): Promise<Location[]>;
|
package/dist/server.js
CHANGED
|
@@ -103,6 +103,8 @@ function startLanguageServer(connection, env) {
|
|
|
103
103
|
foldingRangeProvider: true,
|
|
104
104
|
definitionProvider: true,
|
|
105
105
|
typeDefinitionProvider: true,
|
|
106
|
+
referencesProvider: true,
|
|
107
|
+
implementationProvider: true,
|
|
106
108
|
renameProvider: true,
|
|
107
109
|
documentFormattingProvider: true,
|
|
108
110
|
codeActionProvider: {
|
|
@@ -197,7 +199,9 @@ function startLanguageServer(connection, env) {
|
|
|
197
199
|
// Features
|
|
198
200
|
connection.onHover((params) => pluginHost.doHover(params.textDocument, params.position));
|
|
199
201
|
connection.onDefinition((evt) => pluginHost.getDefinitions(evt.textDocument, evt.position));
|
|
200
|
-
connection.onTypeDefinition((evt) => pluginHost.
|
|
202
|
+
connection.onTypeDefinition((evt) => pluginHost.getTypeDefinitions(evt.textDocument, evt.position));
|
|
203
|
+
connection.onReferences((evt) => pluginHost.getReferences(evt.textDocument, evt.position, evt.context));
|
|
204
|
+
connection.onImplementation((evt) => pluginHost.getImplementations(evt.textDocument, evt.position));
|
|
201
205
|
connection.onFoldingRanges((evt) => pluginHost.getFoldingRanges(evt.textDocument));
|
|
202
206
|
connection.onCodeAction((evt, cancellationToken) => pluginHost.getCodeActions(evt.textDocument, evt.range, evt.context, cancellationToken));
|
|
203
207
|
connection.onCompletion(async (evt) => {
|
|
@@ -230,6 +234,9 @@ function startLanguageServer(connection, env) {
|
|
|
230
234
|
}
|
|
231
235
|
updateAllDiagnostics();
|
|
232
236
|
});
|
|
237
|
+
connection.onRequest('$/getFileReferences', async (uri) => {
|
|
238
|
+
return pluginHost.fileReferences({ uri });
|
|
239
|
+
});
|
|
233
240
|
connection.onRequest('$/getTSXOutput', async (uri) => {
|
|
234
241
|
const doc = documentManager.get(uri);
|
|
235
242
|
if (!doc) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/language-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"author": "withastro",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsc --project tsconfig.build.json",
|
|
51
51
|
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
|
52
|
-
"test": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --timeout 20000 --require ts-node/register \"test/**/*.ts\" --exclude \"test/**/*.d.ts\""
|
|
52
|
+
"test": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --timeout 20000 --require ts-node/register \"test/**/*.ts\" --exclude \"test/**/*.d.ts\"",
|
|
53
|
+
"test:match": "pnpm run test -g"
|
|
53
54
|
}
|
|
54
55
|
}
|