mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into ownJsonParsing
This commit is contained in:
+46
-6
@@ -224,7 +224,7 @@ namespace ts.server {
|
||||
return { name, kind, kindModifiers, sortText, replacementSpan: convertedSpan };
|
||||
}
|
||||
|
||||
return entry as { name: string, kind: string, kindModifiers: string, sortText: string };
|
||||
return entry as { name: string, kind: ScriptElementKind, kindModifiers: string, sortText: string };
|
||||
})
|
||||
};
|
||||
}
|
||||
@@ -265,7 +265,7 @@ namespace ts.server {
|
||||
return {
|
||||
name: entry.name,
|
||||
containerName: entry.containerName || "",
|
||||
containerKind: entry.containerKind || "",
|
||||
containerKind: entry.containerKind || ScriptElementKind.unknown,
|
||||
kind: entry.kind,
|
||||
kindModifiers: entry.kindModifiers,
|
||||
matchKind: entry.matchKind,
|
||||
@@ -330,11 +330,11 @@ namespace ts.server {
|
||||
const start = this.lineOffsetToPosition(fileName, entry.start);
|
||||
const end = this.lineOffsetToPosition(fileName, entry.end);
|
||||
return {
|
||||
containerKind: "",
|
||||
containerKind: ScriptElementKind.unknown,
|
||||
containerName: "",
|
||||
fileName: fileName,
|
||||
textSpan: ts.createTextSpanFromBounds(start, end),
|
||||
kind: "",
|
||||
kind: ScriptElementKind.unknown,
|
||||
name: ""
|
||||
};
|
||||
});
|
||||
@@ -356,11 +356,11 @@ namespace ts.server {
|
||||
const start = this.lineOffsetToPosition(fileName, entry.start);
|
||||
const end = this.lineOffsetToPosition(fileName, entry.end);
|
||||
return {
|
||||
containerKind: "",
|
||||
containerKind: ScriptElementKind.unknown,
|
||||
containerName: "",
|
||||
fileName: fileName,
|
||||
textSpan: ts.createTextSpanFromBounds(start, end),
|
||||
kind: "",
|
||||
kind: ScriptElementKind.unknown,
|
||||
name: ""
|
||||
};
|
||||
});
|
||||
@@ -695,6 +695,46 @@ namespace ts.server {
|
||||
return response.body.map(entry => this.convertCodeActions(entry, fileName));
|
||||
}
|
||||
|
||||
private createFileLocationOrRangeRequestArgs(positionOrRange: number | TextRange, fileName: string): protocol.FileLocationOrRangeRequestArgs {
|
||||
if (typeof positionOrRange === "number") {
|
||||
const { line, offset } = this.positionToOneBasedLineOffset(fileName, positionOrRange);
|
||||
return <protocol.FileLocationRequestArgs>{ file: fileName, line, offset };
|
||||
}
|
||||
const { line: startLine, offset: startOffset } = this.positionToOneBasedLineOffset(fileName, positionOrRange.pos);
|
||||
const { line: endLine, offset: endOffset } = this.positionToOneBasedLineOffset(fileName, positionOrRange.end);
|
||||
return <protocol.FileRangeRequestArgs>{
|
||||
file: fileName,
|
||||
startLine,
|
||||
startOffset,
|
||||
endLine,
|
||||
endOffset
|
||||
};
|
||||
}
|
||||
|
||||
getApplicableRefactors(fileName: string, positionOrRange: number | TextRange): ApplicableRefactorInfo[] {
|
||||
const args = this.createFileLocationOrRangeRequestArgs(positionOrRange, fileName);
|
||||
|
||||
const request = this.processRequest<protocol.GetApplicableRefactorsRequest>(CommandNames.GetApplicableRefactors, args);
|
||||
const response = this.processResponse<protocol.GetApplicableRefactorsResponse>(request);
|
||||
return response.body;
|
||||
}
|
||||
|
||||
getRefactorCodeActions(
|
||||
fileName: string,
|
||||
_formatOptions: FormatCodeSettings,
|
||||
positionOrRange: number | TextRange,
|
||||
refactorName: string) {
|
||||
|
||||
const args = this.createFileLocationOrRangeRequestArgs(positionOrRange, fileName) as protocol.GetRefactorCodeActionsRequestArgs;
|
||||
args.refactorName = refactorName;
|
||||
|
||||
const request = this.processRequest<protocol.GetRefactorCodeActionsRequest>(CommandNames.GetRefactorCodeActions, args);
|
||||
const response = this.processResponse<protocol.GetRefactorCodeActionsResponse>(request);
|
||||
const codeActions = response.body.actions;
|
||||
|
||||
return map(codeActions, codeAction => this.convertCodeActions(codeAction, fileName));
|
||||
}
|
||||
|
||||
convertCodeActions(entry: protocol.CodeAction, fileName: string): CodeAction {
|
||||
return {
|
||||
description: entry.description,
|
||||
|
||||
@@ -283,6 +283,7 @@ namespace ts.server {
|
||||
throttleWaitMilliseconds?: number;
|
||||
globalPlugins?: string[];
|
||||
pluginProbeLocations?: string[];
|
||||
allowLocalPluginLoads?: boolean;
|
||||
}
|
||||
|
||||
export class ProjectService {
|
||||
@@ -342,6 +343,7 @@ namespace ts.server {
|
||||
|
||||
public readonly globalPlugins: ReadonlyArray<string>;
|
||||
public readonly pluginProbeLocations: ReadonlyArray<string>;
|
||||
public readonly allowLocalPluginLoads: boolean;
|
||||
|
||||
constructor(opts: ProjectServiceOptions) {
|
||||
this.host = opts.host;
|
||||
@@ -353,6 +355,7 @@ namespace ts.server {
|
||||
this.eventHandler = opts.eventHandler;
|
||||
this.globalPlugins = opts.globalPlugins || emptyArray;
|
||||
this.pluginProbeLocations = opts.pluginProbeLocations || emptyArray;
|
||||
this.allowLocalPluginLoads = !!opts.allowLocalPluginLoads;
|
||||
|
||||
Debug.assert(!!this.host.createHash, "'ServerHost.createHash' is required for ProjectService");
|
||||
|
||||
|
||||
@@ -13,13 +13,6 @@ namespace ts.server {
|
||||
External
|
||||
}
|
||||
|
||||
function remove<T>(items: T[], item: T) {
|
||||
const index = items.indexOf(item);
|
||||
if (index >= 0) {
|
||||
items.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
function countEachFileTypes(infos: ScriptInfo[]): { js: number, jsx: number, ts: number, tsx: number, dts: number } {
|
||||
const result = { js: 0, jsx: 0, ts: 0, tsx: 0, dts: 0 };
|
||||
for (const info of infos) {
|
||||
@@ -769,7 +762,7 @@ namespace ts.server {
|
||||
|
||||
// remove a root file from project
|
||||
protected removeRoot(info: ScriptInfo): void {
|
||||
remove(this.rootFiles, info);
|
||||
orderedRemoveItem(this.rootFiles, info);
|
||||
this.rootFilesMap.remove(info.path);
|
||||
}
|
||||
}
|
||||
@@ -910,6 +903,12 @@ namespace ts.server {
|
||||
// ../../.. to walk from X/node_modules/typescript/lib/tsserver.js to X/node_modules/
|
||||
const searchPaths = [combinePaths(host.getExecutingFilePath(), "../../.."), ...this.projectService.pluginProbeLocations];
|
||||
|
||||
if (this.projectService.allowLocalPluginLoads) {
|
||||
const local = getDirectoryPath(this.canonicalConfigFilePath);
|
||||
this.projectService.logger.info(`Local plugin loading enabled; adding ${local} to search paths`);
|
||||
searchPaths.unshift(local);
|
||||
}
|
||||
|
||||
// Enable tsconfig-specified plugins
|
||||
if (options.plugins) {
|
||||
for (const pluginConfigEntry of options.plugins) {
|
||||
|
||||
+165
-123
@@ -2,99 +2,104 @@
|
||||
* Declaration module describing the TypeScript Server protocol
|
||||
*/
|
||||
namespace ts.server.protocol {
|
||||
export namespace CommandTypes {
|
||||
export type Brace = "brace";
|
||||
// NOTE: If updating this, be sure to also update `allCommandNames` in `harness/unittests/session.ts`.
|
||||
export const enum CommandTypes {
|
||||
Brace = "brace",
|
||||
/* @internal */
|
||||
export type BraceFull = "brace-full";
|
||||
export type BraceCompletion = "braceCompletion";
|
||||
export type Change = "change";
|
||||
export type Close = "close";
|
||||
export type Completions = "completions";
|
||||
BraceFull = "brace-full",
|
||||
BraceCompletion = "braceCompletion",
|
||||
Change = "change",
|
||||
Close = "close",
|
||||
Completions = "completions",
|
||||
/* @internal */
|
||||
export type CompletionsFull = "completions-full";
|
||||
export type CompletionDetails = "completionEntryDetails";
|
||||
export type CompileOnSaveAffectedFileList = "compileOnSaveAffectedFileList";
|
||||
export type CompileOnSaveEmitFile = "compileOnSaveEmitFile";
|
||||
export type Configure = "configure";
|
||||
export type Definition = "definition";
|
||||
CompletionsFull = "completions-full",
|
||||
CompletionDetails = "completionEntryDetails",
|
||||
CompileOnSaveAffectedFileList = "compileOnSaveAffectedFileList",
|
||||
CompileOnSaveEmitFile = "compileOnSaveEmitFile",
|
||||
Configure = "configure",
|
||||
Definition = "definition",
|
||||
/* @internal */
|
||||
export type DefinitionFull = "definition-full";
|
||||
export type Implementation = "implementation";
|
||||
DefinitionFull = "definition-full",
|
||||
Implementation = "implementation",
|
||||
/* @internal */
|
||||
export type ImplementationFull = "implementation-full";
|
||||
export type Exit = "exit";
|
||||
export type Format = "format";
|
||||
export type Formatonkey = "formatonkey";
|
||||
ImplementationFull = "implementation-full",
|
||||
Exit = "exit",
|
||||
Format = "format",
|
||||
Formatonkey = "formatonkey",
|
||||
/* @internal */
|
||||
export type FormatFull = "format-full";
|
||||
FormatFull = "format-full",
|
||||
/* @internal */
|
||||
export type FormatonkeyFull = "formatonkey-full";
|
||||
FormatonkeyFull = "formatonkey-full",
|
||||
/* @internal */
|
||||
export type FormatRangeFull = "formatRange-full";
|
||||
export type Geterr = "geterr";
|
||||
export type GeterrForProject = "geterrForProject";
|
||||
export type SemanticDiagnosticsSync = "semanticDiagnosticsSync";
|
||||
export type SyntacticDiagnosticsSync = "syntacticDiagnosticsSync";
|
||||
export type NavBar = "navbar";
|
||||
FormatRangeFull = "formatRange-full",
|
||||
Geterr = "geterr",
|
||||
GeterrForProject = "geterrForProject",
|
||||
SemanticDiagnosticsSync = "semanticDiagnosticsSync",
|
||||
SyntacticDiagnosticsSync = "syntacticDiagnosticsSync",
|
||||
NavBar = "navbar",
|
||||
/* @internal */
|
||||
export type NavBarFull = "navbar-full";
|
||||
export type Navto = "navto";
|
||||
NavBarFull = "navbar-full",
|
||||
Navto = "navto",
|
||||
/* @internal */
|
||||
export type NavtoFull = "navto-full";
|
||||
export type NavTree = "navtree";
|
||||
export type NavTreeFull = "navtree-full";
|
||||
export type Occurrences = "occurrences";
|
||||
export type DocumentHighlights = "documentHighlights";
|
||||
NavtoFull = "navto-full",
|
||||
NavTree = "navtree",
|
||||
NavTreeFull = "navtree-full",
|
||||
Occurrences = "occurrences",
|
||||
DocumentHighlights = "documentHighlights",
|
||||
/* @internal */
|
||||
export type DocumentHighlightsFull = "documentHighlights-full";
|
||||
export type Open = "open";
|
||||
export type Quickinfo = "quickinfo";
|
||||
DocumentHighlightsFull = "documentHighlights-full",
|
||||
Open = "open",
|
||||
Quickinfo = "quickinfo",
|
||||
/* @internal */
|
||||
export type QuickinfoFull = "quickinfo-full";
|
||||
export type References = "references";
|
||||
QuickinfoFull = "quickinfo-full",
|
||||
References = "references",
|
||||
/* @internal */
|
||||
export type ReferencesFull = "references-full";
|
||||
export type Reload = "reload";
|
||||
export type Rename = "rename";
|
||||
ReferencesFull = "references-full",
|
||||
Reload = "reload",
|
||||
Rename = "rename",
|
||||
/* @internal */
|
||||
export type RenameInfoFull = "rename-full";
|
||||
RenameInfoFull = "rename-full",
|
||||
/* @internal */
|
||||
export type RenameLocationsFull = "renameLocations-full";
|
||||
export type Saveto = "saveto";
|
||||
export type SignatureHelp = "signatureHelp";
|
||||
RenameLocationsFull = "renameLocations-full",
|
||||
Saveto = "saveto",
|
||||
SignatureHelp = "signatureHelp",
|
||||
/* @internal */
|
||||
export type SignatureHelpFull = "signatureHelp-full";
|
||||
export type TypeDefinition = "typeDefinition";
|
||||
export type ProjectInfo = "projectInfo";
|
||||
export type ReloadProjects = "reloadProjects";
|
||||
export type Unknown = "unknown";
|
||||
export type OpenExternalProject = "openExternalProject";
|
||||
export type OpenExternalProjects = "openExternalProjects";
|
||||
export type CloseExternalProject = "closeExternalProject";
|
||||
SignatureHelpFull = "signatureHelp-full",
|
||||
TypeDefinition = "typeDefinition",
|
||||
ProjectInfo = "projectInfo",
|
||||
ReloadProjects = "reloadProjects",
|
||||
Unknown = "unknown",
|
||||
OpenExternalProject = "openExternalProject",
|
||||
OpenExternalProjects = "openExternalProjects",
|
||||
CloseExternalProject = "closeExternalProject",
|
||||
/* @internal */
|
||||
export type SynchronizeProjectList = "synchronizeProjectList";
|
||||
SynchronizeProjectList = "synchronizeProjectList",
|
||||
/* @internal */
|
||||
export type ApplyChangedToOpenFiles = "applyChangedToOpenFiles";
|
||||
ApplyChangedToOpenFiles = "applyChangedToOpenFiles",
|
||||
/* @internal */
|
||||
export type EncodedSemanticClassificationsFull = "encodedSemanticClassifications-full";
|
||||
EncodedSemanticClassificationsFull = "encodedSemanticClassifications-full",
|
||||
/* @internal */
|
||||
export type Cleanup = "cleanup";
|
||||
Cleanup = "cleanup",
|
||||
/* @internal */
|
||||
export type OutliningSpans = "outliningSpans";
|
||||
export type TodoComments = "todoComments";
|
||||
export type Indentation = "indentation";
|
||||
export type DocCommentTemplate = "docCommentTemplate";
|
||||
OutliningSpans = "outliningSpans",
|
||||
TodoComments = "todoComments",
|
||||
Indentation = "indentation",
|
||||
DocCommentTemplate = "docCommentTemplate",
|
||||
/* @internal */
|
||||
export type CompilerOptionsDiagnosticsFull = "compilerOptionsDiagnostics-full";
|
||||
CompilerOptionsDiagnosticsFull = "compilerOptionsDiagnostics-full",
|
||||
/* @internal */
|
||||
export type NameOrDottedNameSpan = "nameOrDottedNameSpan";
|
||||
NameOrDottedNameSpan = "nameOrDottedNameSpan",
|
||||
/* @internal */
|
||||
export type BreakpointStatement = "breakpointStatement";
|
||||
export type CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects";
|
||||
export type GetCodeFixes = "getCodeFixes";
|
||||
BreakpointStatement = "breakpointStatement",
|
||||
CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects",
|
||||
GetCodeFixes = "getCodeFixes",
|
||||
/* @internal */
|
||||
export type GetCodeFixesFull = "getCodeFixes-full";
|
||||
export type GetSupportedCodeFixes = "getSupportedCodeFixes";
|
||||
GetCodeFixesFull = "getCodeFixes-full",
|
||||
GetSupportedCodeFixes = "getSupportedCodeFixes",
|
||||
|
||||
GetApplicableRefactors = "getApplicableRefactors",
|
||||
GetRefactorCodeActions = "getRefactorCodeActions",
|
||||
GetRefactorCodeActionsFull = "getRefactorCodeActions-full",
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -394,6 +399,54 @@ namespace ts.server.protocol {
|
||||
position?: number;
|
||||
}
|
||||
|
||||
export type FileLocationOrRangeRequestArgs = FileLocationRequestArgs | FileRangeRequestArgs;
|
||||
|
||||
export interface GetApplicableRefactorsRequest extends Request {
|
||||
command: CommandTypes.GetApplicableRefactors;
|
||||
arguments: GetApplicableRefactorsRequestArgs;
|
||||
}
|
||||
|
||||
export type GetApplicableRefactorsRequestArgs = FileLocationOrRangeRequestArgs;
|
||||
|
||||
export interface ApplicableRefactorInfo {
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface GetApplicableRefactorsResponse extends Response {
|
||||
body?: ApplicableRefactorInfo[];
|
||||
}
|
||||
|
||||
export interface GetRefactorCodeActionsRequest extends Request {
|
||||
command: CommandTypes.GetRefactorCodeActions;
|
||||
arguments: GetRefactorCodeActionsRequestArgs;
|
||||
}
|
||||
|
||||
export type GetRefactorCodeActionsRequestArgs = FileLocationOrRangeRequestArgs & {
|
||||
/* The kind of the applicable refactor */
|
||||
refactorName: string;
|
||||
};
|
||||
|
||||
export type RefactorCodeActions = {
|
||||
actions: protocol.CodeAction[];
|
||||
renameLocation?: number
|
||||
};
|
||||
|
||||
/* @internal */
|
||||
export type RefactorCodeActionsFull = {
|
||||
actions: ts.CodeAction[];
|
||||
renameLocation?: number
|
||||
};
|
||||
|
||||
export interface GetRefactorCodeActionsResponse extends Response {
|
||||
body: RefactorCodeActions;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export interface GetRefactorCodeActionsFullResponse extends Response {
|
||||
body: RefactorCodeActionsFull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request for the available codefixes at a specific position.
|
||||
*/
|
||||
@@ -402,10 +455,7 @@ namespace ts.server.protocol {
|
||||
arguments: CodeFixRequestArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instances of this interface specify errorcodes on a specific location in a sourcefile.
|
||||
*/
|
||||
export interface CodeFixRequestArgs extends FileRequestArgs {
|
||||
export interface FileRangeRequestArgs extends FileRequestArgs {
|
||||
/**
|
||||
* The line number for the request (1-based).
|
||||
*/
|
||||
@@ -437,7 +487,12 @@ namespace ts.server.protocol {
|
||||
*/
|
||||
/* @internal */
|
||||
endPosition?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instances of this interface specify errorcodes on a specific location in a sourcefile.
|
||||
*/
|
||||
export interface CodeFixRequestArgs extends FileRangeRequestArgs {
|
||||
/**
|
||||
* Errorcodes we want to get the fixes for.
|
||||
*/
|
||||
@@ -644,10 +699,9 @@ namespace ts.server.protocol {
|
||||
|
||||
/**
|
||||
* Span augmented with extra information that denotes the kind of the highlighting to be used for span.
|
||||
* Kind is taken from HighlightSpanKind type.
|
||||
*/
|
||||
export interface HighlightSpan extends TextSpan {
|
||||
kind: string;
|
||||
kind: HighlightSpanKind;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -784,7 +838,7 @@ namespace ts.server.protocol {
|
||||
/**
|
||||
* The items's kind (such as 'className' or 'parameterName' or plain 'text').
|
||||
*/
|
||||
kind: string;
|
||||
kind: ScriptElementKind;
|
||||
|
||||
/**
|
||||
* Optional modifiers for the kind (such as 'public').
|
||||
@@ -1298,7 +1352,7 @@ namespace ts.server.protocol {
|
||||
/**
|
||||
* The symbol's kind (such as 'className' or 'parameterName' or plain 'text').
|
||||
*/
|
||||
kind: string;
|
||||
kind: ScriptElementKind;
|
||||
|
||||
/**
|
||||
* Optional modifiers for the kind (such as 'public').
|
||||
@@ -1517,7 +1571,7 @@ namespace ts.server.protocol {
|
||||
/**
|
||||
* The symbol's kind (such as 'className' or 'parameterName').
|
||||
*/
|
||||
kind: string;
|
||||
kind: ScriptElementKind;
|
||||
/**
|
||||
* Optional modifiers for the kind (such as 'public').
|
||||
*/
|
||||
@@ -1545,7 +1599,7 @@ namespace ts.server.protocol {
|
||||
/**
|
||||
* The symbol's kind (such as 'className' or 'parameterName').
|
||||
*/
|
||||
kind: string;
|
||||
kind: ScriptElementKind;
|
||||
/**
|
||||
* Optional modifiers for the kind (such as 'public').
|
||||
*/
|
||||
@@ -2011,7 +2065,7 @@ namespace ts.server.protocol {
|
||||
/**
|
||||
* The symbol's kind (such as 'className' or 'parameterName').
|
||||
*/
|
||||
kind: string;
|
||||
kind: ScriptElementKind;
|
||||
|
||||
/**
|
||||
* exact, substring, or prefix.
|
||||
@@ -2052,7 +2106,7 @@ namespace ts.server.protocol {
|
||||
/**
|
||||
* Kind of symbol's container symbol (if any).
|
||||
*/
|
||||
containerKind?: string;
|
||||
containerKind?: ScriptElementKind;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2125,7 +2179,7 @@ namespace ts.server.protocol {
|
||||
/**
|
||||
* The symbol's kind (such as 'className' or 'parameterName').
|
||||
*/
|
||||
kind: string;
|
||||
kind: ScriptElementKind;
|
||||
|
||||
/**
|
||||
* Optional modifiers for the kind (such as 'public').
|
||||
@@ -2151,7 +2205,7 @@ namespace ts.server.protocol {
|
||||
/** protocol.NavigationTree is identical to ts.NavigationTree, except using protocol.TextSpan instead of ts.TextSpan */
|
||||
export interface NavigationTree {
|
||||
text: string;
|
||||
kind: string;
|
||||
kind: ScriptElementKind;
|
||||
kindModifiers: string;
|
||||
spans: TextSpan[];
|
||||
childItems?: NavigationTree[];
|
||||
@@ -2245,14 +2299,12 @@ namespace ts.server.protocol {
|
||||
body?: NavigationTree;
|
||||
}
|
||||
|
||||
export namespace IndentStyle {
|
||||
export type None = "None";
|
||||
export type Block = "Block";
|
||||
export type Smart = "Smart";
|
||||
export const enum IndentStyle {
|
||||
None = "None",
|
||||
Block = "Block",
|
||||
Smart = "Smart",
|
||||
}
|
||||
|
||||
export type IndentStyle = IndentStyle.None | IndentStyle.Block | IndentStyle.Smart;
|
||||
|
||||
export interface EditorSettings {
|
||||
baseIndentSize?: number;
|
||||
indentSize?: number;
|
||||
@@ -2349,47 +2401,37 @@ namespace ts.server.protocol {
|
||||
[option: string]: CompilerOptionsValue | undefined;
|
||||
}
|
||||
|
||||
export namespace JsxEmit {
|
||||
export type None = "None";
|
||||
export type Preserve = "Preserve";
|
||||
export type ReactNative = "ReactNative";
|
||||
export type React = "React";
|
||||
export const enum JsxEmit {
|
||||
None = "None",
|
||||
Preserve = "Preserve",
|
||||
ReactNative = "ReactNative",
|
||||
React = "React",
|
||||
}
|
||||
|
||||
export type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React | JsxEmit.ReactNative;
|
||||
|
||||
export namespace ModuleKind {
|
||||
export type None = "None";
|
||||
export type CommonJS = "CommonJS";
|
||||
export type AMD = "AMD";
|
||||
export type UMD = "UMD";
|
||||
export type System = "System";
|
||||
export type ES6 = "ES6";
|
||||
export type ES2015 = "ES2015";
|
||||
export const enum ModuleKind {
|
||||
None = "None",
|
||||
CommonJS = "CommonJS",
|
||||
AMD = "AMD",
|
||||
UMD = "UMD",
|
||||
System = "System",
|
||||
ES6 = "ES6",
|
||||
ES2015 = "ES2015",
|
||||
}
|
||||
|
||||
export type ModuleKind = ModuleKind.None | ModuleKind.CommonJS | ModuleKind.AMD | ModuleKind.UMD | ModuleKind.System | ModuleKind.ES6 | ModuleKind.ES2015;
|
||||
|
||||
export namespace ModuleResolutionKind {
|
||||
export type Classic = "Classic";
|
||||
export type Node = "Node";
|
||||
export const enum ModuleResolutionKind {
|
||||
Classic = "Classic",
|
||||
Node = "Node",
|
||||
}
|
||||
|
||||
export type ModuleResolutionKind = ModuleResolutionKind.Classic | ModuleResolutionKind.Node;
|
||||
|
||||
export namespace NewLineKind {
|
||||
export type Crlf = "Crlf";
|
||||
export type Lf = "Lf";
|
||||
export const enum NewLineKind {
|
||||
Crlf = "Crlf",
|
||||
Lf = "Lf",
|
||||
}
|
||||
|
||||
export type NewLineKind = NewLineKind.Crlf | NewLineKind.Lf;
|
||||
|
||||
export namespace ScriptTarget {
|
||||
export type ES3 = "ES3";
|
||||
export type ES5 = "ES5";
|
||||
export type ES6 = "ES6";
|
||||
export type ES2015 = "ES2015";
|
||||
export const enum ScriptTarget {
|
||||
ES3 = "ES3",
|
||||
ES5 = "ES5",
|
||||
ES6 = "ES6",
|
||||
ES2015 = "ES2015",
|
||||
}
|
||||
|
||||
export type ScriptTarget = ScriptTarget.ES3 | ScriptTarget.ES5 | ScriptTarget.ES6 | ScriptTarget.ES2015;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace ts.server {
|
||||
telemetryEnabled: boolean;
|
||||
globalPlugins: string[];
|
||||
pluginProbeLocations: string[];
|
||||
allowLocalPluginLoads: boolean;
|
||||
}
|
||||
|
||||
const net: {
|
||||
@@ -403,7 +404,8 @@ namespace ts.server {
|
||||
logger,
|
||||
canUseEvents,
|
||||
globalPlugins: options.globalPlugins,
|
||||
pluginProbeLocations: options.pluginProbeLocations});
|
||||
pluginProbeLocations: options.pluginProbeLocations,
|
||||
allowLocalPluginLoads: options.allowLocalPluginLoads });
|
||||
|
||||
if (telemetryEnabled && typingsInstaller) {
|
||||
typingsInstaller.setTelemetrySender(this);
|
||||
@@ -743,6 +745,7 @@ namespace ts.server {
|
||||
|
||||
const globalPlugins = (findArgument("--globalPlugins") || "").split(",");
|
||||
const pluginProbeLocations = (findArgument("--pluginProbeLocations") || "").split(",");
|
||||
const allowLocalPluginLoads = hasArgument("--allowLocalPluginLoads");
|
||||
|
||||
const useSingleInferredProject = hasArgument("--useSingleInferredProject");
|
||||
const disableAutomaticTypingAcquisition = hasArgument("--disableAutomaticTypingAcquisition");
|
||||
@@ -760,7 +763,8 @@ namespace ts.server {
|
||||
telemetryEnabled,
|
||||
logger,
|
||||
globalPlugins,
|
||||
pluginProbeLocations
|
||||
pluginProbeLocations,
|
||||
allowLocalPluginLoads
|
||||
};
|
||||
|
||||
const ioSession = new IOSession(options);
|
||||
|
||||
+98
-113
@@ -106,7 +106,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
export interface EventSender {
|
||||
event(payload: any, eventName: string): void;
|
||||
event<T>(payload: T, eventName: string): void;
|
||||
}
|
||||
|
||||
function allEditsBeforePos(edits: ts.TextChange[], pos: number) {
|
||||
@@ -118,100 +118,7 @@ namespace ts.server {
|
||||
return true;
|
||||
}
|
||||
|
||||
export namespace CommandNames {
|
||||
export const Brace: protocol.CommandTypes.Brace = "brace";
|
||||
/* @internal */
|
||||
export const BraceFull: protocol.CommandTypes.BraceFull = "brace-full";
|
||||
export const BraceCompletion: protocol.CommandTypes.BraceCompletion = "braceCompletion";
|
||||
export const Change: protocol.CommandTypes.Change = "change";
|
||||
export const Close: protocol.CommandTypes.Close = "close";
|
||||
export const Completions: protocol.CommandTypes.Completions = "completions";
|
||||
/* @internal */
|
||||
export const CompletionsFull: protocol.CommandTypes.CompletionsFull = "completions-full";
|
||||
export const CompletionDetails: protocol.CommandTypes.CompletionDetails = "completionEntryDetails";
|
||||
export const CompileOnSaveAffectedFileList: protocol.CommandTypes.CompileOnSaveAffectedFileList = "compileOnSaveAffectedFileList";
|
||||
export const CompileOnSaveEmitFile: protocol.CommandTypes.CompileOnSaveEmitFile = "compileOnSaveEmitFile";
|
||||
export const Configure: protocol.CommandTypes.Configure = "configure";
|
||||
export const Definition: protocol.CommandTypes.Definition = "definition";
|
||||
/* @internal */
|
||||
export const DefinitionFull: protocol.CommandTypes.DefinitionFull = "definition-full";
|
||||
export const Exit: protocol.CommandTypes.Exit = "exit";
|
||||
export const Format: protocol.CommandTypes.Format = "format";
|
||||
export const Formatonkey: protocol.CommandTypes.Formatonkey = "formatonkey";
|
||||
/* @internal */
|
||||
export const FormatFull: protocol.CommandTypes.FormatFull = "format-full";
|
||||
/* @internal */
|
||||
export const FormatonkeyFull: protocol.CommandTypes.FormatonkeyFull = "formatonkey-full";
|
||||
/* @internal */
|
||||
export const FormatRangeFull: protocol.CommandTypes.FormatRangeFull = "formatRange-full";
|
||||
export const Geterr: protocol.CommandTypes.Geterr = "geterr";
|
||||
export const GeterrForProject: protocol.CommandTypes.GeterrForProject = "geterrForProject";
|
||||
export const Implementation: protocol.CommandTypes.Implementation = "implementation";
|
||||
/* @internal */
|
||||
export const ImplementationFull: protocol.CommandTypes.ImplementationFull = "implementation-full";
|
||||
export const SemanticDiagnosticsSync: protocol.CommandTypes.SemanticDiagnosticsSync = "semanticDiagnosticsSync";
|
||||
export const SyntacticDiagnosticsSync: protocol.CommandTypes.SyntacticDiagnosticsSync = "syntacticDiagnosticsSync";
|
||||
export const NavBar: protocol.CommandTypes.NavBar = "navbar";
|
||||
/* @internal */
|
||||
export const NavBarFull: protocol.CommandTypes.NavBarFull = "navbar-full";
|
||||
export const NavTree: protocol.CommandTypes.NavTree = "navtree";
|
||||
export const NavTreeFull: protocol.CommandTypes.NavTreeFull = "navtree-full";
|
||||
export const Navto: protocol.CommandTypes.Navto = "navto";
|
||||
/* @internal */
|
||||
export const NavtoFull: protocol.CommandTypes.NavtoFull = "navto-full";
|
||||
export const Occurrences: protocol.CommandTypes.Occurrences = "occurrences";
|
||||
export const DocumentHighlights: protocol.CommandTypes.DocumentHighlights = "documentHighlights";
|
||||
/* @internal */
|
||||
export const DocumentHighlightsFull: protocol.CommandTypes.DocumentHighlightsFull = "documentHighlights-full";
|
||||
export const Open: protocol.CommandTypes.Open = "open";
|
||||
export const Quickinfo: protocol.CommandTypes.Quickinfo = "quickinfo";
|
||||
/* @internal */
|
||||
export const QuickinfoFull: protocol.CommandTypes.QuickinfoFull = "quickinfo-full";
|
||||
export const References: protocol.CommandTypes.References = "references";
|
||||
/* @internal */
|
||||
export const ReferencesFull: protocol.CommandTypes.ReferencesFull = "references-full";
|
||||
export const Reload: protocol.CommandTypes.Reload = "reload";
|
||||
export const Rename: protocol.CommandTypes.Rename = "rename";
|
||||
/* @internal */
|
||||
export const RenameInfoFull: protocol.CommandTypes.RenameInfoFull = "rename-full";
|
||||
/* @internal */
|
||||
export const RenameLocationsFull: protocol.CommandTypes.RenameLocationsFull = "renameLocations-full";
|
||||
export const Saveto: protocol.CommandTypes.Saveto = "saveto";
|
||||
export const SignatureHelp: protocol.CommandTypes.SignatureHelp = "signatureHelp";
|
||||
/* @internal */
|
||||
export const SignatureHelpFull: protocol.CommandTypes.SignatureHelpFull = "signatureHelp-full";
|
||||
export const TypeDefinition: protocol.CommandTypes.TypeDefinition = "typeDefinition";
|
||||
export const ProjectInfo: protocol.CommandTypes.ProjectInfo = "projectInfo";
|
||||
export const ReloadProjects: protocol.CommandTypes.ReloadProjects = "reloadProjects";
|
||||
export const Unknown: protocol.CommandTypes.Unknown = "unknown";
|
||||
export const OpenExternalProject: protocol.CommandTypes.OpenExternalProject = "openExternalProject";
|
||||
export const OpenExternalProjects: protocol.CommandTypes.OpenExternalProjects = "openExternalProjects";
|
||||
export const CloseExternalProject: protocol.CommandTypes.CloseExternalProject = "closeExternalProject";
|
||||
/* @internal */
|
||||
export const SynchronizeProjectList: protocol.CommandTypes.SynchronizeProjectList = "synchronizeProjectList";
|
||||
/* @internal */
|
||||
export const ApplyChangedToOpenFiles: protocol.CommandTypes.ApplyChangedToOpenFiles = "applyChangedToOpenFiles";
|
||||
/* @internal */
|
||||
export const EncodedSemanticClassificationsFull: protocol.CommandTypes.EncodedSemanticClassificationsFull = "encodedSemanticClassifications-full";
|
||||
/* @internal */
|
||||
export const Cleanup: protocol.CommandTypes.Cleanup = "cleanup";
|
||||
/* @internal */
|
||||
export const OutliningSpans: protocol.CommandTypes.OutliningSpans = "outliningSpans";
|
||||
export const TodoComments: protocol.CommandTypes.TodoComments = "todoComments";
|
||||
export const Indentation: protocol.CommandTypes.Indentation = "indentation";
|
||||
export const DocCommentTemplate: protocol.CommandTypes.DocCommentTemplate = "docCommentTemplate";
|
||||
/* @internal */
|
||||
export const CompilerOptionsDiagnosticsFull: protocol.CommandTypes.CompilerOptionsDiagnosticsFull = "compilerOptionsDiagnostics-full";
|
||||
/* @internal */
|
||||
export const NameOrDottedNameSpan: protocol.CommandTypes.NameOrDottedNameSpan = "nameOrDottedNameSpan";
|
||||
/* @internal */
|
||||
export const BreakpointStatement: protocol.CommandTypes.BreakpointStatement = "breakpointStatement";
|
||||
export const CompilerOptionsForInferredProjects: protocol.CommandTypes.CompilerOptionsForInferredProjects = "compilerOptionsForInferredProjects";
|
||||
export const GetCodeFixes: protocol.CommandTypes.GetCodeFixes = "getCodeFixes";
|
||||
/* @internal */
|
||||
export const GetCodeFixesFull: protocol.CommandTypes.GetCodeFixesFull = "getCodeFixes-full";
|
||||
export const GetSupportedCodeFixes: protocol.CommandTypes.GetSupportedCodeFixes = "getSupportedCodeFixes";
|
||||
}
|
||||
export import CommandNames = protocol.CommandTypes;
|
||||
|
||||
export function formatMessage<T extends protocol.Message>(msg: T, logger: server.Logger, byteLength: (s: string, encoding: string) => number, newLine: string): string {
|
||||
const verboseLogging = logger.hasLevel(LogLevel.verbose);
|
||||
@@ -368,6 +275,7 @@ namespace ts.server {
|
||||
|
||||
globalPlugins?: string[];
|
||||
pluginProbeLocations?: string[];
|
||||
allowLocalPluginLoads?: boolean;
|
||||
}
|
||||
|
||||
export class Session implements EventSender {
|
||||
@@ -421,7 +329,8 @@ namespace ts.server {
|
||||
throttleWaitMilliseconds,
|
||||
eventHandler: this.eventHandler,
|
||||
globalPlugins: opts.globalPlugins,
|
||||
pluginProbeLocations: opts.pluginProbeLocations
|
||||
pluginProbeLocations: opts.pluginProbeLocations,
|
||||
allowLocalPluginLoads: opts.allowLocalPluginLoads
|
||||
};
|
||||
this.projectService = new ProjectService(settings);
|
||||
this.gcTimer = new GcTimer(this.host, /*delay*/ 7000, this.logger);
|
||||
@@ -450,7 +359,7 @@ namespace ts.server {
|
||||
break;
|
||||
case ProjectLanguageServiceStateEvent:
|
||||
const eventName: protocol.ProjectLanguageServiceStateEventName = "projectLanguageServiceState";
|
||||
this.event(<protocol.ProjectLanguageServiceStateEventBody>{
|
||||
this.event<protocol.ProjectLanguageServiceStateEventBody>({
|
||||
projectName: event.data.project.getProjectName(),
|
||||
languageServiceEnabled: event.data.languageServiceEnabled
|
||||
}, eventName);
|
||||
@@ -494,7 +403,7 @@ namespace ts.server {
|
||||
this.send(ev);
|
||||
}
|
||||
|
||||
public event(info: any, eventName: string) {
|
||||
public event<T>(info: T, eventName: string) {
|
||||
const ev: protocol.Event = {
|
||||
seq: 0,
|
||||
type: "event",
|
||||
@@ -529,7 +438,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
const bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
|
||||
this.event({ file: file, diagnostics: bakedDiags }, "semanticDiag");
|
||||
this.event<protocol.DiagnosticEventBody>({ file: file, diagnostics: bakedDiags }, "semanticDiag");
|
||||
}
|
||||
catch (err) {
|
||||
this.logError(err, "semantic check");
|
||||
@@ -541,7 +450,7 @@ namespace ts.server {
|
||||
const diags = project.getLanguageService().getSyntacticDiagnostics(file);
|
||||
if (diags) {
|
||||
const bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
|
||||
this.event({ file: file, diagnostics: bakedDiags }, "syntaxDiag");
|
||||
this.event<protocol.DiagnosticEventBody>({ file: file, diagnostics: bakedDiags }, "syntaxDiag");
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
@@ -1440,8 +1349,8 @@ namespace ts.server {
|
||||
return !items
|
||||
? undefined
|
||||
: simplifiedResult
|
||||
? this.decorateNavigationBarItems(items, project.getScriptInfoForNormalizedPath(file))
|
||||
: items;
|
||||
? this.decorateNavigationBarItems(items, project.getScriptInfoForNormalizedPath(file))
|
||||
: items;
|
||||
}
|
||||
|
||||
private decorateNavigationTree(tree: ts.NavigationTree, scriptInfo: ScriptInfo): protocol.NavigationTree {
|
||||
@@ -1467,8 +1376,8 @@ namespace ts.server {
|
||||
return !tree
|
||||
? undefined
|
||||
: simplifiedResult
|
||||
? this.decorateNavigationTree(tree, project.getScriptInfoForNormalizedPath(file))
|
||||
: tree;
|
||||
? this.decorateNavigationTree(tree, project.getScriptInfoForNormalizedPath(file))
|
||||
: tree;
|
||||
}
|
||||
|
||||
private getNavigateToItems(args: protocol.NavtoRequestArgs, simplifiedResult: boolean): protocol.NavtoItem[] | NavigateToItem[] {
|
||||
@@ -1555,6 +1464,60 @@ namespace ts.server {
|
||||
return ts.getSupportedCodeFixes();
|
||||
}
|
||||
|
||||
private isLocation(locationOrSpan: protocol.FileLocationOrRangeRequestArgs): locationOrSpan is protocol.FileLocationRequestArgs {
|
||||
return (<protocol.FileLocationRequestArgs>locationOrSpan).line !== undefined;
|
||||
}
|
||||
|
||||
private extractPositionAndRange(args: protocol.FileLocationOrRangeRequestArgs, scriptInfo: ScriptInfo): { position: number, textRange: TextRange } {
|
||||
let position: number = undefined;
|
||||
let textRange: TextRange;
|
||||
if (this.isLocation(args)) {
|
||||
position = getPosition(args);
|
||||
}
|
||||
else {
|
||||
const { startPosition, endPosition } = this.getStartAndEndPosition(args, scriptInfo);
|
||||
textRange = { pos: startPosition, end: endPosition };
|
||||
}
|
||||
return { position, textRange };
|
||||
|
||||
function getPosition(loc: protocol.FileLocationRequestArgs) {
|
||||
return loc.position !== undefined ? loc.position : scriptInfo.lineOffsetToPosition(loc.line, loc.offset);
|
||||
}
|
||||
}
|
||||
|
||||
private getApplicableRefactors(args: protocol.GetApplicableRefactorsRequestArgs): protocol.ApplicableRefactorInfo[] {
|
||||
const { file, project } = this.getFileAndProjectWithoutRefreshingInferredProjects(args);
|
||||
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
|
||||
const { position, textRange } = this.extractPositionAndRange(args, scriptInfo);
|
||||
return project.getLanguageService().getApplicableRefactors(file, position || textRange);
|
||||
}
|
||||
|
||||
private getRefactorCodeActions(args: protocol.GetRefactorCodeActionsRequestArgs, simplifiedResult: boolean): protocol.RefactorCodeActions | protocol.RefactorCodeActionsFull {
|
||||
const { file, project } = this.getFileAndProjectWithoutRefreshingInferredProjects(args);
|
||||
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
|
||||
const { position, textRange } = this.extractPositionAndRange(args, scriptInfo);
|
||||
|
||||
const result: ts.CodeAction[] = project.getLanguageService().getRefactorCodeActions(
|
||||
file,
|
||||
this.projectService.getFormatCodeOptions(),
|
||||
position || textRange,
|
||||
args.refactorName
|
||||
);
|
||||
|
||||
if (simplifiedResult) {
|
||||
// Not full
|
||||
return {
|
||||
actions: result.map(action => this.mapCodeAction(action, scriptInfo))
|
||||
};
|
||||
}
|
||||
else {
|
||||
// Full
|
||||
return {
|
||||
actions: result
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private getCodeFixes(args: protocol.CodeFixRequestArgs, simplifiedResult: boolean): protocol.CodeAction[] | CodeAction[] {
|
||||
if (args.errorCodes.length === 0) {
|
||||
return undefined;
|
||||
@@ -1562,8 +1525,7 @@ namespace ts.server {
|
||||
const { file, project } = this.getFileAndProjectWithoutRefreshingInferredProjects(args);
|
||||
|
||||
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
|
||||
const startPosition = getStartPosition();
|
||||
const endPosition = getEndPosition();
|
||||
const { startPosition, endPosition } = this.getStartAndEndPosition(args, scriptInfo);
|
||||
const formatOptions = this.projectService.getFormatCodeOptions(file);
|
||||
|
||||
const codeActions = project.getLanguageService().getCodeFixesAtPosition(file, startPosition, endPosition, args.errorCodes, formatOptions);
|
||||
@@ -1576,14 +1538,28 @@ namespace ts.server {
|
||||
else {
|
||||
return codeActions;
|
||||
}
|
||||
}
|
||||
|
||||
function getStartPosition() {
|
||||
return args.startPosition !== undefined ? args.startPosition : scriptInfo.lineOffsetToPosition(args.startLine, args.startOffset);
|
||||
private getStartAndEndPosition(args: protocol.FileRangeRequestArgs, scriptInfo: ScriptInfo) {
|
||||
let startPosition: number = undefined, endPosition: number = undefined;
|
||||
if (args.startPosition !== undefined) {
|
||||
startPosition = args.startPosition;
|
||||
}
|
||||
else {
|
||||
startPosition = scriptInfo.lineOffsetToPosition(args.startLine, args.startOffset);
|
||||
// save the result so we don't always recompute
|
||||
args.startPosition = startPosition;
|
||||
}
|
||||
|
||||
function getEndPosition() {
|
||||
return args.endPosition !== undefined ? args.endPosition : scriptInfo.lineOffsetToPosition(args.endLine, args.endOffset);
|
||||
if (args.endPosition !== undefined) {
|
||||
endPosition = args.endPosition;
|
||||
}
|
||||
else {
|
||||
endPosition = scriptInfo.lineOffsetToPosition(args.endLine, args.endOffset);
|
||||
args.endPosition = endPosition;
|
||||
}
|
||||
|
||||
return { startPosition, endPosition };
|
||||
}
|
||||
|
||||
private mapCodeAction(codeAction: CodeAction, scriptInfo: ScriptInfo): protocol.CodeAction {
|
||||
@@ -1614,8 +1590,8 @@ namespace ts.server {
|
||||
return !spans
|
||||
? undefined
|
||||
: simplifiedResult
|
||||
? spans.map(span => this.decorateSpan(span, scriptInfo))
|
||||
: spans;
|
||||
? spans.map(span => this.decorateSpan(span, scriptInfo))
|
||||
: spans;
|
||||
}
|
||||
|
||||
private getDiagnosticsForProject(next: NextStep, delay: number, fileName: string): void {
|
||||
@@ -1940,6 +1916,15 @@ namespace ts.server {
|
||||
},
|
||||
[CommandNames.GetSupportedCodeFixes]: () => {
|
||||
return this.requiredResponse(this.getSupportedCodeFixes());
|
||||
},
|
||||
[CommandNames.GetApplicableRefactors]: (request: protocol.GetApplicableRefactorsRequest) => {
|
||||
return this.requiredResponse(this.getApplicableRefactors(request.arguments));
|
||||
},
|
||||
[CommandNames.GetRefactorCodeActions]: (request: protocol.GetRefactorCodeActionsRequest) => {
|
||||
return this.requiredResponse(this.getRefactorCodeActions(request.arguments, /*simplifiedResult*/ true));
|
||||
},
|
||||
[CommandNames.GetRefactorCodeActionsFull]: (request: protocol.GetRefactorCodeActionsRequest) => {
|
||||
return this.requiredResponse(this.getRefactorCodeActions(request.arguments, /*simplifiedResult*/ false));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1997,7 +1982,7 @@ namespace ts.server {
|
||||
let request: protocol.Request;
|
||||
try {
|
||||
request = <protocol.Request>JSON.parse(message);
|
||||
const {response, responseRequired} = this.executeCommand(request);
|
||||
const { response, responseRequired } = this.executeCommand(request);
|
||||
|
||||
if (this.logger.hasLevel(LogLevel.requestTime)) {
|
||||
const elapsedTime = hrTimeToMilliseconds(this.hrtime(start)).toFixed(4);
|
||||
|
||||
Reference in New Issue
Block a user