volar-service-typescript
Advanced tools
Comparing version 0.0.0 to 0.0.1
@@ -1,3 +0,11 @@ | ||
import type { Service } from '@volar/language-service'; | ||
import { InjectionKey, Service } from '@volar/language-service'; | ||
import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
import type { TextDocument } from 'vscode-languageserver-textdocument'; | ||
export declare const rulesInjectionKey: InjectionKey<{ | ||
sourceFile: ts.SourceFile; | ||
languageService: ts.LanguageService; | ||
languageServiceHost: ts.LanguageServiceHost; | ||
getTextDocument(uri: string): TextDocument | undefined; | ||
}>; | ||
declare const _default: () => Service; | ||
export default _default; |
@@ -26,2 +26,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.rulesInjectionKey = void 0; | ||
const language_service_1 = require("@volar/language-service"); | ||
const semver = __importStar(require("semver")); | ||
@@ -57,2 +59,3 @@ const vscode = __importStar(require("vscode-languageserver-protocol")); | ||
const tsconfig = __importStar(require("./services/tsconfig")); | ||
exports.rulesInjectionKey = Symbol(); | ||
exports.default = () => (contextOrNull, modules) => { | ||
@@ -77,3 +80,3 @@ const jsDocTriggerCharacter = '*'; | ||
if (!modules?.typescript) { | ||
console.warn('[volar-service-typescript] context.typescript not found, @volar/typescript plugin disabled. Make sure you have provide tsdk in language client.'); | ||
console.warn('[volar-service-typescript] context.typescript not found, volar-service-typescript is disabled. Make sure you have provide tsdk in language client.'); | ||
return {}; | ||
@@ -146,2 +149,33 @@ } | ||
return { | ||
rules: { | ||
provide: { | ||
[exports.rulesInjectionKey](document, type) { | ||
if ((0, shared_1.isTsDocument)(document)) { | ||
if (type === language_service_1.RuleType.Format || type === language_service_1.RuleType.Syntax) { | ||
prepareSyntacticService(document); | ||
const sourceFile = syntacticCtx.typescript.languageService.getProgram()?.getSourceFile(syntacticHostCtx.fileName); | ||
if (sourceFile) { | ||
return { | ||
sourceFile, | ||
languageService: syntacticCtx.typescript.languageService, | ||
languageServiceHost: syntacticCtx.typescript.languageServiceHost, | ||
getTextDocument: syntacticCtx.getTextDocument, | ||
}; | ||
} | ||
} | ||
else { | ||
const sourceFile = semanticCtx.typescript.languageService.getProgram()?.getSourceFile(context.env.uriToFileName(document.uri)); | ||
if (sourceFile) { | ||
return { | ||
sourceFile, | ||
languageService: semanticCtx.typescript.languageService, | ||
languageServiceHost: semanticCtx.typescript.languageServiceHost, | ||
getTextDocument: semanticCtx.getTextDocument, | ||
}; | ||
} | ||
} | ||
} | ||
}, | ||
}, | ||
}, | ||
...triggerCharacters, | ||
@@ -153,25 +187,2 @@ triggerCharacters: [ | ||
], | ||
resolveRuleContext(ruleCtx, type) { | ||
if ((0, shared_1.isTsDocument)(ruleCtx.document)) { | ||
let sourceFile; | ||
if (type === 'format' || type === 'syntax') { | ||
prepareSyntacticService(ruleCtx.document); | ||
sourceFile = syntacticCtx.typescript.languageService.getProgram()?.getSourceFile(syntacticHostCtx.fileName); | ||
} | ||
else { | ||
sourceFile = semanticCtx.typescript.languageService.getProgram()?.getSourceFile(context.env.uriToFileName(ruleCtx.document.uri)); | ||
} | ||
if (sourceFile) { | ||
ruleCtx.typescript = { | ||
sourceFile, | ||
getTextDocument: syntacticCtx.getTextDocument, | ||
...syntacticCtx.typescript, | ||
}; | ||
} | ||
else { | ||
console.warn('[volar-service-typescript] sourceFile not found', ruleCtx.document.uri); | ||
} | ||
} | ||
return ruleCtx; | ||
}, | ||
provideAutoInsertionEdit(document, position, ctx) { | ||
@@ -178,0 +189,0 @@ if ((document.languageId === 'javascriptreact' || document.languageId === 'typescriptreact') |
import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
export declare namespace SymbolKind { | ||
function fromProtocolScriptElementKind(kind: ts.ScriptElementKind): 2 | 5 | 10 | 22 | 11 | 6 | 7 | 13 | 12 | 9 | 26 | 15; | ||
function fromProtocolScriptElementKind(kind: ts.ScriptElementKind): 2 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 15 | 22 | 26; | ||
} |
{ | ||
"name": "volar-service-typescript", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"main": "out/index.js", | ||
"license": "MIT", | ||
"files": [ | ||
"rules.d.ts", | ||
"out/**/*.js", | ||
@@ -31,3 +30,3 @@ "out/**/*.d.ts" | ||
}, | ||
"gitHead": "1011561ac4bbf79c53c3b80c27692569bf861519" | ||
"gitHead": "5bf5152f076f25cb1ddbc7aa6978a8d1c7009fd6" | ||
} |
189900
3951
81