@volar/language-service
Advanced tools
Comparing version 1.2.0-alpha.4 to 1.2.0-alpha.5
import { LanguageServiceHost } from '@volar/language-core'; | ||
import * as executeCommand from './languageFeatures/executeCommand'; | ||
import { LanguageServiceConfig, LanguageServiceRuntimeContext } from './types'; | ||
import { Config, LanguageServiceRuntimeContext } from './types'; | ||
import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
import type * as _ from 'vscode-languageserver-protocol'; | ||
export type LanguageService = ReturnType<typeof createLanguageService>; | ||
export declare function createLanguageService(host: LanguageServiceHost, config: LanguageServiceConfig, env: LanguageServiceRuntimeContext['env'], documentRegistry?: ts.DocumentRegistry): { | ||
export declare function createLanguageService(host: LanguageServiceHost, config: Config, env: LanguageServiceRuntimeContext['env'], documentRegistry?: ts.DocumentRegistry): { | ||
format: (uri: string, options: _.FormattingOptions, range?: _.Range | undefined, onTypeParams?: { | ||
@@ -9,0 +9,0 @@ ch: string; |
@@ -67,3 +67,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
plugins = {}; // avoid infinite loop | ||
for (let pluginId in (_a = config.plugins) !== null && _a !== void 0 ? _a : {}) { | ||
for (const pluginId in (_a = config.plugins) !== null && _a !== void 0 ? _a : {}) { | ||
const plugin = (_b = config.plugins) === null || _b === void 0 ? void 0 : _b[pluginId]; | ||
@@ -70,0 +70,0 @@ if (plugin instanceof Function) { |
@@ -192,3 +192,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
yield ((_d = rule[api]) === null || _d === void 0 ? void 0 : _d.call(rule, ruleCtx)); | ||
if (typeof rule === 'function') { | ||
if (api === 'onSyntax') { | ||
yield rule(ruleCtx); | ||
} | ||
} | ||
else { | ||
yield ((_d = rule[api]) === null || _d === void 0 ? void 0 : _d.call(rule, ruleCtx)); | ||
} | ||
(_e = context.ruleFixes) !== null && _e !== void 0 ? _e : (context.ruleFixes = {}); | ||
@@ -195,0 +202,0 @@ (_f = (_h = context.ruleFixes)[_j = ruleCtx.document.uri]) !== null && _f !== void 0 ? _f : (_h[_j] = {}); |
@@ -19,2 +19,3 @@ import { LanguageContext, LanguageModule, LanguageServiceHost } from '@volar/language-core'; | ||
rootUri: URI; | ||
locale?: string; | ||
configurationHost?: ConfigurationHost; | ||
@@ -82,4 +83,6 @@ documentContext: DocumentContext; | ||
export interface LanguageServicePluginInstance { | ||
rules?: { | ||
prepare?(context: RuleContext): NotNullableResult<RuleContext>; | ||
}; | ||
validation?: { | ||
setupRuleContext?(context: RuleContext): NotNullableResult<RuleContext>; | ||
onSemantic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>; | ||
@@ -152,3 +155,4 @@ onSyntactic?(document: TextDocument): NullableResult<vscode.Diagnostic[]>; | ||
} | ||
export interface Rule { | ||
export type Rule = _Rule | NonNullable<_Rule['onSyntax']>; | ||
export interface _Rule { | ||
onFormat?(ctx: RuleContext): void; | ||
@@ -159,6 +163,10 @@ onSyntax?(ctx: RuleContext): void; | ||
export interface RuleContext { | ||
locale?: string; | ||
uriToFileName(uri: string): string; | ||
fileNameToUri(fileName: string): string; | ||
rootUri: URI; | ||
getConfiguration?: ConfigurationHost['getConfiguration']; | ||
onDidChangeConfiguration?: ConfigurationHost['onDidChangeConfiguration']; | ||
ruleId: string; | ||
document: TextDocument; | ||
uriToFileName(uri: string): string; | ||
fileNameToUri(fileName: string): string; | ||
report(error: vscode.Diagnostic, ...fixes: RuleFix[]): void; | ||
@@ -172,9 +180,12 @@ } | ||
} | ||
export interface LanguageServiceConfig { | ||
languages?: ConfigValue<LanguageModule>; | ||
plugins?: ConfigValue<LanguageServicePlugin | LanguageServicePluginInstance>; | ||
rules?: ConfigValue<Rule>; | ||
export interface Config { | ||
languages?: { | ||
[id: string]: LanguageModule | undefined; | ||
}; | ||
plugins?: { | ||
[id: string]: LanguageServicePlugin | LanguageServicePluginInstance | undefined; | ||
}; | ||
rules?: { | ||
[id: string]: Rule | undefined; | ||
}; | ||
} | ||
type ConfigValue<T> = { | ||
[id: string]: T | undefined; | ||
}; |
@@ -18,2 +18,3 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
; | ||
; | ||
//# sourceMappingURL=types.js.map |
@@ -80,3 +80,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function ruleWorker(context, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d, _e; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -88,3 +88,3 @@ const document = context.getTextDocument(uri); | ||
yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () { | ||
var _d; | ||
var _f, _g, _h; | ||
if (!isValidSourceMap(file)) { | ||
@@ -94,11 +94,17 @@ return true; | ||
let ruleCtx = { | ||
// project context | ||
uriToFileName: shared.uriToFileName, | ||
fileNameToUri: shared.fileNameToUri, | ||
rootUri: context.env.rootUri, | ||
locale: context.env.locale, | ||
getConfiguration: (_f = context.env.configurationHost) === null || _f === void 0 ? void 0 : _f.getConfiguration, | ||
onDidChangeConfiguration: (_g = context.env.configurationHost) === null || _g === void 0 ? void 0 : _g.onDidChangeConfiguration, | ||
// document context | ||
ruleId: '', | ||
document: map.virtualFileDocument, | ||
uriToFileName: shared.uriToFileName, | ||
fileNameToUri: shared.fileNameToUri, | ||
report: () => { }, | ||
}; | ||
for (const plugin of Object.values(context.plugins)) { | ||
if ((_d = plugin.validation) === null || _d === void 0 ? void 0 : _d.setupRuleContext) { | ||
ruleCtx = yield plugin.validation.setupRuleContext(ruleCtx); | ||
if ((_h = plugin.rules) === null || _h === void 0 ? void 0 : _h.prepare) { | ||
ruleCtx = yield plugin.rules.prepare(ruleCtx); | ||
} | ||
@@ -131,11 +137,17 @@ } | ||
let ruleCtx = { | ||
// project context | ||
uriToFileName: shared.uriToFileName, | ||
fileNameToUri: shared.fileNameToUri, | ||
rootUri: context.env.rootUri, | ||
locale: context.env.locale, | ||
getConfiguration: (_b = context.env.configurationHost) === null || _b === void 0 ? void 0 : _b.getConfiguration, | ||
onDidChangeConfiguration: (_c = context.env.configurationHost) === null || _c === void 0 ? void 0 : _c.onDidChangeConfiguration, | ||
// document context | ||
ruleId: '', | ||
document, | ||
uriToFileName: shared.uriToFileName, | ||
fileNameToUri: shared.fileNameToUri, | ||
report: () => { }, | ||
}; | ||
for (const plugin of Object.values(context.plugins)) { | ||
if ((_b = plugin.validation) === null || _b === void 0 ? void 0 : _b.setupRuleContext) { | ||
ruleCtx = yield ((_c = plugin.validation) === null || _c === void 0 ? void 0 : _c.setupRuleContext(ruleCtx)); | ||
if ((_d = plugin.rules) === null || _d === void 0 ? void 0 : _d.prepare) { | ||
ruleCtx = yield ((_e = plugin.rules) === null || _e === void 0 ? void 0 : _e.prepare(ruleCtx)); | ||
} | ||
@@ -142,0 +154,0 @@ } |
{ | ||
"name": "@volar/language-service", | ||
"version": "1.2.0-alpha.4", | ||
"version": "1.2.0-alpha.5", | ||
"main": "out/index.js", | ||
@@ -16,6 +16,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"@volar/language-core": "1.2.0-alpha.4", | ||
"@volar/shared": "1.2.0-alpha.4", | ||
"@volar/source-map": "1.2.0-alpha.4", | ||
"@volar/typescript-faster": "1.2.0-alpha.4", | ||
"@volar/language-core": "1.2.0-alpha.5", | ||
"@volar/shared": "1.2.0-alpha.5", | ||
"@volar/source-map": "1.2.0-alpha.5", | ||
"@volar/typescript-faster": "1.2.0-alpha.5", | ||
"vscode-html-languageservice": "^5.0.3", | ||
@@ -27,3 +27,3 @@ "vscode-json-languageservice": "^5.1.3", | ||
}, | ||
"gitHead": "cce402aa84061635c951e27c4423408d0b56e46d" | ||
"gitHead": "a31d022987c454762d1ba3c9ef8e7d74a5bca06a" | ||
} |
212539
3873
+ Added@volar/language-core@1.2.0-alpha.5(transitive)
+ Added@volar/shared@1.2.0-alpha.5(transitive)
+ Added@volar/source-map@1.2.0-alpha.5(transitive)
+ Added@volar/typescript-faster@1.2.0-alpha.5(transitive)
- Removed@volar/language-core@1.2.0-alpha.4(transitive)
- Removed@volar/shared@1.2.0-alpha.4(transitive)
- Removed@volar/source-map@1.2.0-alpha.4(transitive)
- Removed@volar/typescript-faster@1.2.0-alpha.4(transitive)
Updated@volar/shared@1.2.0-alpha.5