@volar/language-service
Advanced tools
Comparing version 1.3.0-alpha.3 to 1.4.0-alpha.0
@@ -7,46 +7,42 @@ import { LanguageServicePluginContext, LanguageServiceOptions } from './types'; | ||
triggerCharacters: string[]; | ||
format: (uri: string, options: _.FormattingOptions, range?: _.Range | undefined, onTypeParams?: { | ||
autoFormatTriggerCharacters: string[]; | ||
signatureHelpTriggerCharacters: string[]; | ||
signatureHelpRetriggerCharacters: string[]; | ||
format: (uri: string, options: _.FormattingOptions, range: _.Range | undefined, onTypeParams: { | ||
ch: string; | ||
position: _.Position; | ||
} | undefined) => Promise<_.TextEdit[] | undefined>; | ||
getFoldingRanges: (uri: string) => Promise<_.FoldingRange[] | undefined>; | ||
getSelectionRanges: (uri: string, positions: _.Position[]) => Promise<_.SelectionRange[] | undefined>; | ||
findLinkedEditingRanges: (uri: string, position: _.Position) => Promise<_.LinkedEditingRanges | undefined>; | ||
findDocumentSymbols: (uri: string) => Promise<_.DocumentSymbol[] | undefined>; | ||
findDocumentColors: (uri: string) => Promise<_.ColorInformation[] | undefined>; | ||
getColorPresentations: (uri: string, color: _.Color, range: _.Range) => Promise<_.ColorPresentation[] | undefined>; | ||
doValidation: (uri: string, token?: _.CancellationToken | undefined, response?: ((result: _.Diagnostic[]) => void) | undefined) => Promise<_.Diagnostic[]>; | ||
findReferences: (uri: string, position: _.Position) => Promise<_.Location[] | undefined>; | ||
findFileReferences: (uri: string) => import("./types").NullableResult<_.Location[]>; | ||
findDefinition: (uri: string, position: _.Position) => Promise<_.LocationLink[] | undefined>; | ||
findTypeDefinition: (uri: string, position: _.Position) => Promise<_.LocationLink[] | undefined>; | ||
findImplementations: (uri: string, position: _.Position) => Promise<_.LocationLink[] | undefined>; | ||
prepareRename: (uri: string, position: _.Position) => Promise<NonNullable<_.Range | _.ResponseError<void> | null | undefined> | undefined>; | ||
doRename: (uri: string, position: _.Position, newName: string) => Promise<_.WorkspaceEdit | undefined>; | ||
getEditsForFileRename: (oldUri: string, newUri: string) => Promise<_.WorkspaceEdit | undefined>; | ||
getSemanticTokens: (uri: string, range: _.Range | undefined, legend: _.SemanticTokensLegend, cancelToken: _.CancellationToken, reportProgress?: ((tokens: import("./types").SemanticToken[]) => void) | undefined) => Promise<import("./types").SemanticToken[] | undefined> | undefined; | ||
doHover: (uri: string, position: _.Position) => Promise<_.Hover | undefined>; | ||
doComplete: (uri: string, position: _.Position, completionContext?: _.CompletionContext | undefined) => Promise<_.CompletionList>; | ||
doCodeActions: (uri: string, range: _.Range, codeActionContext: _.CodeActionContext) => Promise<_.CodeAction[] | undefined>; | ||
doCodeActionResolve: (item: _.CodeAction) => Promise<_.CodeAction>; | ||
doCompletionResolve: (item: _.CompletionItem) => Promise<_.CompletionItem>; | ||
getSignatureHelp: (uri: string, position: _.Position, signatureHelpContext?: _.SignatureHelpContext | undefined) => Promise<_.SignatureHelp | undefined>; | ||
doCodeLens: (uri: string) => Promise<_.CodeLens[]>; | ||
doCodeLensResolve: (item: _.CodeLens) => Promise<_.CodeLens>; | ||
findDocumentHighlights: (uri: string, position: _.Position) => Promise<_.DocumentHighlight[] | undefined>; | ||
findDocumentLinks: (uri: string) => Promise<_.DocumentLink[]>; | ||
findWorkspaceSymbols: (query: string) => Promise<_.WorkspaceSymbol[]>; | ||
doAutoInsert: (uri: string, position: _.Position, autoInsertContext: { | ||
lastChange: { | ||
range: _.Range; | ||
rangeOffset: number; | ||
rangeLength: number; | ||
text: string; | ||
}; | ||
}) => Promise<NonNullable<string | _.TextEdit | null | undefined> | undefined>; | ||
getInlayHints: (uri: string, range: _.Range) => Promise<_.InlayHint[] | undefined>; | ||
} | undefined, token: _.CancellationToken) => Promise<_.TextEdit[] | undefined>; | ||
getFoldingRanges: (uri: string, token: _.CancellationToken) => Promise<_.FoldingRange[] | undefined>; | ||
getSelectionRanges: (uri: string, positions: _.Position[], token: _.CancellationToken) => Promise<_.SelectionRange[] | undefined>; | ||
findLinkedEditingRanges: (uri: string, position: _.Position, token: _.CancellationToken) => Promise<_.LinkedEditingRanges | undefined>; | ||
findDocumentSymbols: (uri: string, token: _.CancellationToken) => Promise<_.DocumentSymbol[] | undefined>; | ||
findDocumentColors: (uri: string, token: _.CancellationToken) => Promise<_.ColorInformation[] | undefined>; | ||
getColorPresentations: (uri: string, color: _.Color, range: _.Range, token: _.CancellationToken) => Promise<_.ColorPresentation[] | undefined>; | ||
doValidation: (uri: string, token: _.CancellationToken, mode: "all" | "semantic" | "syntactic", response?: ((result: _.Diagnostic[]) => void) | undefined) => Promise<_.Diagnostic[]>; | ||
findReferences: (uri: string, position: _.Position, token: _.CancellationToken) => Promise<_.Location[] | undefined>; | ||
findFileReferences: (uri: string, token: _.CancellationToken) => import("./types").NullableResult<_.Location[]>; | ||
findDefinition: (uri: string, position: _.Position, token: _.CancellationToken) => Promise<_.LocationLink[] | undefined>; | ||
findTypeDefinition: (uri: string, position: _.Position, token: _.CancellationToken) => Promise<_.LocationLink[] | undefined>; | ||
findImplementations: (uri: string, position: _.Position, token: _.CancellationToken) => Promise<_.LocationLink[] | undefined>; | ||
prepareRename: (uri: string, position: _.Position, token: _.CancellationToken) => Promise<NonNullable<_.Range | _.ResponseError<void> | null | undefined> | undefined>; | ||
doRename: (uri: string, position: _.Position, newName: string, token: _.CancellationToken) => Promise<_.WorkspaceEdit | undefined>; | ||
getEditsForFileRename: (oldUri: string, newUri: string, token: _.CancellationToken) => Promise<_.WorkspaceEdit | undefined>; | ||
getSemanticTokens: (uri: string, range: _.Range | undefined, legend: _.SemanticTokensLegend, token: _.CancellationToken, reportProgress?: ((tokens: _.SemanticTokens) => void) | undefined) => Promise<_.SemanticTokens | undefined>; | ||
doHover: (uri: string, position: _.Position, token: _.CancellationToken) => Promise<_.Hover | undefined>; | ||
doComplete: (uri: string, position: _.Position, completionContext: _.CompletionContext | undefined, token: _.CancellationToken) => Promise<_.CompletionList>; | ||
doCodeActions: (uri: string, range: _.Range, codeActionContext: _.CodeActionContext, token: _.CancellationToken) => Promise<_.CodeAction[] | undefined>; | ||
doCodeActionResolve: (item: _.CodeAction, token: _.CancellationToken) => Promise<_.CodeAction>; | ||
doCompletionResolve: (item: _.CompletionItem, token: _.CancellationToken) => Promise<_.CompletionItem>; | ||
getSignatureHelp: (uri: string, position: _.Position, signatureHelpContext: _.SignatureHelpContext | undefined, token: _.CancellationToken) => Promise<_.SignatureHelp | undefined>; | ||
doCodeLens: (uri: string, token: _.CancellationToken) => Promise<_.CodeLens[]>; | ||
doCodeLensResolve: (item: _.CodeLens, token: _.CancellationToken) => Promise<_.CodeLens>; | ||
findDocumentHighlights: (uri: string, position: _.Position, token: _.CancellationToken) => Promise<_.DocumentHighlight[] | undefined>; | ||
findDocumentLinks: (uri: string, token: _.CancellationToken) => Promise<_.DocumentLink[]>; | ||
findWorkspaceSymbols: (query: string, token: _.CancellationToken) => Promise<_.WorkspaceSymbol[]>; | ||
doAutoInsert: (uri: string, position: _.Position, autoInsertContext: import("./types").AutoInsertionContext, token: _.CancellationToken) => Promise<NonNullable<string | _.TextEdit | null | undefined> | undefined>; | ||
getInlayHints: (uri: string, range: _.Range, token: _.CancellationToken) => Promise<_.InlayHint[] | undefined>; | ||
callHierarchy: { | ||
doPrepare(uri: string, position: _.Position): Promise<_.CallHierarchyItem[] | undefined>; | ||
getIncomingCalls(item: _.CallHierarchyItem): Promise<_.CallHierarchyIncomingCall[]>; | ||
getOutgoingCalls(item: _.CallHierarchyItem): Promise<_.CallHierarchyOutgoingCall[]>; | ||
doPrepare(uri: string, position: _.Position, token: _.CancellationToken): Promise<_.CallHierarchyItem[] | undefined>; | ||
getIncomingCalls(item: _.CallHierarchyItem, token: _.CancellationToken): Promise<_.CallHierarchyIncomingCall[]>; | ||
getOutgoingCalls(item: _.CallHierarchyItem, token: _.CancellationToken): Promise<_.CallHierarchyOutgoingCall[]>; | ||
}; | ||
@@ -53,0 +49,0 @@ dispose: () => void | undefined; |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createLanguageService = void 0; | ||
const language_core_1 = require("@volar/language-core"); | ||
const shared = require("@volar/shared"); | ||
const tsFaster = require("@volar/typescript-faster"); | ||
const tsFaster = require("typescript-auto-import-cache"); | ||
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument"); | ||
@@ -37,5 +36,6 @@ const documents_1 = require("./documents"); | ||
const selectionRanges = require("./documentFeatures/selectionRanges"); | ||
const common_1 = require("./utils/common"); | ||
function createLanguageService(ctx, documentRegistry) { | ||
var _a; | ||
const languageContext = (0, language_core_1.createLanguageContext)(ctx.host, Object.values((_a = ctx.config.languages) !== null && _a !== void 0 ? _a : {}).filter(shared.notEmpty)); | ||
const languageContext = (0, language_core_1.createLanguageContext)(ctx.host, Object.values((_a = ctx.config.languages) !== null && _a !== void 0 ? _a : {}).filter(common_1.notEmpty)); | ||
const context = createLanguageServiceContext(ctx, languageContext, documentRegistry); | ||
@@ -80,3 +80,3 @@ return createLanguageServiceBase(context); | ||
documentVersions.set(uri.toLowerCase(), newVersion); | ||
document = vscode_languageserver_textdocument_1.TextDocument.create(uri, shared.syntaxToLanguageId(uri.substring(uri.lastIndexOf('.') + 1)), newVersion, scriptSnapshot.getText(0, scriptSnapshot.getLength())); | ||
document = vscode_languageserver_textdocument_1.TextDocument.create(uri, (0, common_1.syntaxToLanguageId)(uri.substring(uri.lastIndexOf('.') + 1)), newVersion, scriptSnapshot.getText(0, scriptSnapshot.getLength())); | ||
documents.set(scriptSnapshot, document); | ||
@@ -90,3 +90,6 @@ } | ||
return { | ||
triggerCharacters: Object.values(context.plugins).map(plugin => { var _a, _b; return (_b = (_a = plugin.complete) === null || _a === void 0 ? void 0 : _a.triggerCharacters) !== null && _b !== void 0 ? _b : []; }).flat(), | ||
triggerCharacters: Object.values(context.plugins).map(plugin => { var _a; return (_a = plugin === null || plugin === void 0 ? void 0 : plugin.triggerCharacters) !== null && _a !== void 0 ? _a : []; }).flat(), | ||
autoFormatTriggerCharacters: Object.values(context.plugins).map(plugin => { var _a; return (_a = plugin === null || plugin === void 0 ? void 0 : plugin.autoFormatTriggerCharacters) !== null && _a !== void 0 ? _a : []; }).flat(), | ||
signatureHelpTriggerCharacters: Object.values(context.plugins).map(plugin => { var _a; return (_a = plugin === null || plugin === void 0 ? void 0 : plugin.signatureHelpTriggerCharacters) !== null && _a !== void 0 ? _a : []; }).flat(), | ||
signatureHelpRetriggerCharacters: Object.values(context.plugins).map(plugin => { var _a; return (_a = plugin === null || plugin === void 0 ? void 0 : plugin.signatureHelpRetriggerCharacters) !== null && _a !== void 0 ? _a : []; }).flat(), | ||
format: format.register(context), | ||
@@ -102,5 +105,5 @@ getFoldingRanges: foldingRanges.register(context), | ||
findFileReferences: fileReferences.register(context), | ||
findDefinition: definition.register(context, 'findDefinition', data => !!data.definition, data => !!data.definition), | ||
findTypeDefinition: definition.register(context, 'findTypeDefinition', data => !!data.definition, data => !!data.definition), | ||
findImplementations: definition.register(context, 'findImplementations', data => !!data.references, () => false), | ||
findDefinition: definition.register(context, 'provideDefinition', data => !!data.definition, data => !!data.definition), | ||
findTypeDefinition: definition.register(context, 'provideTypeDefinition', data => !!data.definition, data => !!data.definition), | ||
findImplementations: definition.register(context, 'provideImplementation', data => !!data.references, () => false), | ||
prepareRename: renamePrepare.register(context), | ||
@@ -107,0 +110,0 @@ doRename: rename.register(context), |
import type { LanguageServicePluginContext } from '../types'; | ||
import * as vscode from 'vscode-languageserver-protocol'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, color: vscode.Color, range: vscode.Range) => Promise<vscode.ColorPresentation[] | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, color: vscode.Color, range: vscode.Range, token: vscode.CancellationToken) => Promise<vscode.ColorPresentation[] | undefined>; |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.register = void 0; | ||
const featureWorkers_1 = require("../utils/featureWorkers"); | ||
const shared = require("@volar/shared"); | ||
const common_1 = require("../utils/common"); | ||
function register(context) { | ||
return (uri, color, range) => { | ||
return (uri, color, range, token) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, range, (range, map, file) => { | ||
@@ -11,3 +11,8 @@ if (file.capabilities.documentSymbol) // TODO: add color capability setting | ||
return []; | ||
}, (plugin, document, range) => { var _a; return (_a = plugin.getColorPresentations) === null || _a === void 0 ? void 0 : _a.call(plugin, document, color, range); }, (data, map) => map ? data.map(cp => { | ||
}, (plugin, document, range) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideColorPresentations) === null || _a === void 0 ? void 0 : _a.call(plugin, document, color, range, token); | ||
}, (data, map) => map ? data.map(cp => { | ||
if (cp.textEdit) { | ||
@@ -28,3 +33,3 @@ const range = map.toSourceRange(cp.textEdit.range); | ||
return cp; | ||
}).filter(shared.notEmpty) : data); | ||
}).filter(common_1.notEmpty) : data); | ||
}; | ||
@@ -31,0 +36,0 @@ } |
import type { LanguageServicePluginContext } from '../types'; | ||
import * as vscode from 'vscode-languageserver-protocol'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.ColorInformation[] | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, token: vscode.CancellationToken) => Promise<vscode.ColorInformation[] | undefined>; |
@@ -5,7 +5,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
const vscode = require("vscode-languageserver-protocol"); | ||
const shared = require("@volar/shared"); | ||
const common_1 = require("../utils/common"); | ||
function register(context) { | ||
return (uri) => { | ||
return (uri, token) => { | ||
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, // TODO: add color capability setting | ||
(plugin, document) => { var _a; return (_a = plugin.findDocumentColors) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => map ? data.map(color => { | ||
(plugin, document) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideDocumentColors) === null || _a === void 0 ? void 0 : _a.call(plugin, document, token); | ||
}, (data, map) => map ? data.map(color => { | ||
const range = map.toSourceRange(color.range); | ||
@@ -15,3 +20,3 @@ if (range) { | ||
} | ||
}).filter(shared.notEmpty) : data, arr => arr.flat()); | ||
}).filter(common_1.notEmpty) : data, arr => arr.flat()); | ||
}; | ||
@@ -18,0 +23,0 @@ } |
import type { LanguageServicePluginContext } from '../types'; | ||
import * as vscode from 'vscode-languageserver-protocol'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.DocumentSymbol[] | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, token: vscode.CancellationToken) => Promise<vscode.DocumentSymbol[] | undefined>; |
@@ -14,10 +14,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const transformer = require("../transformer"); | ||
const shared = require("@volar/shared"); | ||
const common_1 = require("../utils/common"); | ||
function register(context) { | ||
return (uri) => { | ||
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => __awaiter(this, void 0, void 0, function* () { var _a; return (_a = plugin.findDocumentSymbols) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }), (data, map) => map | ||
return (uri, token) => { | ||
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideDocumentSymbols) === null || _a === void 0 ? void 0 : _a.call(plugin, document, token); | ||
}), (data, map) => map | ||
? data | ||
.map(symbol => transformer.asDocumentSymbol(symbol, range => map.toSourceRange(range))) | ||
.filter(shared.notEmpty) | ||
.filter(common_1.notEmpty) | ||
: data, results => { | ||
@@ -24,0 +28,0 @@ for (let i = 0; i < results.length; i++) { |
import type { LanguageServicePluginContext } from '../types'; | ||
import type * as _ from 'vscode-languageserver-protocol'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<_.FoldingRange[] | undefined>; | ||
import type * as vscode from 'vscode-languageserver-protocol'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, token: vscode.CancellationToken) => Promise<vscode.FoldingRange[] | undefined>; |
@@ -6,4 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function register(context) { | ||
return (uri) => { | ||
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.foldingRange, (plugin, document) => { var _a; return (_a = plugin.getFoldingRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => map ? transformer.asFoldingRanges(data, range => map.toSourceRange(range)) : data, arr => arr.flat()); | ||
return (uri, token) => { | ||
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.foldingRange, (plugin, document) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideFoldingRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, token); | ||
}, (data, map) => map ? transformer.asFoldingRanges(data, range => map.toSourceRange(range)) : data, arr => arr.flat()); | ||
}; | ||
@@ -10,0 +15,0 @@ } |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, options: vscode.FormattingOptions, range?: vscode.Range, onTypeParams?: { | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, options: vscode.FormattingOptions, range: vscode.Range | undefined, onTypeParams: { | ||
ch: string; | ||
position: vscode.Position; | ||
}) => Promise<vscode.TextEdit[] | undefined>; | ||
} | undefined, token: vscode.CancellationToken) => Promise<vscode.TextEdit[] | undefined>; |
@@ -16,3 +16,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function register(context) { | ||
return (uri, options, range, onTypeParams) => __awaiter(this, void 0, void 0, function* () { | ||
return (uri, options, range, onTypeParams, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c; | ||
@@ -101,4 +101,6 @@ let document = context.getTextDocument(uri); | ||
for (const plugin of Object.values(context.plugins)) { | ||
if (plugin.getIndentSensitiveLines) { | ||
const lines = yield plugin.getIndentSensitiveLines(map.virtualFileDocument); | ||
if (token.isCancellationRequested) | ||
break; | ||
if (plugin.provideFormattingIndentSensitiveLines) { | ||
const lines = yield plugin.provideFormattingIndentSensitiveLines(map.virtualFileDocument, token); | ||
if (lines) { | ||
@@ -158,13 +160,17 @@ for (const line of lines) { | ||
function tryFormat(document, range, ch) { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let formatRange = range; | ||
for (const plugin of Object.values(context.plugins)) { | ||
if (token.isCancellationRequested) | ||
break; | ||
let edits; | ||
try { | ||
if (ch !== undefined && vscode.Position.is(formatRange)) { | ||
edits = yield ((_a = plugin.formatOnType) === null || _a === void 0 ? void 0 : _a.call(plugin, document, formatRange, ch, options)); | ||
if ((_a = plugin.autoFormatTriggerCharacters) === null || _a === void 0 ? void 0 : _a.includes(ch)) { | ||
edits = yield ((_b = plugin.provideOnTypeFormattingEdits) === null || _b === void 0 ? void 0 : _b.call(plugin, document, formatRange, ch, options, token)); | ||
} | ||
} | ||
else if (ch === undefined && vscode.Range.is(formatRange)) { | ||
edits = yield ((_b = plugin.format) === null || _b === void 0 ? void 0 : _b.call(plugin, document, formatRange, options)); | ||
edits = yield ((_c = plugin.provideDocumentFormattingEdits) === null || _c === void 0 ? void 0 : _c.call(plugin, document, formatRange, options, token)); | ||
} | ||
@@ -171,0 +177,0 @@ } |
import type { LanguageServicePluginContext } from '../types'; | ||
import * as vscode from 'vscode-languageserver-protocol'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<vscode.LinkedEditingRanges | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, token: vscode.CancellationToken) => Promise<vscode.LinkedEditingRanges | undefined>; |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.register = void 0; | ||
const featureWorkers_1 = require("../utils/featureWorkers"); | ||
const shared = require("@volar/shared"); | ||
const common_1 = require("../utils/common"); | ||
function register(context) { | ||
return (uri, position) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.completion), (plugin, document, position) => { var _a; return (_a = plugin.findLinkedEditingRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position); }, (data, map) => map ? ({ | ||
return (uri, position, token) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.completion), (plugin, document, position) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideLinkedEditingRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, token); | ||
}, (data, map) => map ? ({ | ||
wordPattern: data.wordPattern, | ||
ranges: data.ranges.map(range => map.toSourceRange(range)).filter(shared.notEmpty), | ||
ranges: data.ranges.map(range => map.toSourceRange(range)).filter(common_1.notEmpty), | ||
}) : data); | ||
@@ -11,0 +16,0 @@ }; |
import type { LanguageServicePluginContext } from '../types'; | ||
import * as vscode from 'vscode-languageserver-protocol'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, positions: vscode.Position[]) => Promise<vscode.SelectionRange[] | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, positions: vscode.Position[], token: vscode.CancellationToken) => Promise<vscode.SelectionRange[] | undefined>; |
@@ -5,5 +5,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
const transformer = require("../transformer"); | ||
const shared = require("@volar/shared"); | ||
const common_1 = require("../utils/common"); | ||
function register(context) { | ||
return (uri, positions) => { | ||
return (uri, positions, token) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, positions, (positions, map, file) => { | ||
@@ -13,3 +13,3 @@ if (file.capabilities.documentFormatting) { | ||
.map(position => map.toGeneratedPosition(position)) | ||
.filter(shared.notEmpty); | ||
.filter(common_1.notEmpty); | ||
if (result.length) { | ||
@@ -20,3 +20,8 @@ return [result]; | ||
return []; | ||
}, (plugin, document, positions) => { var _a; return (_a = plugin.getSelectionRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, positions); }, (item, map) => map ? transformer.asSelectionRanges(item, range => map.toSourceRange(range)) : item, results => { | ||
}, (plugin, document, positions) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideSelectionRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, positions, token); | ||
}, (item, map) => map ? transformer.asSelectionRanges(item, range => map.toSourceRange(range)) : item, results => { | ||
for (let i = 0; i < results[0].length; i++) { | ||
@@ -23,0 +28,0 @@ const first = results[0][i]; |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createDocumentsAndSourceMaps = exports.MirrorMapWithDocument = exports.SourceMapWithDocuments = void 0; | ||
const language_core_1 = require("@volar/language-core"); | ||
const shared = require("@volar/shared"); | ||
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument"); | ||
const common_1 = require("./utils/common"); | ||
class SourceMapWithDocuments { | ||
@@ -206,3 +206,3 @@ constructor(sourceFileDocument, virtualFileDocument, map) { | ||
if (!map.has(fileName)) { | ||
map.set(fileName, vscode_languageserver_textdocument_1.TextDocument.create(ctx.fileNameToUri(fileName), shared.syntaxToLanguageId(fileName.substring(fileName.lastIndexOf('.') + 1)), version++, snapshot.getText(0, snapshot.getLength()))); | ||
map.set(fileName, vscode_languageserver_textdocument_1.TextDocument.create(ctx.fileNameToUri(fileName), (0, common_1.syntaxToLanguageId)(fileName.substring(fileName.lastIndexOf('.') + 1)), version++, snapshot.getText(0, snapshot.getLength()))); | ||
} | ||
@@ -209,0 +209,0 @@ return map.get(fileName); |
@@ -8,1 +8,3 @@ export * from '@volar/language-core'; | ||
export { showReferencesCommand, ShowReferencesCommandData } from './languageFeatures/codeLensResolve'; | ||
import * as vscode from 'vscode-languageserver-protocol'; | ||
export declare const standardSemanticTokensLegend: vscode.SemanticTokensLegend; |
@@ -16,3 +16,3 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.showReferencesCommand = exports.transformer = exports.mergeWorkspaceEdits = void 0; | ||
exports.standardSemanticTokensLegend = exports.showReferencesCommand = exports.transformer = exports.mergeWorkspaceEdits = void 0; | ||
__exportStar(require("@volar/language-core"), exports); | ||
@@ -27,2 +27,42 @@ __exportStar(require("./baseLanguageService"), exports); | ||
Object.defineProperty(exports, "showReferencesCommand", { enumerable: true, get: function () { return codeLensResolve_1.showReferencesCommand; } }); | ||
// https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#standard-token-types-and-modifiers | ||
exports.standardSemanticTokensLegend = { | ||
tokenTypes: [ | ||
'namespace', | ||
'class', | ||
'enum', | ||
'interface', | ||
'struct', | ||
'typeParameter', | ||
'type', | ||
'parameter', | ||
'variable', | ||
'property', | ||
'enumMember', | ||
'decorator', | ||
'event', | ||
'function', | ||
'method', | ||
'macro', | ||
'label', | ||
'comment', | ||
'string', | ||
'keyword', | ||
'number', | ||
'regexp', | ||
'operator', | ||
], | ||
tokenModifiers: [ | ||
'declaration', | ||
'definition', | ||
'readonly', | ||
'static', | ||
'deprecated', | ||
'abstract', | ||
'async', | ||
'modification', | ||
'documentation', | ||
'defaultLibrary', | ||
], | ||
}; | ||
//# sourceMappingURL=index.js.map |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginInstance, LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, autoInsertContext: Parameters<NonNullable<LanguageServicePluginInstance['doAutoInsert']>>[2]) => Promise<NonNullable<string | vscode.TextEdit | null | undefined> | undefined>; | ||
import type { LanguageServicePluginContext, AutoInsertionContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, autoInsertContext: AutoInsertionContext, token: vscode.CancellationToken) => Promise<NonNullable<string | vscode.TextEdit | null | undefined> | undefined>; |
@@ -5,3 +5,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function register(context) { | ||
return (uri, position, autoInsertContext) => { | ||
return (uri, position, autoInsertContext, token) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, { position, autoInsertContext }, function* (arg, map) { | ||
@@ -23,3 +23,8 @@ var _a; | ||
} | ||
}, (plugin, document, arg) => { var _a; return (_a = plugin.doAutoInsert) === null || _a === void 0 ? void 0 : _a.call(plugin, document, arg.position, arg.autoInsertContext); }, (item, map) => { | ||
}, (plugin, document, arg) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideAutoInsertionEdit) === null || _a === void 0 ? void 0 : _a.call(plugin, document, arg.position, arg.autoInsertContext, token); | ||
}, (item, map) => { | ||
if (!map || typeof item === 'string') | ||
@@ -26,0 +31,0 @@ return item; |
@@ -12,5 +12,5 @@ import type * as vscode from 'vscode-languageserver-protocol'; | ||
export declare function register(context: LanguageServicePluginContext): { | ||
doPrepare(uri: string, position: vscode.Position): Promise<vscode.CallHierarchyItem[] | undefined>; | ||
getIncomingCalls(item: vscode.CallHierarchyItem): Promise<vscode.CallHierarchyIncomingCall[]>; | ||
getOutgoingCalls(item: vscode.CallHierarchyItem): Promise<vscode.CallHierarchyOutgoingCall[]>; | ||
doPrepare(uri: string, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.CallHierarchyItem[] | undefined>; | ||
getIncomingCalls(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Promise<vscode.CallHierarchyIncomingCall[]>; | ||
getOutgoingCalls(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Promise<vscode.CallHierarchyOutgoingCall[]>; | ||
}; |
@@ -12,4 +12,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
exports.register = void 0; | ||
const shared = require("@volar/shared"); | ||
const path_1 = require("path"); | ||
const common_1 = require("../utils/common"); | ||
const dedupe = require("../utils/dedupe"); | ||
@@ -19,6 +19,8 @@ const featureWorkers_1 = require("../utils/featureWorkers"); | ||
return { | ||
doPrepare(uri, position) { | ||
doPrepare(uri, position, token) { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), (plugin, document, position, map) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
const items = yield ((_a = plugin.callHierarchy) === null || _a === void 0 ? void 0 : _a.prepare(document, position)); | ||
if (token.isCancellationRequested) | ||
return; | ||
const items = yield ((_a = plugin.provideCallHierarchyItems) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, token)); | ||
items === null || items === void 0 ? void 0 : items.forEach(item => { | ||
@@ -39,5 +41,5 @@ item.data = { | ||
.map(item => { var _a; return (_a = transformCallHierarchyItem(item, [])) === null || _a === void 0 ? void 0 : _a[0]; }) | ||
.filter(shared.notEmpty), arr => dedupe.withLocations(arr.flat())); | ||
.filter(common_1.notEmpty), arr => dedupe.withLocations(arr.flat())); | ||
}, | ||
getIncomingCalls(item) { | ||
getIncomingCalls(item, token) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -48,3 +50,3 @@ const data = item.data; | ||
const plugin = context.plugins[data.pluginId]; | ||
if (!plugin.callHierarchy) | ||
if (!plugin.provideCallHierarchyIncomingCalls) | ||
return incomingItems; | ||
@@ -54,3 +56,3 @@ Object.assign(item, data.original); | ||
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) { | ||
const _calls = yield plugin.callHierarchy.onIncomingCalls(item); | ||
const _calls = yield plugin.provideCallHierarchyIncomingCalls(item, token); | ||
for (const _call of _calls) { | ||
@@ -68,3 +70,3 @@ const calls = transformCallHierarchyItem(_call.from, _call.fromRanges); | ||
else { | ||
const _calls = yield plugin.callHierarchy.onIncomingCalls(item); | ||
const _calls = yield plugin.provideCallHierarchyIncomingCalls(item, token); | ||
for (const _call of _calls) { | ||
@@ -84,3 +86,3 @@ const calls = transformCallHierarchyItem(_call.from, _call.fromRanges); | ||
}, | ||
getOutgoingCalls(item) { | ||
getOutgoingCalls(item, token) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -91,3 +93,3 @@ const data = item.data; | ||
const plugin = context.plugins[data.pluginId]; | ||
if (!plugin.callHierarchy) | ||
if (!plugin.provideCallHierarchyOutgoingCalls) | ||
return items; | ||
@@ -97,3 +99,3 @@ Object.assign(item, data.original); | ||
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) { | ||
const _calls = yield plugin.callHierarchy.onOutgoingCalls(item); | ||
const _calls = yield plugin.provideCallHierarchyOutgoingCalls(item, token); | ||
for (const call of _calls) { | ||
@@ -111,3 +113,3 @@ const calls = transformCallHierarchyItem(call.to, call.fromRanges); | ||
else { | ||
const _calls = yield plugin.callHierarchy.onOutgoingCalls(item); | ||
const _calls = yield plugin.provideCallHierarchyOutgoingCalls(item, token); | ||
for (const call of _calls) { | ||
@@ -143,3 +145,3 @@ const calls = transformCallHierarchyItem(call.to, call.fromRanges); | ||
continue; | ||
const vueRanges = tsRanges.map(tsRange => map.toSourceRange(tsRange)).filter(shared.notEmpty); | ||
const vueRanges = tsRanges.map(tsRange => map.toSourceRange(tsRange)).filter(common_1.notEmpty); | ||
const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === path_1.posix.basename(context.uriToFileName(map.virtualFileDocument.uri)) ? path_1.posix.basename(context.uriToFileName(map.sourceFileDocument.uri)) : tsItem.name, uri: map.sourceFileDocument.uri, | ||
@@ -146,0 +148,0 @@ // TS Bug: `range: range` not works |
@@ -1,3 +0,3 @@ | ||
import type { CodeAction } from 'vscode-languageserver-protocol'; | ||
import type * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (item: CodeAction) => Promise<CodeAction>; | ||
export declare function register(context: LanguageServicePluginContext): (item: vscode.CodeAction, token: vscode.CancellationToken) => Promise<vscode.CodeAction>; |
@@ -14,11 +14,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function register(context) { | ||
return (item) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
return (item, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f; | ||
const data = item.data; | ||
if ((data === null || data === void 0 ? void 0 : data.type) === 'plugin') { | ||
const plugin = context.plugins[data.pluginId]; | ||
if (!((_a = plugin.codeAction) === null || _a === void 0 ? void 0 : _a.resolve)) | ||
if (!plugin.resolveCodeAction) | ||
return item; | ||
Object.assign(item, data.original); | ||
item = yield plugin.codeAction.resolve(item); | ||
item = yield plugin.resolveCodeAction(item, token); | ||
if (item.edit) { | ||
@@ -29,8 +29,8 @@ item.edit = (0, rename_1.embeddedEditToSourceEdit)(item.edit, context.documents, 'codeAction', { [data.uri]: data.version }); | ||
if ((data === null || data === void 0 ? void 0 : data.type) === 'rule') { | ||
const fixes = (_d = (_c = (_b = context.ruleFixes) === null || _b === void 0 ? void 0 : _b[data.documentUri]) === null || _c === void 0 ? void 0 : _c[data.ruleId]) === null || _d === void 0 ? void 0 : _d[data.ruleFixIndex]; | ||
const fixes = (_c = (_b = (_a = context.ruleFixes) === null || _a === void 0 ? void 0 : _a[data.documentUri]) === null || _b === void 0 ? void 0 : _b[data.ruleId]) === null || _c === void 0 ? void 0 : _c[data.ruleFixIndex]; | ||
const fix = fixes === null || fixes === void 0 ? void 0 : fixes[1][data.index]; | ||
if (fix) { | ||
let edit = (_f = yield ((_e = fix.getWorkspaceEdit) === null || _e === void 0 ? void 0 : _e.call(fix, fixes[0]))) !== null && _f !== void 0 ? _f : undefined; | ||
let edit = (_e = yield ((_d = fix.getWorkspaceEdit) === null || _d === void 0 ? void 0 : _d.call(fix, fixes[0]))) !== null && _e !== void 0 ? _e : undefined; | ||
if (!edit) { | ||
const edits = yield ((_g = fix.getEdits) === null || _g === void 0 ? void 0 : _g.call(fix, fixes[0])); | ||
const edits = yield ((_f = fix.getEdits) === null || _f === void 0 ? void 0 : _f.call(fix, fixes[0])); | ||
if (edits) { | ||
@@ -37,0 +37,0 @@ edit = { |
@@ -20,2 +20,2 @@ import * as vscode from 'vscode-languageserver-protocol'; | ||
} | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext) => Promise<vscode.CodeAction[] | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range, codeActionContext: vscode.CodeActionContext, token: vscode.CancellationToken) => Promise<vscode.CodeAction[] | undefined>; |
@@ -12,3 +12,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
exports.register = void 0; | ||
const shared = require("@volar/shared"); | ||
const transformer = require("../transformer"); | ||
@@ -21,3 +20,3 @@ const vscode = require("vscode-languageserver-protocol"); | ||
function register(context) { | ||
return (uri, range, codeActionContext) => __awaiter(this, void 0, void 0, function* () { | ||
return (uri, range, codeActionContext, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e; | ||
@@ -60,3 +59,5 @@ const sourceDocument = context.getTextDocument(uri); | ||
}, (plugin, document, { range, codeActionContext }) => __awaiter(this, void 0, void 0, function* () { | ||
var _f, _g; | ||
var _f; | ||
if (token.isCancellationRequested) | ||
return; | ||
const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin); | ||
@@ -74,7 +75,7 @@ const diagnostics = codeActionContext.diagnostics.filter(diagnostic => { | ||
}); | ||
const codeActions = yield ((_g = (_f = plugin.codeAction) === null || _f === void 0 ? void 0 : _f.on) === null || _g === void 0 ? void 0 : _g.call(_f, document, range, Object.assign(Object.assign({}, codeActionContext), { diagnostics }))); | ||
const codeActions = yield ((_f = plugin.provideCodeActions) === null || _f === void 0 ? void 0 : _f.call(plugin, document, range, Object.assign(Object.assign({}, codeActionContext), { diagnostics }), token)); | ||
codeActions === null || codeActions === void 0 ? void 0 : codeActions.forEach(codeAction => { | ||
codeAction.data = { | ||
uri, | ||
version: document.version, | ||
version: sourceDocument.version, | ||
type: 'plugin', | ||
@@ -102,3 +103,3 @@ original: { | ||
} | ||
}).filter(shared.notEmpty), arr => dedupe.withCodeAction(arr.flat())); | ||
}).filter(common_1.notEmpty), arr => dedupe.withCodeAction(arr.flat())); | ||
const ruleActions = []; | ||
@@ -105,0 +106,0 @@ for (const diagnostic of codeActionContext.diagnostics) { |
@@ -15,2 +15,2 @@ import type { LanguageServicePluginContext } from '../types'; | ||
} | ||
export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.CodeLens[]>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, token: vscode.CancellationToken) => Promise<vscode.CodeLens[]>; |
@@ -12,12 +12,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
exports.register = void 0; | ||
const shared = require("@volar/shared"); | ||
const featureWorkers_1 = require("../utils/featureWorkers"); | ||
const vscode = require("vscode-languageserver-protocol"); | ||
const common_1 = require("../utils/common"); | ||
function register(context) { | ||
return (uri) => __awaiter(this, void 0, void 0, function* () { | ||
return (uri, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c; | ||
const referencesCodeLendsEnabled = (_b = yield ((_a = context.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.codeLens.references'))) !== null && _b !== void 0 ? _b : true; | ||
return (_c = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], (plugin, document) => __awaiter(this, void 0, void 0, function* () { | ||
var _d, _e, _f, _g; | ||
let codeLens = yield ((_e = (_d = plugin.codeLens) === null || _d === void 0 ? void 0 : _d.on) === null || _e === void 0 ? void 0 : _e.call(_d, document)); | ||
var _d, _e; | ||
if (token.isCancellationRequested) | ||
return; | ||
let codeLens = yield ((_d = plugin.provideCodeLenses) === null || _d === void 0 ? void 0 : _d.call(plugin, document, token)); | ||
const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin); | ||
@@ -35,3 +37,3 @@ codeLens === null || codeLens === void 0 ? void 0 : codeLens.forEach(codeLens => { | ||
if (referencesCodeLendsEnabled) { | ||
const referencesCodeLensLocs = yield ((_g = (_f = plugin.referencesCodeLens) === null || _f === void 0 ? void 0 : _f.on) === null || _g === void 0 ? void 0 : _g.call(_f, document)); | ||
const referencesCodeLensLocs = yield ((_e = plugin.provideReferencesCodeLenses) === null || _e === void 0 ? void 0 : _e.call(plugin, document, token)); | ||
const referencesCodeLens = referencesCodeLensLocs === null || referencesCodeLensLocs === void 0 ? void 0 : referencesCodeLensLocs.map(loc => vscode.CodeLens.create(loc.range, { | ||
@@ -56,3 +58,3 @@ kind: 'references', | ||
} | ||
}).filter(shared.notEmpty), arr => arr.flat())) !== null && _c !== void 0 ? _c : []; | ||
}).filter(common_1.notEmpty), arr => arr.flat())) !== null && _c !== void 0 ? _c : []; | ||
}); | ||
@@ -59,0 +61,0 @@ } |
@@ -5,2 +5,2 @@ import * as vscode from 'vscode-languageserver-protocol'; | ||
export type ShowReferencesCommandData = [string, vscode.Position, vscode.Location[]]; | ||
export declare function register(context: LanguageServicePluginContext): (item: vscode.CodeLens) => Promise<vscode.CodeLens>; | ||
export declare function register(context: LanguageServicePluginContext): (item: vscode.CodeLens, token: vscode.CancellationToken) => Promise<vscode.CodeLens>; |
@@ -16,19 +16,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const findReferences = references.register(context); | ||
return (item) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c; | ||
return (item, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
const data = item.data; | ||
if ((data === null || data === void 0 ? void 0 : data.kind) === 'normal') { | ||
const plugin = context.plugins[data.pluginId]; | ||
if (!((_a = plugin.codeLens) === null || _a === void 0 ? void 0 : _a.resolve)) | ||
if (!plugin.resolveCodeLens) | ||
return item; | ||
Object.assign(item, data.original); | ||
item = yield plugin.codeLens.resolve(item); | ||
item = yield plugin.resolveCodeLens(item, token); | ||
// item.range already transformed in codeLens request | ||
} | ||
if ((data === null || data === void 0 ? void 0 : data.kind) === 'references') { | ||
let references = (_b = yield findReferences(data.uri, item.range.start)) !== null && _b !== void 0 ? _b : []; | ||
let references = (_a = yield findReferences(data.uri, item.range.start, token)) !== null && _a !== void 0 ? _a : []; | ||
const plugin = context.plugins[data.pluginId]; | ||
const document = context.getTextDocument(data.uri); | ||
if (document && ((_c = plugin.referencesCodeLens) === null || _c === void 0 ? void 0 : _c.resolve)) { | ||
references = yield plugin.referencesCodeLens.resolve(document, data.location, references); | ||
if (document && plugin.resolveReferencesCodeLens) { | ||
references = yield plugin.resolveReferencesCodeLens(document, data.location, references, token); | ||
} | ||
@@ -35,0 +35,0 @@ item.command = { |
@@ -11,2 +11,2 @@ import * as vscode from 'vscode-languageserver-protocol'; | ||
} | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, completionContext?: vscode.CompletionContext) => Promise<vscode.CompletionList>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, completionContext: vscode.CompletionContext | undefined, token: vscode.CancellationToken) => Promise<vscode.CompletionList>; |
@@ -17,4 +17,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
let cache; | ||
return (uri, position, completionContext) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e; | ||
return (uri, position, completionContext, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b; | ||
completionContext !== null && completionContext !== void 0 ? completionContext : (completionContext = { | ||
triggerKind: vscode.CompletionTriggerKind.Invoked, | ||
}); | ||
let document; | ||
@@ -29,5 +32,5 @@ if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerKind) === vscode.CompletionTriggerKind.TriggerForIncompleteCompletions | ||
for (const mapped of map.toGeneratedPositions(position, data => !!data.completion)) { | ||
if (!((_a = cacheData.plugin.complete) === null || _a === void 0 ? void 0 : _a.on)) | ||
if (!cacheData.plugin.provideCompletionItems) | ||
continue; | ||
const embeddedCompletionList = yield cacheData.plugin.complete.on(map.virtualFileDocument, mapped, completionContext); | ||
const embeddedCompletionList = yield cacheData.plugin.provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token); | ||
if (!embeddedCompletionList) { | ||
@@ -53,5 +56,5 @@ cacheData.list.isIncomplete = false; | ||
else if (document = context.getTextDocument(uri)) { | ||
if (!((_b = cacheData.plugin.complete) === null || _b === void 0 ? void 0 : _b.on)) | ||
if (!cacheData.plugin.provideCompletionItems) | ||
continue; | ||
const completionList = yield cacheData.plugin.complete.on(document, position, completionContext); | ||
const completionList = yield cacheData.plugin.provideCompletionItems(document, position, completionContext, token); | ||
if (!completionList) { | ||
@@ -77,3 +80,3 @@ cacheData.list.isIncomplete = false; | ||
else { | ||
const rootFile = (_c = context.documents.getSourceByUri(uri)) === null || _c === void 0 ? void 0 : _c.root; | ||
const rootFile = (_a = context.documents.getSourceByUri(uri)) === null || _a === void 0 ? void 0 : _a.root; | ||
cache = { | ||
@@ -88,3 +91,3 @@ uri, | ||
yield (0, definePlugin_1.visitEmbedded)(context.documents, rootFile, (_, map) => __awaiter(this, void 0, void 0, function* () { | ||
var _f, _g; | ||
var _c; | ||
const plugins = Object.values(context.plugins).sort(sortPlugins); | ||
@@ -97,15 +100,17 @@ let _data; | ||
for (const plugin of plugins) { | ||
if (!((_f = plugin.complete) === null || _f === void 0 ? void 0 : _f.on)) | ||
if (token.isCancellationRequested) | ||
break; | ||
if (!plugin.provideCompletionItems) | ||
continue; | ||
if (plugin.complete.isAdditional && !isFirstMapping) | ||
if (plugin.isAdditionalCompletion && !isFirstMapping) | ||
continue; | ||
if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_g = plugin.complete.triggerCharacters) === null || _g === void 0 ? void 0 : _g.includes(completionContext.triggerCharacter))) | ||
if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_c = plugin.triggerCharacters) === null || _c === void 0 ? void 0 : _c.includes(completionContext.triggerCharacter))) | ||
continue; | ||
const isAdditional = _data && typeof _data.completion === 'object' && _data.completion.additional || plugin.complete.isAdditional; | ||
const isAdditional = _data && typeof _data.completion === 'object' && _data.completion.additional || plugin.isAdditionalCompletion; | ||
if (cache.mainCompletion && (!isAdditional || (cache === null || cache === void 0 ? void 0 : cache.mainCompletion.documentUri) !== map.virtualFileDocument.uri)) | ||
continue; | ||
// avoid duplicate items with .vue and .vue.html | ||
if (plugin.complete.isAdditional && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin))) | ||
if (plugin.isAdditionalCompletion && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin))) | ||
continue; | ||
const embeddedCompletionList = yield plugin.complete.on(map.virtualFileDocument, mapped, completionContext); | ||
const embeddedCompletionList = yield plugin.provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token); | ||
if (!embeddedCompletionList || !embeddedCompletionList.items.length) | ||
@@ -147,17 +152,19 @@ continue; | ||
for (const plugin of plugins) { | ||
if (!((_d = plugin.complete) === null || _d === void 0 ? void 0 : _d.on)) | ||
if (token.isCancellationRequested) | ||
break; | ||
if (!plugin.provideCompletionItems) | ||
continue; | ||
if (plugin.complete.isAdditional && !isFirstMapping) | ||
if (plugin.isAdditionalCompletion && !isFirstMapping) | ||
continue; | ||
if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_e = plugin.complete.triggerCharacters) === null || _e === void 0 ? void 0 : _e.includes(completionContext.triggerCharacter))) | ||
if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_b = plugin.triggerCharacters) === null || _b === void 0 ? void 0 : _b.includes(completionContext.triggerCharacter))) | ||
continue; | ||
if (cache.mainCompletion && (!plugin.complete.isAdditional || cache.mainCompletion.documentUri !== document.uri)) | ||
if (cache.mainCompletion && (!plugin.isAdditionalCompletion || cache.mainCompletion.documentUri !== document.uri)) | ||
continue; | ||
// avoid duplicate items with .vue and .vue.html | ||
if (plugin.complete.isAdditional && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin))) | ||
if (plugin.isAdditionalCompletion && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin))) | ||
continue; | ||
const completionList = yield plugin.complete.on(document, position, completionContext); | ||
const completionList = yield plugin.provideCompletionItems(document, position, completionContext, token); | ||
if (!completionList || !completionList.items.length) | ||
continue; | ||
if (!plugin.complete.isAdditional) { | ||
if (!plugin.isAdditionalCompletion) { | ||
cache.mainCompletion = { documentUri: document.uri }; | ||
@@ -187,4 +194,3 @@ } | ||
function sortPlugins(a, b) { | ||
var _a, _b; | ||
return (((_a = b.complete) === null || _a === void 0 ? void 0 : _a.isAdditional) ? -1 : 1) - (((_b = a.complete) === null || _b === void 0 ? void 0 : _b.isAdditional) ? -1 : 1); | ||
return (b.isAdditionalCompletion ? -1 : 1) - (a.isAdditionalCompletion ? -1 : 1); | ||
} | ||
@@ -191,0 +197,0 @@ function combineCompletionList(lists) { |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (item: vscode.CompletionItem) => Promise<vscode.CompletionItem>; | ||
export declare function register(context: LanguageServicePluginContext): (item: vscode.CompletionItem, token: vscode.CancellationToken) => Promise<vscode.CompletionItem>; |
@@ -14,8 +14,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function register(context) { | ||
return (item) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
return (item, token) => __awaiter(this, void 0, void 0, function* () { | ||
const data = item.data; | ||
if (data) { | ||
const plugin = context.plugins[data.pluginId]; | ||
if (!((_a = plugin.complete) === null || _a === void 0 ? void 0 : _a.resolve)) | ||
if (!plugin.resolveCompletionItem) | ||
return item; | ||
@@ -25,3 +24,3 @@ item = Object.assign(item, data.original); | ||
for (const [_, map] of context.documents.getMapsByVirtualFileUri(data.map.embeddedDocumentUri)) { | ||
item = yield plugin.complete.resolve(item); | ||
item = yield plugin.resolveCompletionItem(item, token); | ||
item = transformer.asCompletionItem(item, embeddedRange => { | ||
@@ -37,3 +36,3 @@ var _a; | ||
else { | ||
item = yield plugin.complete.resolve(item); | ||
item = yield plugin.resolveCompletionItem(item, token); | ||
} | ||
@@ -40,0 +39,0 @@ } |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
import { FileRangeCapabilities, MirrorBehaviorCapabilities } from '@volar/language-core'; | ||
export declare function register(context: LanguageServicePluginContext, api: 'findDefinition' | 'findTypeDefinition' | 'findImplementations', isValidMapping: (data: FileRangeCapabilities) => boolean, isValidMirrorPosition: (mirrorData: MirrorBehaviorCapabilities) => boolean): (uri: string, position: vscode.Position) => Promise<vscode.LocationLink[] | undefined>; | ||
export declare function register(context: LanguageServicePluginContext, apiName: 'provideDefinition' | 'provideTypeDefinition' | 'provideImplementation', isValidMapping: (data: FileRangeCapabilities) => boolean, isValidMirrorPosition: (mirrorData: MirrorBehaviorCapabilities) => boolean): (uri: string, position: vscode.Position, token: vscode.CancellationToken) => Promise<vscode.LocationLink[] | undefined>; |
@@ -12,8 +12,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
exports.register = void 0; | ||
const shared = require("@volar/shared"); | ||
const featureWorkers_1 = require("../utils/featureWorkers"); | ||
const dedupe = require("../utils/dedupe"); | ||
function register(context, api, isValidMapping, isValidMirrorPosition) { | ||
return (uri, position) => { | ||
const common_1 = require("../utils/common"); | ||
function register(context, apiName, isValidMapping, isValidMirrorPosition) { | ||
return (uri, position, token) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, isValidMapping), (plugin, document, position) => __awaiter(this, void 0, void 0, function* () { | ||
if (token.isCancellationRequested) | ||
return; | ||
const recursiveChecker = dedupe.createLocationSet(); | ||
@@ -24,9 +26,6 @@ const result = []; | ||
function withMirrors(document, position, originDefinition) { | ||
var _a, _b, _c, _d; | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const _api = api === 'findDefinition' ? (_a = plugin.definition) === null || _a === void 0 ? void 0 : _a.on : | ||
api === 'findTypeDefinition' ? (_b = plugin.definition) === null || _b === void 0 ? void 0 : _b.onType : | ||
api === 'findImplementations' ? plugin.findImplementations : | ||
undefined; | ||
if (!_api) | ||
const api = plugin[apiName]; | ||
if (!api) | ||
return; | ||
@@ -36,7 +35,7 @@ if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) | ||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } }); | ||
const definitions = (_c = yield (_api === null || _api === void 0 ? void 0 : _api(document, position))) !== null && _c !== void 0 ? _c : []; | ||
const definitions = (_a = yield (api === null || api === void 0 ? void 0 : api(document, position, token))) !== null && _a !== void 0 ? _a : []; | ||
for (const definition of definitions) { | ||
let foundMirrorPosition = false; | ||
recursiveChecker.add({ uri: definition.targetUri, range: { start: definition.targetRange.start, end: definition.targetRange.start } }); | ||
const mirrorMap = (_d = context.documents.getMirrorMapByUri(definition.targetUri)) === null || _d === void 0 ? void 0 : _d[1]; | ||
const mirrorMap = (_b = context.documents.getMirrorMapByUri(definition.targetUri)) === null || _b === void 0 ? void 0 : _b[1]; | ||
if (mirrorMap) { | ||
@@ -86,3 +85,3 @@ for (const mapped of mirrorMap.findMirrorPositions(definition.targetSelectionRange.start)) { | ||
return link; | ||
}).filter(shared.notEmpty), arr => dedupe.withLocationLinks(arr.flat())); | ||
}).filter(common_1.notEmpty), arr => dedupe.withLocationLinks(arr.flat())); | ||
}; | ||
@@ -89,0 +88,0 @@ } |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<vscode.DocumentHighlight[] | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, token: vscode.CancellationToken) => Promise<vscode.DocumentHighlight[] | undefined>; |
@@ -12,10 +12,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
exports.register = void 0; | ||
const shared = require("@volar/shared"); | ||
const featureWorkers_1 = require("../utils/featureWorkers"); | ||
const dedupe = require("../utils/dedupe"); | ||
const common_1 = require("../utils/common"); | ||
function register(context) { | ||
return (uri, position) => { | ||
return (uri, position, token) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, | ||
// note https://github.com/johnsoncodehk/volar/issues/2009 | ||
data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), (plugin, document, position) => __awaiter(this, void 0, void 0, function* () { | ||
if (token.isCancellationRequested) | ||
return; | ||
const recursiveChecker = dedupe.createLocationSet(); | ||
@@ -28,3 +30,3 @@ const result = []; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!plugin.findDocumentHighlights) | ||
if (!plugin.provideDocumentHighlights) | ||
return; | ||
@@ -34,3 +36,3 @@ if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) | ||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } }); | ||
const references = (_a = yield plugin.findDocumentHighlights(document, position)) !== null && _a !== void 0 ? _a : []; | ||
const references = (_a = yield plugin.provideDocumentHighlights(document, position, token)) !== null && _a !== void 0 ? _a : []; | ||
for (const reference of references) { | ||
@@ -56,10 +58,10 @@ let foundMirrorPosition = false; | ||
} | ||
}), (data, map) => data.map(highlisht => { | ||
}), (data, map) => data.map(highlight => { | ||
if (!map) | ||
return highlisht; | ||
const range = map.toSourceRange(highlisht.range); | ||
return highlight; | ||
const range = map.toSourceRange(highlight.range); | ||
if (range) { | ||
return Object.assign(Object.assign({}, highlisht), { range }); | ||
return Object.assign(Object.assign({}, highlight), { range }); | ||
} | ||
}).filter(shared.notEmpty), arr => arr.flat()); | ||
}).filter(common_1.notEmpty), arr => arr.flat()); | ||
}; | ||
@@ -66,0 +68,0 @@ } |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string) => Promise<vscode.DocumentLink[]>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, token: vscode.CancellationToken) => Promise<vscode.DocumentLink[]>; |
@@ -12,8 +12,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
exports.register = void 0; | ||
const shared = require("@volar/shared"); | ||
const featureWorkers_1 = require("../utils/featureWorkers"); | ||
const common_1 = require("../utils/common"); | ||
function register(context) { | ||
return (uri) => __awaiter(this, void 0, void 0, function* () { | ||
return (uri, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
const pluginLinks = (_a = yield (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => { var _a; return (_a = plugin.findDocumentLinks) === null || _a === void 0 ? void 0 : _a.call(plugin, document); }, (data, map) => data.map(link => { | ||
const pluginLinks = (_a = yield (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideLinks) === null || _a === void 0 ? void 0 : _a.call(plugin, document, token); | ||
}, (data, map) => data.map(link => { | ||
if (!map) | ||
@@ -25,3 +30,3 @@ return link; | ||
} | ||
}).filter(shared.notEmpty), arr => arr.flat())) !== null && _a !== void 0 ? _a : []; | ||
}).filter(common_1.notEmpty), arr => arr.flat())) !== null && _a !== void 0 ? _a : []; | ||
const maps = context.documents.getMapsBySourceFileUri(uri); | ||
@@ -28,0 +33,0 @@ const fictitiousLinks = maps ? getFictitiousLinks(context.documents.getDocumentByUri(maps.snapshot, uri), maps.maps) : []; |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import { SemanticToken } from '@volar/language-service'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range | undefined, legend: vscode.SemanticTokensLegend, cancelToken: vscode.CancellationToken, reportProgress?: ((tokens: SemanticToken[]) => void) | undefined) => Promise<SemanticToken[] | undefined> | undefined; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range | undefined, legend: vscode.SemanticTokensLegend, token: vscode.CancellationToken, reportProgress?: ((tokens: vscode.SemanticTokens) => void) | undefined) => Promise<vscode.SemanticTokens | undefined>; |
@@ -0,8 +1,18 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.register = void 0; | ||
const shared = require("@volar/shared"); | ||
const vscode = require("vscode-languageserver-protocol"); | ||
const featureWorkers_1 = require("../utils/featureWorkers"); | ||
const SemanticTokensBuilder_1 = require("../utils/SemanticTokensBuilder"); | ||
const common_1 = require("../utils/common"); | ||
function register(context) { | ||
return (uri, range, legend, cancelToken, reportProgress) => { | ||
return (uri, range, legend, token, reportProgress) => __awaiter(this, void 0, void 0, function* () { | ||
const document = context.getTextDocument(uri); | ||
@@ -18,5 +28,3 @@ if (!document) | ||
]; | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, offsetRange, function* (offsetRange, map) { | ||
if (cancelToken === null || cancelToken === void 0 ? void 0 : cancelToken.isCancellationRequested) | ||
return; | ||
const tokens = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, offsetRange, function* (offsetRange, map) { | ||
let range; | ||
@@ -41,3 +49,5 @@ for (const mapping of map.map.mappings) { | ||
var _a; | ||
return (_a = plugin.findDocumentSemanticTokens) === null || _a === void 0 ? void 0 : _a.call(plugin, document, vscode.Range.create(document.positionAt(offsetRange[0]), document.positionAt(offsetRange[1])), legend); | ||
if (token === null || token === void 0 ? void 0 : token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideDocumentSemanticTokens) === null || _a === void 0 ? void 0 : _a.call(plugin, document, vscode.Range.create(document.positionAt(offsetRange[0]), document.positionAt(offsetRange[1])), legend, token); | ||
}, (tokens, map) => tokens.map(_token => { | ||
@@ -53,6 +63,17 @@ if (!map) | ||
} | ||
}).filter(shared.notEmpty), tokens => tokens.flat(), reportProgress); | ||
}; | ||
}).filter(common_1.notEmpty), tokens => tokens.flat(), tokens => reportProgress === null || reportProgress === void 0 ? void 0 : reportProgress(buildTokens(tokens))); | ||
if (tokens) { | ||
return buildTokens(tokens); | ||
} | ||
}); | ||
} | ||
exports.register = register; | ||
function buildTokens(tokens) { | ||
const builder = new SemanticTokensBuilder_1.SemanticTokensBuilder(); | ||
const sortedTokens = tokens.sort((a, b) => a[0] - b[0] === 0 ? a[1] - b[1] : a[0] - b[0]); | ||
for (const token of sortedTokens) { | ||
builder.push(...token); | ||
} | ||
return builder.build(); | ||
} | ||
//# sourceMappingURL=documentSemanticTokens.js.map |
import type { LanguageServicePluginContext } from '../types'; | ||
import * as vscode from 'vscode-languageserver-protocol'; | ||
import { NullableResult } from '@volar/language-service'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string) => NullableResult<vscode.Location[]>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, token: vscode.CancellationToken) => NullableResult<vscode.Location[]>; |
@@ -12,7 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
exports.register = void 0; | ||
const shared = require("@volar/shared"); | ||
const featureWorkers_1 = require("../utils/featureWorkers"); | ||
const dedupe = require("../utils/dedupe"); | ||
const common_1 = require("../utils/common"); | ||
function register(context) { | ||
return (uri) => { | ||
return (uri, token) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, function* (_) { | ||
@@ -22,3 +22,5 @@ yield _; | ||
var _a, _b; | ||
return (_b = yield ((_a = plugin.findFileReferences) === null || _a === void 0 ? void 0 : _a.call(plugin, document))) !== null && _b !== void 0 ? _b : []; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_b = yield ((_a = plugin.provideFileReferences) === null || _a === void 0 ? void 0 : _a.call(plugin, document, token))) !== null && _b !== void 0 ? _b : []; | ||
}), (data) => data.map(reference => { | ||
@@ -36,3 +38,3 @@ if (!context.documents.hasVirtualFileByUri(reference.uri)) { | ||
} | ||
}).filter(shared.notEmpty), arr => dedupe.withLocations(arr.flat())); | ||
}).filter(common_1.notEmpty), arr => dedupe.withLocations(arr.flat())); | ||
}; | ||
@@ -39,0 +41,0 @@ } |
import type { LanguageServicePluginContext } from '../types'; | ||
import type * as _ from 'vscode-languageserver-protocol'; | ||
export declare function register(context: LanguageServicePluginContext): (oldUri: string, newUri: string) => Promise<_.WorkspaceEdit | undefined>; | ||
import type * as vscode from 'vscode-languageserver-protocol'; | ||
export declare function register(context: LanguageServicePluginContext): (oldUri: string, newUri: string, token: vscode.CancellationToken) => Promise<_.WorkspaceEdit | undefined>; |
@@ -16,3 +16,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function register(context) { | ||
return (oldUri, newUri) => __awaiter(this, void 0, void 0, function* () { | ||
return (oldUri, newUri, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
@@ -34,5 +34,7 @@ const rootFile = (_a = context.documents.getSourceByUri(oldUri)) === null || _a === void 0 ? void 0 : _a.root; | ||
for (const plugin of Object.values(context.plugins)) { | ||
if (!plugin.doFileRename) | ||
if (!token.isCancellationRequested) | ||
break; | ||
if (!plugin.provideFileRenameEdits) | ||
continue; | ||
const workspaceEdit = yield plugin.doFileRename(oldUri, newUri); | ||
const workspaceEdit = yield plugin.provideFileRenameEdits(oldUri, newUri, token); | ||
if (workspaceEdit) { | ||
@@ -39,0 +41,0 @@ const result = (0, rename_1.embeddedEditToSourceEdit)(workspaceEdit, context.documents, 'fileName'); |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<vscode.Hover | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, token: vscode.CancellationToken) => Promise<vscode.Hover | undefined>; |
@@ -7,4 +7,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function register(context) { | ||
return (uri, position) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.hover), (plugin, document, position) => { var _a; return (_a = plugin.doHover) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position); }, (item, map) => { | ||
return (uri, position, token) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.hover), (plugin, document, position) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideHover) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, token); | ||
}, (item, map) => { | ||
if (!map || !item.range) | ||
@@ -11,0 +16,0 @@ return item; |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range) => Promise<vscode.InlayHint[] | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, range: vscode.Range, token: vscode.CancellationToken) => Promise<vscode.InlayHint[] | undefined>; |
@@ -12,3 +12,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
exports.register = void 0; | ||
const shared = require("@volar/shared"); | ||
const transformer = require("../transformer"); | ||
@@ -19,3 +18,3 @@ const vscode = require("vscode-languageserver-protocol"); | ||
function register(context) { | ||
return (uri, range) => __awaiter(this, void 0, void 0, function* () { | ||
return (uri, range, token) => __awaiter(this, void 0, void 0, function* () { | ||
const document = context.getTextDocument(uri); | ||
@@ -53,4 +52,6 @@ if (!document) | ||
}, (plugin, document, arg) => { | ||
var _a, _b; | ||
return (_b = (_a = plugin.inlayHints) === null || _a === void 0 ? void 0 : _a.on) === null || _b === void 0 ? void 0 : _b.call(_a, document, arg); | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideInlayHints) === null || _a === void 0 ? void 0 : _a.call(plugin, document, arg, token); | ||
}, (inlayHints, map) => inlayHints.map((_inlayHint) => { | ||
@@ -61,7 +62,7 @@ var _a; | ||
const position = map.toSourcePosition(_inlayHint.position); | ||
const edits = (_a = _inlayHint.textEdits) === null || _a === void 0 ? void 0 : _a.map(textEdit => transformer.asTextEdit(textEdit, range => map.toSourceRange(range), map.virtualFileDocument)).filter(shared.notEmpty); | ||
const edits = (_a = _inlayHint.textEdits) === null || _a === void 0 ? void 0 : _a.map(textEdit => transformer.asTextEdit(textEdit, range => map.toSourceRange(range), map.virtualFileDocument)).filter(common_1.notEmpty); | ||
if (position) { | ||
return Object.assign(Object.assign({}, _inlayHint), { position, textEdits: edits }); | ||
} | ||
}).filter(shared.notEmpty), arr => arr.flat()); | ||
}).filter(common_1.notEmpty), arr => arr.flat()); | ||
}); | ||
@@ -68,0 +69,0 @@ } |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<vscode.Location[] | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, token: vscode.CancellationToken) => Promise<vscode.Location[] | undefined>; |
@@ -15,4 +15,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function register(context) { | ||
return (uri, position) => { | ||
return (uri, position, token) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), (plugin, document, position) => __awaiter(this, void 0, void 0, function* () { | ||
if (token.isCancellationRequested) | ||
return; | ||
const recursiveChecker = dedupe.createLocationSet(); | ||
@@ -25,3 +27,3 @@ const result = []; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!plugin.findReferences) | ||
if (!plugin.provideReferences) | ||
return; | ||
@@ -31,3 +33,3 @@ if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) | ||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } }); | ||
const references = (_a = yield plugin.findReferences(document, position)) !== null && _a !== void 0 ? _a : []; | ||
const references = (_a = yield plugin.provideReferences(document, position, token)) !== null && _a !== void 0 ? _a : []; | ||
for (const reference of references) { | ||
@@ -34,0 +36,0 @@ let foundMirrorPosition = false; |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
import { DocumentsAndSourceMaps } from '../documents'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, newName: string, token: vscode.CancellationToken) => Promise<vscode.WorkspaceEdit | undefined>; | ||
export declare function mergeWorkspaceEdits(original: vscode.WorkspaceEdit, ...others: vscode.WorkspaceEdit[]): void; | ||
export declare function embeddedEditToSourceEdit(tsResult: vscode.WorkspaceEdit, documents: DocumentsAndSourceMaps, mode: 'fileName' | 'rename' | 'codeAction' | 'format', versions?: Record<string, number>): vscode.WorkspaceEdit | undefined; |
@@ -16,3 +16,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function register(context) { | ||
return (uri, position, newName) => { | ||
return (uri, position, newName, token) => { | ||
let _data; | ||
@@ -32,2 +32,4 @@ return (0, featureWorkers_1.languageFeatureWorker)(context, uri, { position, newName }, function* (arg, map) { | ||
}, (plugin, document, arg) => __awaiter(this, void 0, void 0, function* () { | ||
if (token.isCancellationRequested) | ||
return; | ||
const recursiveChecker = dedupe.createLocationSet(); | ||
@@ -38,5 +40,5 @@ let result; | ||
function withMirrors(document, position, newName) { | ||
var _a, _b; | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!((_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.on)) | ||
if (!plugin.provideRenameEdits) | ||
return; | ||
@@ -46,3 +48,3 @@ if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) | ||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } }); | ||
const workspaceEdit = yield plugin.rename.on(document, position, newName); | ||
const workspaceEdit = yield plugin.provideRenameEdits(document, position, newName, token); | ||
if (!workspaceEdit) | ||
@@ -58,3 +60,3 @@ return; | ||
recursiveChecker.add({ uri: editUri, range: { start: textEdit.range.start, end: textEdit.range.start } }); | ||
const mirrorMap = (_b = context.documents.getMirrorMapByUri(editUri)) === null || _b === void 0 ? void 0 : _b[1]; | ||
const mirrorMap = (_a = context.documents.getMirrorMapByUri(editUri)) === null || _a === void 0 ? void 0 : _a[1]; | ||
if (mirrorMap) { | ||
@@ -61,0 +63,0 @@ for (const mapped of mirrorMap.findMirrorPositions(textEdit.range.start)) { |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position) => Promise<NonNullable<vscode.Range | vscode.ResponseError<void> | null | undefined> | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, token: vscode.CancellationToken) => Promise<NonNullable<vscode.Range | vscode.ResponseError<void> | null | undefined> | undefined>; |
@@ -6,4 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function register(context) { | ||
return (uri, position) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), (plugin, document, position) => { var _a, _b; return (_b = (_a = plugin.rename) === null || _a === void 0 ? void 0 : _a.prepare) === null || _b === void 0 ? void 0 : _b.call(_a, document, position); }, (item, map) => { | ||
return (uri, position, token) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), (plugin, document, position) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideRenameRange) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, token); | ||
}, (item, map) => { | ||
if (!map) { | ||
@@ -10,0 +15,0 @@ return item; |
@@ -1,3 +0,3 @@ | ||
import type * as vscode from 'vscode-languageserver-protocol'; | ||
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, signatureHelpContext?: vscode.SignatureHelpContext) => Promise<vscode.SignatureHelp | undefined>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, position: vscode.Position, signatureHelpContext: vscode.SignatureHelpContext | undefined, token: vscode.CancellationToken) => Promise<vscode.SignatureHelp | undefined>; |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.register = void 0; | ||
const vscode = require("vscode-languageserver-protocol"); | ||
const featureWorkers_1 = require("../utils/featureWorkers"); | ||
function register(context) { | ||
return (uri, position, signatureHelpContext) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.completion), (plugin, document, position) => { var _a; return (_a = plugin.getSignatureHelp) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, signatureHelpContext); }, (data) => data); | ||
return (uri, position, signatureHelpContext, token) => { | ||
signatureHelpContext !== null && signatureHelpContext !== void 0 ? signatureHelpContext : (signatureHelpContext = { | ||
triggerKind: vscode.SignatureHelpTriggerKind.Invoked, | ||
isRetrigger: false, | ||
}); | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.completion), (plugin, document, position) => { | ||
var _a, _b; | ||
if (token.isCancellationRequested) | ||
return; | ||
if ((signatureHelpContext === null || signatureHelpContext === void 0 ? void 0 : signatureHelpContext.triggerKind) === vscode.SignatureHelpTriggerKind.TriggerCharacter | ||
&& signatureHelpContext.triggerCharacter | ||
&& !((_a = (signatureHelpContext.isRetrigger | ||
? plugin.signatureHelpRetriggerCharacters | ||
: plugin.signatureHelpTriggerCharacters)) === null || _a === void 0 ? void 0 : _a.includes(signatureHelpContext.triggerCharacter))) { | ||
return; | ||
} | ||
return (_b = plugin.provideSignatureHelp) === null || _b === void 0 ? void 0 : _b.call(plugin, document, position, signatureHelpContext, token); | ||
}, (data) => data); | ||
}; | ||
@@ -8,0 +25,0 @@ } |
@@ -17,2 +17,2 @@ import * as vscode from 'vscode-languageserver-protocol'; | ||
} | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, token?: vscode.CancellationToken, response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>; | ||
export declare function register(context: LanguageServicePluginContext): (uri: string, token: vscode.CancellationToken, mode: 'all' | 'semantic' | 'syntactic', response?: ((result: vscode.Diagnostic[]) => void) | undefined) => Promise<vscode.Diagnostic[]>; |
@@ -12,4 +12,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
exports.register = exports.updateRange = void 0; | ||
const shared = require("@volar/shared"); | ||
const vscode = require("vscode-languageserver-protocol"); | ||
const common_1 = require("../utils/common"); | ||
const dedupe = require("../utils/dedupe"); | ||
@@ -93,5 +93,3 @@ const featureWorkers_1 = require("../utils/featureWorkers"); | ||
semantic: new Map(), | ||
declaration: new Map(), | ||
syntactic: new Map(), | ||
suggestion: new Map(), | ||
semantic_rules: new Map(), | ||
@@ -101,3 +99,3 @@ syntax_rules: new Map(), | ||
}; | ||
return (uri, token, response) => __awaiter(this, void 0, void 0, function* () { | ||
return (uri, token, mode, response) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
@@ -110,4 +108,2 @@ const newDocument = context.getTextDocument(uri); | ||
semantic: { errors: [] }, | ||
declaration: { errors: [] }, | ||
suggestion: { errors: [] }, | ||
syntactic: { errors: [] }, | ||
@@ -144,15 +140,15 @@ semantic_rules: { errors: [] }, | ||
} | ||
yield lintWorker('onFormat', cacheMaps.format_rules, lastResponse.format_rules); | ||
doResponse(); | ||
yield lintWorker('onSyntax', cacheMaps.syntax_rules, lastResponse.syntax_rules); | ||
doResponse(); | ||
yield worker('onSyntactic', cacheMaps.syntactic, lastResponse.syntactic); | ||
doResponse(); | ||
yield worker('onSuggestion', cacheMaps.suggestion, lastResponse.suggestion); | ||
doResponse(); | ||
yield lintWorker('onSemantic', cacheMaps.semantic_rules, lastResponse.semantic_rules); | ||
doResponse(); | ||
yield worker('onSemantic', cacheMaps.semantic, lastResponse.semantic); | ||
doResponse(); | ||
yield worker('onDeclaration', cacheMaps.declaration, lastResponse.declaration); | ||
if (mode === 'all' || mode === 'syntactic') { | ||
yield lintWorker('onFormat', cacheMaps.format_rules, lastResponse.format_rules); | ||
doResponse(); | ||
yield lintWorker('onSyntax', cacheMaps.syntax_rules, lastResponse.syntax_rules); | ||
doResponse(); | ||
yield worker('provideSyntacticDiagnostics', cacheMaps.syntactic, lastResponse.syntactic); | ||
doResponse(); | ||
} | ||
if (mode === 'all' || mode === 'semantic') { | ||
yield lintWorker('onSemantic', cacheMaps.semantic_rules, lastResponse.semantic_rules); | ||
doResponse(); | ||
yield worker('provideSemanticDiagnostics', cacheMaps.semantic, lastResponse.semantic); | ||
} | ||
return collectErrors(); | ||
@@ -175,3 +171,3 @@ function doResponse() { | ||
if (Date.now() - lastCheckCancelAt >= 5) { | ||
yield shared.sleep(5); // wait for LSP event polling | ||
yield (0, common_1.sleep)(5); // wait for LSP event polling | ||
lastCheckCancelAt = Date.now(); | ||
@@ -259,6 +255,6 @@ } | ||
}, (plugin, document) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e; | ||
var _a, _b, _c, _d; | ||
if (token) { | ||
if (Date.now() - lastCheckCancelAt >= 5) { | ||
yield shared.sleep(5); // wait for LSP event polling | ||
yield (0, common_1.sleep)(5); // waiting LSP event polling | ||
lastCheckCancelAt = Date.now(); | ||
@@ -273,4 +269,4 @@ } | ||
const cache = pluginCache.get(document.uri); | ||
const tsProjectVersion = (api === 'onDeclaration' || api === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined; | ||
if (api === 'onDeclaration' || api === 'onSemantic') { | ||
const tsProjectVersion = api === 'provideSemanticDiagnostics' ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined; | ||
if (api === 'provideSemanticDiagnostics') { | ||
if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) { | ||
@@ -285,3 +281,3 @@ return cache.errors; | ||
} | ||
const errors = yield ((_e = (_d = plugin.validation) === null || _d === void 0 ? void 0 : _d[api]) === null || _e === void 0 ? void 0 : _e.call(_d, document)); | ||
const errors = yield ((_d = plugin[api]) === null || _d === void 0 ? void 0 : _d.call(plugin, document, token)); | ||
errors === null || errors === void 0 ? void 0 : errors.forEach(error => { | ||
@@ -288,0 +284,0 @@ error.data = { |
import * as vscode from 'vscode-languageserver-protocol'; | ||
import type { LanguageServicePluginContext } from '../types'; | ||
export declare function register(context: LanguageServicePluginContext): (query: string) => Promise<vscode.WorkspaceSymbol[]>; | ||
export declare function register(context: LanguageServicePluginContext): (query: string, token: vscode.CancellationToken) => Promise<vscode.WorkspaceSymbol[]>; |
@@ -14,10 +14,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const vscode = require("vscode-languageserver-protocol"); | ||
const shared = require("@volar/shared"); | ||
const common_1 = require("../utils/common"); | ||
function register(context) { | ||
return (query) => __awaiter(this, void 0, void 0, function* () { | ||
return (query, token) => __awaiter(this, void 0, void 0, function* () { | ||
const symbolsList = []; | ||
for (const plugin of Object.values(context.plugins)) { | ||
if (!plugin.findWorkspaceSymbols) | ||
if (token.isCancellationRequested) | ||
break; | ||
if (!plugin.provideWorkspaceSymbols) | ||
continue; | ||
const embeddedSymbols = yield plugin.findWorkspaceSymbols(query); | ||
const embeddedSymbols = yield plugin.provideWorkspaceSymbols(query, token); | ||
if (!embeddedSymbols) | ||
@@ -37,3 +39,3 @@ continue; | ||
} | ||
})).filter(shared.notEmpty); | ||
})).filter(common_1.notEmpty); | ||
symbolsList.push(symbols); | ||
@@ -40,0 +42,0 @@ } |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transform = void 0; | ||
const common_1 = require("../utils/common"); | ||
const textEdit_1 = require("./textEdit"); | ||
const shared = require("@volar/shared"); | ||
function transform(item, getOtherRange, document) { | ||
var _a; | ||
return Object.assign(Object.assign({}, item), { additionalTextEdits: (_a = item.additionalTextEdits) === null || _a === void 0 ? void 0 : _a.map(edit => (0, textEdit_1.transform)(edit, getOtherRange, document)).filter(shared.notEmpty), textEdit: item.textEdit | ||
return Object.assign(Object.assign({}, item), { additionalTextEdits: (_a = item.additionalTextEdits) === null || _a === void 0 ? void 0 : _a.map(edit => (0, textEdit_1.transform)(edit, getOtherRange, document)).filter(common_1.notEmpty), textEdit: item.textEdit | ||
? (0, textEdit_1.transform)(item.textEdit, getOtherRange, document) | ||
@@ -9,0 +9,0 @@ : undefined }); |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transform = void 0; | ||
const shared = require("@volar/shared"); | ||
const common_1 = require("../utils/common"); | ||
function transform(symbol, getOtherRange) { | ||
@@ -15,5 +15,5 @@ var _a; | ||
return Object.assign(Object.assign({}, symbol), { range, | ||
selectionRange, children: (_a = symbol.children) === null || _a === void 0 ? void 0 : _a.map(child => transform(child, getOtherRange)).filter(shared.notEmpty) }); | ||
selectionRange, children: (_a = symbol.children) === null || _a === void 0 ? void 0 : _a.map(child => transform(child, getOtherRange)).filter(common_1.notEmpty) }); | ||
} | ||
exports.transform = transform; | ||
//# sourceMappingURL=documentSymbol.js.map |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transform = void 0; | ||
const shared = require("@volar/shared"); | ||
const common_1 = require("../utils/common"); | ||
const locationLike_1 = require("./locationLike"); | ||
@@ -8,5 +8,5 @@ function transform(locations, getOtherRange) { | ||
.map(location => (0, locationLike_1.transform)(location, getOtherRange)) | ||
.filter(shared.notEmpty); | ||
.filter(common_1.notEmpty); | ||
} | ||
exports.transform = transform; | ||
//# sourceMappingURL=locationsLike.js.map |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transform = void 0; | ||
const shared = require("@volar/shared"); | ||
const common_1 = require("../utils/common"); | ||
const selectionRange_1 = require("./selectionRange"); | ||
@@ -8,5 +8,5 @@ function transform(locations, getOtherRange) { | ||
.map(location => (0, selectionRange_1.transform)(location, getOtherRange)) | ||
.filter(shared.notEmpty); | ||
.filter(common_1.notEmpty); | ||
} | ||
exports.transform = transform; | ||
//# sourceMappingURL=selectionRanges.js.map |
@@ -54,85 +54,61 @@ import { LanguageContext, LanguageModule, LanguageServiceHost } from '@volar/language-core'; | ||
*/ | ||
export type NotNullableResult<T> = T | Thenable<T>; | ||
export type NullableResult<T> = NotNullableResult<T | undefined | null>; | ||
export type Result<T> = T | Thenable<T>; | ||
export type NullableResult<T> = Result<T | undefined | null>; | ||
export type SemanticToken = [number, number, number, number, number]; | ||
export interface LanguageServicePlugin<T = {}> { | ||
(context: LanguageServicePluginContext): LanguageServicePluginInstance & T; | ||
export interface LanguageServicePlugin { | ||
(context?: LanguageServicePluginContext): LanguageServicePluginInstance; | ||
} | ||
export interface AutoInsertionContext { | ||
lastChange: { | ||
range: vscode.Range; | ||
rangeOffset: number; | ||
rangeLength: number; | ||
text: string; | ||
}; | ||
} | ||
export interface LanguageServicePluginInstance { | ||
rules?: { | ||
onAny?(context: RuleContext): NotNullableResult<RuleContext>; | ||
onFormat?(context: RuleContext): NotNullableResult<RuleContext>; | ||
onSyntax?(context: RuleContext): NotNullableResult<RuleContext>; | ||
onSemantic?(context: RuleContext): NotNullableResult<RuleContext>; | ||
}; | ||
validation?: { | ||
onSemantic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>; | ||
onSyntactic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>; | ||
onSuggestion?(document: TextDocument): NullableResult<vscode.Diagnostic[]>; | ||
onDeclaration?(document: TextDocument): NullableResult<vscode.Diagnostic[]>; | ||
}; | ||
doHover?(document: TextDocument, position: vscode.Position): NullableResult<vscode.Hover>; | ||
findImplementations?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>; | ||
findReferences?(document: TextDocument, position: vscode.Position): NullableResult<vscode.Location[]>; | ||
findFileReferences?(document: TextDocument): NullableResult<vscode.Location[]>; | ||
findDocumentHighlights?(document: TextDocument, position: vscode.Position): NullableResult<vscode.DocumentHighlight[]>; | ||
findDocumentLinks?(document: TextDocument): NullableResult<vscode.DocumentLink[]>; | ||
findDocumentSymbols?(document: TextDocument): NullableResult<vscode.DocumentSymbol[]>; | ||
findDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend): NullableResult<SemanticToken[]>; | ||
findWorkspaceSymbols?(query: string): NullableResult<vscode.WorkspaceSymbol[]>; | ||
findDocumentColors?(document: TextDocument): NullableResult<vscode.ColorInformation[]>; | ||
getColorPresentations?(document: TextDocument, color: vscode.Color, range: vscode.Range): NullableResult<vscode.ColorPresentation[]>; | ||
doFileRename?(oldUri: string, newUri: string): NullableResult<vscode.WorkspaceEdit>; | ||
getFoldingRanges?(document: TextDocument): NullableResult<vscode.FoldingRange[]>; | ||
getSelectionRanges?(document: TextDocument, positions: vscode.Position[]): NullableResult<vscode.SelectionRange[]>; | ||
getSignatureHelp?(document: TextDocument, position: vscode.Position, context?: vscode.SignatureHelpContext): NullableResult<vscode.SignatureHelp>; | ||
format?(document: TextDocument, range: vscode.Range, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>; | ||
formatOnType?(document: TextDocument, position: vscode.Position, key: string, options: vscode.FormattingOptions): NullableResult<vscode.TextEdit[]>; | ||
getIndentSensitiveLines?(document: TextDocument): NullableResult<number[]>; | ||
definition?: { | ||
on?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>; | ||
onType?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LocationLink[]>; | ||
}; | ||
complete?: { | ||
triggerCharacters?: string[]; | ||
isAdditional?: boolean; | ||
on?(document: TextDocument, position: vscode.Position, context?: vscode.CompletionContext): NullableResult<vscode.CompletionList>; | ||
resolve?(item: vscode.CompletionItem): NotNullableResult<vscode.CompletionItem>; | ||
}; | ||
rename?: { | ||
prepare?(document: TextDocument, position: vscode.Position): NullableResult<vscode.Range | vscode.ResponseError<void>>; | ||
on?(document: TextDocument, position: vscode.Position, newName: string): NullableResult<vscode.WorkspaceEdit>; | ||
}; | ||
codeAction?: { | ||
on?(document: TextDocument, range: vscode.Range, context: vscode.CodeActionContext): NullableResult<vscode.CodeAction[]>; | ||
resolve?(codeAction: vscode.CodeAction): NotNullableResult<vscode.CodeAction>; | ||
}; | ||
codeLens?: { | ||
on?(document: TextDocument): NullableResult<vscode.CodeLens[]>; | ||
resolve?(codeLens: vscode.CodeLens): NotNullableResult<vscode.CodeLens>; | ||
}; | ||
referencesCodeLens?: { | ||
on?(document: TextDocument): NullableResult<vscode.Location[]>; | ||
resolve?(document: TextDocument, location: vscode.Location, references: vscode.Location[]): NotNullableResult<vscode.Location[]>; | ||
}; | ||
callHierarchy?: { | ||
prepare(document: TextDocument, position: vscode.Position): NullableResult<vscode.CallHierarchyItem[]>; | ||
onIncomingCalls(item: vscode.CallHierarchyItem): NotNullableResult<vscode.CallHierarchyIncomingCall[]>; | ||
onOutgoingCalls(item: vscode.CallHierarchyItem): NotNullableResult<vscode.CallHierarchyOutgoingCall[]>; | ||
}; | ||
inlayHints?: { | ||
on?(document: TextDocument, range: vscode.Range): NullableResult<vscode.InlayHint[]>; | ||
}; | ||
findLinkedEditingRanges?(document: TextDocument, position: vscode.Position): NullableResult<vscode.LinkedEditingRanges>; | ||
doAutoInsert?(document: TextDocument, position: vscode.Position, context: { | ||
lastChange: { | ||
range: vscode.Range; | ||
rangeOffset: number; | ||
rangeLength: number; | ||
text: string; | ||
}; | ||
}): NullableResult<string | vscode.TextEdit>; | ||
/** | ||
* TODO: only support to doCompleteResolve for now | ||
*/ | ||
isAdditionalCompletion?: boolean; | ||
triggerCharacters?: string[]; | ||
signatureHelpTriggerCharacters?: string[]; | ||
signatureHelpRetriggerCharacters?: string[]; | ||
autoFormatTriggerCharacters?: string[]; | ||
provideHover?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.Hover>; | ||
provideDocumentSymbols?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.DocumentSymbol[]>; | ||
provideDocumentHighlights?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.DocumentHighlight[]>; | ||
provideLinkedEditingRanges?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.LinkedEditingRanges>; | ||
provideDefinition?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.LocationLink[]>; | ||
provideTypeDefinition?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.LocationLink[]>; | ||
provideImplementation?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.LocationLink[]>; | ||
provideCodeLenses?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.CodeLens[]>; | ||
provideCodeActions?(document: TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken): NullableResult<vscode.CodeAction[]>; | ||
provideDocumentFormattingEdits?(document: TextDocument, range: vscode.Range, options: vscode.FormattingOptions, token: vscode.CancellationToken): NullableResult<vscode.TextEdit[]>; | ||
provideOnTypeFormattingEdits?(document: TextDocument, position: vscode.Position, key: string, options: vscode.FormattingOptions, token: vscode.CancellationToken): NullableResult<vscode.TextEdit[]>; | ||
provideLinks?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.DocumentLink[]>; | ||
provideCompletionItems?(document: TextDocument, position: vscode.Position, context: vscode.CompletionContext, token: vscode.CancellationToken): NullableResult<vscode.CompletionList>; | ||
provideDocumentColors?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.ColorInformation[]>; | ||
provideColorPresentations?(document: TextDocument, color: vscode.Color, range: vscode.Range, token: vscode.CancellationToken): NullableResult<vscode.ColorPresentation[]>; | ||
provideFoldingRanges?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.FoldingRange[]>; | ||
provideSignatureHelp?(document: TextDocument, position: vscode.Position, context: vscode.SignatureHelpContext, token: vscode.CancellationToken): NullableResult<vscode.SignatureHelp>; | ||
provideRenameRange?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.Range | vscode.ResponseError<void>>; | ||
provideRenameEdits?(document: TextDocument, position: vscode.Position, newName: string, token: vscode.CancellationToken): NullableResult<vscode.WorkspaceEdit>; | ||
provideReferences?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.Location[]>; | ||
provideSelectionRanges?(document: TextDocument, positions: vscode.Position[], token: vscode.CancellationToken): NullableResult<vscode.SelectionRange[]>; | ||
provideInlayHints?(document: TextDocument, range: vscode.Range, token: vscode.CancellationToken): NullableResult<vscode.InlayHint[]>; | ||
provideCallHierarchyItems(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.CallHierarchyItem[]>; | ||
provideCallHierarchyIncomingCalls(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Result<vscode.CallHierarchyIncomingCall[]>; | ||
provideCallHierarchyOutgoingCalls(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Result<vscode.CallHierarchyOutgoingCall[]>; | ||
provideDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend, token: vscode.CancellationToken): NullableResult<SemanticToken[]>; | ||
provideWorkspaceSymbols?(query: string, token: vscode.CancellationToken): NullableResult<vscode.WorkspaceSymbol[]>; | ||
provideSyntacticDiagnostics?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.Diagnostic[]>; | ||
provideSemanticDiagnostics?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.Diagnostic[]>; | ||
provideFileReferences?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.Location[]>; | ||
provideReferencesCodeLenses?(document: TextDocument, token: vscode.CancellationToken): NullableResult<vscode.Location[]>; | ||
provideAutoInsertionEdit?(document: TextDocument, position: vscode.Position, context: AutoInsertionContext, token: vscode.CancellationToken): NullableResult<string | vscode.TextEdit>; | ||
provideFileRenameEdits?(oldUri: string, newUri: string, token: vscode.CancellationToken): NullableResult<vscode.WorkspaceEdit>; | ||
provideFormattingIndentSensitiveLines?(document: TextDocument, token: vscode.CancellationToken): NullableResult<number[]>; | ||
resolveCodeLens?(codeLens: vscode.CodeLens, token: vscode.CancellationToken): Result<vscode.CodeLens>; | ||
resolveCodeAction?(codeAction: vscode.CodeAction, token: vscode.CancellationToken): Result<vscode.CodeAction>; | ||
resolveCompletionItem?(item: vscode.CompletionItem, token: vscode.CancellationToken): Result<vscode.CompletionItem>; | ||
resolveReferencesCodeLens?(document: TextDocument, location: vscode.Location, references: vscode.Location[], token: vscode.CancellationToken): Result<vscode.Location[]>; | ||
resolveRuleContext?(context: RuleContext, ruleType: 'format' | 'syntax' | 'semantic'): Result<RuleContext>; | ||
resolveEmbeddedRange?(range: vscode.Range): vscode.Range | undefined; | ||
@@ -139,0 +115,0 @@ } |
@@ -17,3 +17,2 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
__exportStar(require("vscode-languageserver-protocol"), exports); | ||
; | ||
//# sourceMappingURL=types.js.map |
@@ -8,1 +8,4 @@ import type * as vscode from 'vscode-languageserver-protocol'; | ||
export declare function stringToSnapshot(str: string): ts.IScriptSnapshot; | ||
export declare function syntaxToLanguageId(syntax: string): string; | ||
export declare function sleep(ms: number): Promise<unknown>; | ||
export declare function notEmpty<T>(value: T | null | undefined): value is T; |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringToSnapshot = exports.isInsideRange = exports.getOverlapRange = void 0; | ||
exports.notEmpty = exports.sleep = exports.syntaxToLanguageId = exports.stringToSnapshot = exports.isInsideRange = exports.getOverlapRange = void 0; | ||
function getOverlapRange(range1Start, range1End, range2Start, range2End) { | ||
@@ -34,2 +34,26 @@ const start = Math.max(range1Start, range2Start); | ||
exports.stringToSnapshot = stringToSnapshot; | ||
function syntaxToLanguageId(syntax) { | ||
switch (syntax) { | ||
case 'js': return 'javascript'; | ||
case 'cjs': return 'javascript'; | ||
case 'mjs': return 'javascript'; | ||
case 'ts': return 'typescript'; | ||
case 'cts': return 'typescript'; | ||
case 'mts': return 'typescript'; | ||
case 'jsx': return 'javascriptreact'; | ||
case 'tsx': return 'typescriptreact'; | ||
case 'pug': return 'jade'; | ||
case 'md': return 'markdown'; | ||
} | ||
return syntax; | ||
} | ||
exports.syntaxToLanguageId = syntaxToLanguageId; | ||
function sleep(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
exports.sleep = sleep; | ||
function notEmpty(value) { | ||
return value !== null && value !== undefined; | ||
} | ||
exports.notEmpty = notEmpty; | ||
//# sourceMappingURL=common.js.map |
@@ -79,3 +79,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -87,3 +87,3 @@ const document = context.getTextDocument(uri); | ||
yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () { | ||
var _l, _m, _o, _p, _q, _r, _s, _t, _u; | ||
var _j, _k, _l, _m, _o, _p, _q; | ||
if (!isValidSourceMap(file)) { | ||
@@ -94,3 +94,3 @@ return true; | ||
// project context | ||
modules: { typescript: (_l = context.typescript) === null || _l === void 0 ? void 0 : _l.module }, | ||
modules: { typescript: (_j = context.typescript) === null || _j === void 0 ? void 0 : _j.module }, | ||
uriToFileName: context.uriToFileName, | ||
@@ -100,5 +100,5 @@ fileNameToUri: context.fileNameToUri, | ||
locale: context.locale, | ||
getConfiguration: (_m = context.configurationHost) === null || _m === void 0 ? void 0 : _m.getConfiguration, | ||
onDidChangeConfiguration: (_o = context.configurationHost) === null || _o === void 0 ? void 0 : _o.onDidChangeConfiguration, | ||
settings: (_q = (_p = context.config.lint) === null || _p === void 0 ? void 0 : _p.settings) !== null && _q !== void 0 ? _q : {}, | ||
getConfiguration: (_k = context.configurationHost) === null || _k === void 0 ? void 0 : _k.getConfiguration, | ||
onDidChangeConfiguration: (_l = context.configurationHost) === null || _l === void 0 ? void 0 : _l.onDidChangeConfiguration, | ||
settings: (_o = (_m = context.config.lint) === null || _m === void 0 ? void 0 : _m.settings) !== null && _o !== void 0 ? _o : {}, | ||
// document context | ||
@@ -110,10 +110,6 @@ ruleId: '', | ||
for (const plugin of Object.values(context.plugins)) { | ||
const fn = (_r = plugin.rules) === null || _r === void 0 ? void 0 : _r[api]; | ||
try { | ||
if (fn) { | ||
ruleCtx = yield fn(ruleCtx); | ||
if (plugin.resolveRuleContext) { | ||
ruleCtx = yield plugin.resolveRuleContext(ruleCtx, api === 'onFormat' ? 'format' : api === 'onSyntax' ? 'syntax' : 'semantic'); | ||
} | ||
else if ((_s = plugin.rules) === null || _s === void 0 ? void 0 : _s.onAny) { | ||
ruleCtx = yield plugin.rules.onAny(ruleCtx); | ||
} | ||
} | ||
@@ -124,4 +120,4 @@ catch (err) { | ||
} | ||
for (const ruleName in (_t = context.config.lint) === null || _t === void 0 ? void 0 : _t.rules) { | ||
const rule = (_u = context.config.lint) === null || _u === void 0 ? void 0 : _u.rules[ruleName]; | ||
for (const ruleName in (_p = context.config.lint) === null || _p === void 0 ? void 0 : _p.rules) { | ||
const rule = (_q = context.config.lint) === null || _q === void 0 ? void 0 : _q.rules[ruleName]; | ||
if (!rule) { | ||
@@ -165,10 +161,6 @@ continue; | ||
for (const plugin of Object.values(context.plugins)) { | ||
const fn = (_g = plugin.rules) === null || _g === void 0 ? void 0 : _g[api]; | ||
try { | ||
if (fn) { | ||
ruleCtx = yield fn(ruleCtx); | ||
if (plugin.resolveRuleContext) { | ||
ruleCtx = yield plugin.resolveRuleContext(ruleCtx, api === 'onFormat' ? 'format' : api === 'onSyntax' ? 'syntax' : 'semantic'); | ||
} | ||
else if ((_h = plugin.rules) === null || _h === void 0 ? void 0 : _h.onAny) { | ||
ruleCtx = yield plugin.rules.onAny(ruleCtx); | ||
} | ||
} | ||
@@ -179,4 +171,4 @@ catch (err) { | ||
} | ||
for (const ruleName in (_j = context.config.lint) === null || _j === void 0 ? void 0 : _j.rules) { | ||
const rule = (_k = context.config.lint) === null || _k === void 0 ? void 0 : _k.rules[ruleName]; | ||
for (const ruleName in (_g = context.config.lint) === null || _g === void 0 ? void 0 : _g.rules) { | ||
const rule = (_h = context.config.lint) === null || _h === void 0 ? void 0 : _h.rules[ruleName]; | ||
if (!rule) { | ||
@@ -183,0 +175,0 @@ continue; |
{ | ||
"name": "@volar/language-service", | ||
"version": "1.3.0-alpha.3", | ||
"version": "1.4.0-alpha.0", | ||
"main": "out/index.js", | ||
@@ -16,6 +16,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"@volar/language-core": "1.3.0-alpha.3", | ||
"@volar/shared": "1.3.0-alpha.3", | ||
"@volar/source-map": "1.3.0-alpha.3", | ||
"@volar/typescript-faster": "1.3.0-alpha.3", | ||
"@volar/language-core": "1.4.0-alpha.0", | ||
"@volar/source-map": "1.4.0-alpha.0", | ||
"typescript-auto-import-cache": "^0.0.1", | ||
"vscode-html-languageservice": "^5.0.4", | ||
@@ -27,3 +26,3 @@ "vscode-json-languageservice": "^5.2.0", | ||
}, | ||
"gitHead": "03c8fff84531d8740863da5f9350e0d9382b5784" | ||
"gitHead": "2607410cae341cf802b446062d446ad497be2057" | ||
} |
226101
8
102
4132
+ Added@volar/language-core@1.4.0-alpha.0(transitive)
+ Added@volar/source-map@1.4.0-alpha.0(transitive)
+ Addedtypescript-auto-import-cache@0.0.1(transitive)
- Removed@volar/shared@1.3.0-alpha.3
- Removed@volar/language-core@1.3.0-alpha.3(transitive)
- Removed@volar/shared@1.3.0-alpha.3(transitive)
- Removed@volar/source-map@1.3.0-alpha.3(transitive)
- Removed@volar/typescript-faster@1.3.0-alpha.3(transitive)
- Removedtypesafe-path@0.2.2(transitive)