mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
refactor(lsp): clean up tsc requests (#20743)
This commit is contained in:
parent
de25c81fd0
commit
6fd2d08418
4 changed files with 519 additions and 1354 deletions
1338
cli/lsp/tsc.rs
1338
cli/lsp/tsc.rs
File diff suppressed because it is too large
Load diff
|
@ -968,26 +968,23 @@ delete Object.prototype.__proto__;
|
|||
ops.op_respond({ id, data });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {LanguageServerRequest} request
|
||||
*/
|
||||
function serverRequest({ id, ...request }) {
|
||||
function serverRequest(id, method, args) {
|
||||
if (logDebug) {
|
||||
debug(`serverRequest()`, { id, ...request });
|
||||
debug(`serverRequest()`, id, method, args);
|
||||
}
|
||||
|
||||
// reset all memoized source files names
|
||||
scriptFileNamesCache = undefined;
|
||||
// evict all memoized source file versions
|
||||
scriptVersionCache.clear();
|
||||
switch (request.method) {
|
||||
case "restart": {
|
||||
switch (method) {
|
||||
case "$restart": {
|
||||
serverRestart();
|
||||
return respond(id, true);
|
||||
}
|
||||
case "configure": {
|
||||
case "$configure": {
|
||||
const { options, errors } = ts
|
||||
.convertCompilerOptionsFromJson(request.compilerOptions, "");
|
||||
.convertCompilerOptionsFromJson(args[0], "");
|
||||
Object.assign(options, {
|
||||
allowNonTsExtensions: true,
|
||||
allowImportingTsExtensions: true,
|
||||
|
@ -998,141 +995,20 @@ delete Object.prototype.__proto__;
|
|||
compilationSettings = options;
|
||||
return respond(id, true);
|
||||
}
|
||||
case "findRenameLocations": {
|
||||
case "$getSupportedCodeFixes": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.findRenameLocations(
|
||||
request.specifier,
|
||||
request.position,
|
||||
request.findInStrings,
|
||||
request.findInComments,
|
||||
request.providePrefixAndSuffixTextForRename,
|
||||
),
|
||||
ts.getSupportedCodeFixes(),
|
||||
);
|
||||
}
|
||||
case "getAssets": {
|
||||
case "$getAssets": {
|
||||
return respond(id, getAssets());
|
||||
}
|
||||
case "getApplicableRefactors": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getApplicableRefactors(
|
||||
request.specifier,
|
||||
request.range,
|
||||
{
|
||||
...(request.preferences ?? {}),
|
||||
allowTextChangesInNewFiles: true,
|
||||
provideRefactorNotApplicableReason: true,
|
||||
},
|
||||
undefined,
|
||||
request.kind,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getEditsForRefactor": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getEditsForRefactor(
|
||||
request.specifier,
|
||||
{
|
||||
...request.formatCodeSettings,
|
||||
indentStyle: ts.IndentStyle.Smart,
|
||||
insertSpaceBeforeAndAfterBinaryOperators: true,
|
||||
insertSpaceAfterCommaDelimiter: true,
|
||||
},
|
||||
request.range,
|
||||
request.refactorName,
|
||||
request.actionName,
|
||||
request.preferences,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getEditsForFileRename": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getEditsForFileRename(
|
||||
request.oldSpecifier,
|
||||
request.newSpecifier,
|
||||
request.formatCodeSettings,
|
||||
request.preferences,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getCodeFixes": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getCodeFixesAtPosition(
|
||||
request.specifier,
|
||||
request.startPosition,
|
||||
request.endPosition,
|
||||
request.errorCodes.map((v) => Number(v)),
|
||||
{
|
||||
...request.formatCodeSettings,
|
||||
indentStyle: ts.IndentStyle.Block,
|
||||
},
|
||||
request.preferences,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getCombinedCodeFix": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getCombinedCodeFix(
|
||||
{
|
||||
type: "file",
|
||||
fileName: request.specifier,
|
||||
},
|
||||
request.fixId,
|
||||
{
|
||||
...request.formatCodeSettings,
|
||||
indentStyle: ts.IndentStyle.Block,
|
||||
},
|
||||
request.preferences,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getCompletionDetails": {
|
||||
if (logDebug) {
|
||||
debug("request", request);
|
||||
}
|
||||
return respond(
|
||||
id,
|
||||
languageService.getCompletionEntryDetails(
|
||||
request.args.specifier,
|
||||
request.args.position,
|
||||
request.args.name,
|
||||
request.args.formatCodeSettings ?? {},
|
||||
request.args.source,
|
||||
request.args.preferences,
|
||||
request.args.data,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getCompletions": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getCompletionsAtPosition(
|
||||
request.specifier,
|
||||
request.position,
|
||||
request.preferences,
|
||||
request.formatCodeSettings,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getDefinition": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getDefinitionAndBoundSpan(
|
||||
request.specifier,
|
||||
request.position,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getDiagnostics": {
|
||||
case "$getDiagnostics": {
|
||||
try {
|
||||
/** @type {Record<string, any[]>} */
|
||||
const diagnosticMap = {};
|
||||
for (const specifier of request.specifiers) {
|
||||
for (const specifier of args[0]) {
|
||||
diagnosticMap[specifier] = fromTypeScriptDiagnostics([
|
||||
...languageService.getSemanticDiagnostics(specifier),
|
||||
...languageService.getSuggestionDiagnostics(specifier),
|
||||
|
@ -1154,151 +1030,18 @@ delete Object.prototype.__proto__;
|
|||
return respond(id, {});
|
||||
}
|
||||
}
|
||||
case "getDocumentHighlights": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getDocumentHighlights(
|
||||
request.specifier,
|
||||
request.position,
|
||||
request.filesToSearch,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getEncodedSemanticClassifications": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getEncodedSemanticClassifications(
|
||||
request.specifier,
|
||||
request.span,
|
||||
ts.SemanticClassificationFormat.TwentyTwenty,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getImplementation": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getImplementationAtPosition(
|
||||
request.specifier,
|
||||
request.position,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getNavigateToItems": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getNavigateToItems(
|
||||
request.search,
|
||||
request.maxResultCount,
|
||||
request.fileName,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getNavigationTree": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getNavigationTree(request.specifier),
|
||||
);
|
||||
}
|
||||
case "getOutliningSpans": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getOutliningSpans(
|
||||
request.specifier,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getQuickInfo": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getQuickInfoAtPosition(
|
||||
request.specifier,
|
||||
request.position,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "findReferences": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.findReferences(
|
||||
request.specifier,
|
||||
request.position,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getSignatureHelpItems": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getSignatureHelpItems(
|
||||
request.specifier,
|
||||
request.position,
|
||||
request.options,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getSmartSelectionRange": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getSmartSelectionRange(
|
||||
request.specifier,
|
||||
request.position,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "getSupportedCodeFixes": {
|
||||
return respond(
|
||||
id,
|
||||
ts.getSupportedCodeFixes(),
|
||||
);
|
||||
}
|
||||
case "getTypeDefinition": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.getTypeDefinitionAtPosition(
|
||||
request.specifier,
|
||||
request.position,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "prepareCallHierarchy": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.prepareCallHierarchy(
|
||||
request.specifier,
|
||||
request.position,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "provideCallHierarchyIncomingCalls": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.provideCallHierarchyIncomingCalls(
|
||||
request.specifier,
|
||||
request.position,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "provideCallHierarchyOutgoingCalls": {
|
||||
return respond(
|
||||
id,
|
||||
languageService.provideCallHierarchyOutgoingCalls(
|
||||
request.specifier,
|
||||
request.position,
|
||||
),
|
||||
);
|
||||
}
|
||||
case "provideInlayHints":
|
||||
return respond(
|
||||
id,
|
||||
languageService.provideInlayHints(
|
||||
request.specifier,
|
||||
request.span,
|
||||
request.preferences,
|
||||
),
|
||||
);
|
||||
default:
|
||||
if (typeof languageService[method] === "function") {
|
||||
// The `getCompletionEntryDetails()` method returns null if the
|
||||
// `source` is `null` for whatever reason. It must be `undefined`.
|
||||
if (method == "getCompletionEntryDetails") {
|
||||
args[4] ??= undefined;
|
||||
}
|
||||
return respond(id, languageService[method](...args));
|
||||
}
|
||||
throw new TypeError(
|
||||
// @ts-ignore exhausted case statement sets type to never
|
||||
`Invalid request method for request: "${request.method}" (${id})`,
|
||||
`Invalid request method for request: "${method}" (${id})`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
235
cli/tsc/compiler.d.ts
vendored
235
cli/tsc/compiler.d.ts
vendored
|
@ -56,239 +56,4 @@ declare global {
|
|||
...args: any[]
|
||||
): void;
|
||||
}
|
||||
|
||||
type LanguageServerRequest =
|
||||
| Restart
|
||||
| ConfigureRequest
|
||||
| FindRenameLocationsRequest
|
||||
| GetAssets
|
||||
| GetApplicableRefactors
|
||||
| GetEditsForRefactor
|
||||
| GetEditsForFileRename
|
||||
| GetCodeFixes
|
||||
| GetCombinedCodeFix
|
||||
| GetCompletionDetails
|
||||
| GetCompletionsRequest
|
||||
| GetDefinitionRequest
|
||||
| GetDiagnosticsRequest
|
||||
| GetDocumentHighlightsRequest
|
||||
| GetEncodedSemanticClassifications
|
||||
| GetImplementationRequest
|
||||
| GetNavigateToItems
|
||||
| GetNavigationTree
|
||||
| GetOutliningSpans
|
||||
| GetQuickInfoRequest
|
||||
| FindReferencesRequest
|
||||
| GetSignatureHelpItemsRequest
|
||||
| GetSmartSelectionRange
|
||||
| GetSupportedCodeFixes
|
||||
| GetTypeDefinitionRequest
|
||||
| PrepareCallHierarchy
|
||||
| ProvideCallHierarchyIncomingCalls
|
||||
| ProvideCallHierarchyOutgoingCalls
|
||||
| ProvideInlayHints;
|
||||
|
||||
interface BaseLanguageServerRequest {
|
||||
id: number;
|
||||
method: string;
|
||||
}
|
||||
|
||||
interface ConfigureRequest extends BaseLanguageServerRequest {
|
||||
method: "configure";
|
||||
// deno-lint-ignore no-explicit-any
|
||||
compilerOptions: Record<string, any>;
|
||||
}
|
||||
|
||||
interface FindRenameLocationsRequest extends BaseLanguageServerRequest {
|
||||
method: "findRenameLocations";
|
||||
specifier: string;
|
||||
position: number;
|
||||
findInStrings: boolean;
|
||||
findInComments: boolean;
|
||||
providePrefixAndSuffixTextForRename: boolean;
|
||||
}
|
||||
|
||||
interface GetAssets extends BaseLanguageServerRequest {
|
||||
method: "getAssets";
|
||||
}
|
||||
|
||||
interface GetApplicableRefactors extends BaseLanguageServerRequest {
|
||||
method: "getApplicableRefactors";
|
||||
specifier: string;
|
||||
range: ts.TextRange;
|
||||
preferences?: ts.UserPreferences;
|
||||
kind: string;
|
||||
}
|
||||
|
||||
interface GetEditsForRefactor extends BaseLanguageServerRequest {
|
||||
method: "getEditsForRefactor";
|
||||
specifier: string;
|
||||
formatCodeSettings: ts.FormatCodeSettings;
|
||||
range: ts.TextRange;
|
||||
refactorName: string;
|
||||
actionName: string;
|
||||
preferences?: ts.UserPreferences;
|
||||
}
|
||||
|
||||
interface GetEditsForFileRename extends BaseLanguageServerRequest {
|
||||
method: "getEditsForFileRename";
|
||||
oldSpecifier: string;
|
||||
newSpecifier: string;
|
||||
formatCodeSettings: ts.FormatCodeSettings;
|
||||
preferences?: ts.UserPreferences;
|
||||
}
|
||||
|
||||
interface GetCodeFixes extends BaseLanguageServerRequest {
|
||||
method: "getCodeFixes";
|
||||
specifier: string;
|
||||
startPosition: number;
|
||||
endPosition: number;
|
||||
errorCodes: string[];
|
||||
formatCodeSettings: ts.FormatCodeSettings;
|
||||
preferences: ts.UserPreferences;
|
||||
}
|
||||
|
||||
interface GetCombinedCodeFix extends BaseLanguageServerRequest {
|
||||
method: "getCombinedCodeFix";
|
||||
specifier: string;
|
||||
// deno-lint-ignore ban-types
|
||||
fixId: {};
|
||||
formatCodeSettings: ts.FormatCodeSettings;
|
||||
preferences: ts.UserPreferences;
|
||||
}
|
||||
|
||||
interface GetCompletionDetails extends BaseLanguageServerRequest {
|
||||
method: "getCompletionDetails";
|
||||
args: {
|
||||
specifier: string;
|
||||
position: number;
|
||||
name: string;
|
||||
formatCodeSettings: ts.FormatCodeSettings;
|
||||
source?: string;
|
||||
preferences?: ts.UserPreferences;
|
||||
data?: ts.CompletionEntryData;
|
||||
};
|
||||
}
|
||||
|
||||
interface GetCompletionsRequest extends BaseLanguageServerRequest {
|
||||
method: "getCompletions";
|
||||
specifier: string;
|
||||
position: number;
|
||||
preferences: ts.GetCompletionsAtPositionOptions;
|
||||
formatCodeSettings: ts.FormatCodeSettings;
|
||||
}
|
||||
|
||||
interface GetDiagnosticsRequest extends BaseLanguageServerRequest {
|
||||
method: "getDiagnostics";
|
||||
specifiers: string[];
|
||||
}
|
||||
|
||||
interface GetDefinitionRequest extends BaseLanguageServerRequest {
|
||||
method: "getDefinition";
|
||||
specifier: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
interface GetDocumentHighlightsRequest extends BaseLanguageServerRequest {
|
||||
method: "getDocumentHighlights";
|
||||
specifier: string;
|
||||
position: number;
|
||||
filesToSearch: string[];
|
||||
}
|
||||
|
||||
interface GetEncodedSemanticClassifications
|
||||
extends BaseLanguageServerRequest {
|
||||
method: "getEncodedSemanticClassifications";
|
||||
specifier: string;
|
||||
span: ts.TextSpan;
|
||||
}
|
||||
|
||||
interface GetImplementationRequest extends BaseLanguageServerRequest {
|
||||
method: "getImplementation";
|
||||
specifier: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
interface GetNavigateToItems extends BaseLanguageServerRequest {
|
||||
method: "getNavigateToItems";
|
||||
search: string;
|
||||
maxResultCount?: number;
|
||||
fileName?: string;
|
||||
}
|
||||
|
||||
interface GetNavigationTree extends BaseLanguageServerRequest {
|
||||
method: "getNavigationTree";
|
||||
specifier: string;
|
||||
}
|
||||
|
||||
interface GetOutliningSpans extends BaseLanguageServerRequest {
|
||||
method: "getOutliningSpans";
|
||||
specifier: string;
|
||||
}
|
||||
|
||||
interface GetQuickInfoRequest extends BaseLanguageServerRequest {
|
||||
method: "getQuickInfo";
|
||||
specifier: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
interface FindReferencesRequest extends BaseLanguageServerRequest {
|
||||
method: "findReferences";
|
||||
specifier: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
interface GetSignatureHelpItemsRequest extends BaseLanguageServerRequest {
|
||||
method: "getSignatureHelpItems";
|
||||
specifier: string;
|
||||
position: number;
|
||||
options: ts.SignatureHelpItemsOptions;
|
||||
}
|
||||
|
||||
interface GetSmartSelectionRange extends BaseLanguageServerRequest {
|
||||
method: "getSmartSelectionRange";
|
||||
specifier: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
interface GetSupportedCodeFixes extends BaseLanguageServerRequest {
|
||||
method: "getSupportedCodeFixes";
|
||||
}
|
||||
|
||||
interface GetTypeDefinitionRequest extends BaseLanguageServerRequest {
|
||||
method: "getTypeDefinition";
|
||||
specifier: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
interface PrepareCallHierarchy extends BaseLanguageServerRequest {
|
||||
method: "prepareCallHierarchy";
|
||||
specifier: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
interface ProvideCallHierarchyIncomingCalls
|
||||
extends BaseLanguageServerRequest {
|
||||
method: "provideCallHierarchyIncomingCalls";
|
||||
specifier: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
interface ProvideCallHierarchyOutgoingCalls
|
||||
extends BaseLanguageServerRequest {
|
||||
method: "provideCallHierarchyOutgoingCalls";
|
||||
specifier: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
interface ProvideInlayHints extends BaseLanguageServerRequest {
|
||||
method: "provideInlayHints";
|
||||
specifier: string;
|
||||
span: ts.TextSpan;
|
||||
preferences?: ts.UserPreferences;
|
||||
}
|
||||
|
||||
interface Restart extends BaseLanguageServerRequest {
|
||||
method: "restart";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,10 +113,13 @@ pub struct Diagnostic {
|
|||
pub start: Option<Position>,
|
||||
pub end: Option<Position>,
|
||||
pub message_text: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub message_chain: Option<DiagnosticMessageChain>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub source: Option<String>,
|
||||
pub source_line: Option<String>,
|
||||
pub file_name: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub related_information: Option<Vec<Diagnostic>>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue