Merge branch 'master' into referencesPrototypeSourceFile

This commit is contained in:
Sheetal Nandi
2019-09-11 12:27:58 -07:00
368 changed files with 33753 additions and 7149 deletions

View File

@@ -3,7 +3,6 @@ namespace ts.server {
/*@internal*/
export const maxFileSize = 4 * 1024 * 1024;
// tslint:disable variable-name
export const ProjectsUpdatedInBackgroundEvent = "projectsUpdatedInBackground";
export const ProjectLoadingStartEvent = "projectLoadingStart";
export const ProjectLoadingFinishEvent = "projectLoadingFinish";
@@ -12,7 +11,6 @@ namespace ts.server {
export const ProjectLanguageServiceStateEvent = "projectLanguageServiceState";
export const ProjectInfoTelemetryEvent = "projectInfo";
export const OpenFileInfoTelemetryEvent = "openFileInfo";
// tslint:enable variable-name
export interface ProjectsUpdatedInBackgroundEvent {
eventName: typeof ProjectsUpdatedInBackgroundEvent;
@@ -36,7 +34,7 @@ namespace ts.server {
export interface ConfigFileDiagEvent {
eventName: typeof ConfigFileDiagEvent;
data: { triggerFile: string, configFileName: string, diagnostics: ReadonlyArray<Diagnostic> };
data: { triggerFile: string, configFileName: string, diagnostics: readonly Diagnostic[] };
}
export interface ProjectLanguageServiceStateEvent {
@@ -50,24 +48,25 @@ namespace ts.server {
readonly data: ProjectInfoTelemetryEventData;
}
/* __GDPR__
"projectInfo" : {
"${include}": ["${TypeScriptCommonProperties}"],
"projectId": { "classification": "EndUserPseudonymizedInformation", "purpose": "FeatureInsight", "endpoint": "ProjectId" },
"fileStats": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"compilerOptions": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"extends": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"files": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"include": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"exclude": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"compileOnSave": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"typeAcquisition": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"configFileName": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"projectType": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"languageServiceEnabled": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"version": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
/*
* __GDPR__
* "projectInfo" : {
* "${include}": ["${TypeScriptCommonProperties}"],
* "projectId": { "classification": "EndUserPseudonymizedInformation", "purpose": "FeatureInsight", "endpoint": "ProjectId" },
* "fileStats": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
* "compilerOptions": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
* "extends": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
* "files": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
* "include": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
* "exclude": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
* "compileOnSave": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
* "typeAcquisition": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
* "configFileName": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
* "projectType": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
* "languageServiceEnabled": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
* "version": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
* }
*/
export interface ProjectInfoTelemetryEventData {
/** Cryptographically secure hash of project file location. */
readonly projectId: string;
@@ -139,14 +138,15 @@ namespace ts.server {
readonly checkJs: boolean;
}
export type ProjectServiceEvent = LargeFileReferencedEvent |
ProjectsUpdatedInBackgroundEvent |
ProjectLoadingStartEvent |
ProjectLoadingFinishEvent |
ConfigFileDiagEvent |
ProjectLanguageServiceStateEvent |
ProjectInfoTelemetryEvent |
OpenFileInfoTelemetryEvent;
export type ProjectServiceEvent =
LargeFileReferencedEvent
| ProjectsUpdatedInBackgroundEvent
| ProjectLoadingStartEvent
| ProjectLoadingFinishEvent
| ConfigFileDiagEvent
| ProjectLanguageServiceStateEvent
| ProjectInfoTelemetryEvent
| OpenFileInfoTelemetryEvent;
export type ProjectServiceEventHandler = (event: ProjectServiceEvent) => void;
@@ -281,7 +281,7 @@ namespace ts.server {
export interface OpenConfiguredProjectResult {
configFileName?: NormalizedPath;
configFileErrors?: ReadonlyArray<Diagnostic>;
configFileErrors?: readonly Diagnostic[];
}
interface AssignProjectResult extends OpenConfiguredProjectResult {
@@ -375,8 +375,8 @@ namespace ts.server {
eventHandler?: ProjectServiceEventHandler;
suppressDiagnosticEvents?: boolean;
throttleWaitMilliseconds?: number;
globalPlugins?: ReadonlyArray<string>;
pluginProbeLocations?: ReadonlyArray<string>;
globalPlugins?: readonly string[];
pluginProbeLocations?: readonly string[];
allowLocalPluginLoads?: boolean;
typesMapLocation?: string;
syntaxOnly?: boolean;
@@ -519,8 +519,8 @@ namespace ts.server {
private readonly eventHandler?: ProjectServiceEventHandler;
private readonly suppressDiagnosticEvents?: boolean;
public readonly globalPlugins: ReadonlyArray<string>;
public readonly pluginProbeLocations: ReadonlyArray<string>;
public readonly globalPlugins: readonly string[];
public readonly pluginProbeLocations: readonly string[];
public readonly allowLocalPluginLoads: boolean;
private currentPluginConfigOverrides: Map<any> | undefined;
@@ -663,8 +663,7 @@ namespace ts.server {
updateTypingsForProject(response: SetTypings | InvalidateCachedTypings | PackageInstalledResponse): void;
/** @internal */
// tslint:disable-next-line:unified-signatures
updateTypingsForProject(response: SetTypings | InvalidateCachedTypings | PackageInstalledResponse | BeginInstallTypes | EndInstallTypes): void;
updateTypingsForProject(response: SetTypings | InvalidateCachedTypings | PackageInstalledResponse | BeginInstallTypes | EndInstallTypes): void; // eslint-disable-line @typescript-eslint/unified-signatures
updateTypingsForProject(response: SetTypings | InvalidateCachedTypings | PackageInstalledResponse | BeginInstallTypes | EndInstallTypes): void {
const project = this.findProject(response.projectName);
if (!project) {
@@ -778,7 +777,7 @@ namespace ts.server {
this.delayEnsureProjectForOpenFiles();
}
private delayUpdateProjectGraphs(projects: ReadonlyArray<Project>) {
private delayUpdateProjectGraphs(projects: readonly Project[]) {
if (projects.length) {
for (const project of projects) {
this.delayUpdateProjectGraph(project);
@@ -1811,7 +1810,7 @@ namespace ts.server {
}
project.enablePluginsWithOptions(compilerOptions, this.currentPluginConfigOverrides);
const filesToAdd = parsedCommandLine.fileNames.concat(project.getExternalFiles());
this.updateRootAndOptionsOfNonInferredProject(project, filesToAdd, fileNamePropertyReader, compilerOptions, parsedCommandLine.typeAcquisition!, parsedCommandLine.compileOnSave!); // TODO: GH#18217
this.updateRootAndOptionsOfNonInferredProject(project, filesToAdd, fileNamePropertyReader, compilerOptions, parsedCommandLine.typeAcquisition!, parsedCommandLine.compileOnSave);
}
private updateNonInferredProjectFiles<T>(project: ExternalProject | ConfiguredProject, files: T[], propertyReader: FilePropertyReader<T>) {
@@ -2359,7 +2358,7 @@ namespace ts.server {
this.delayUpdateSourceInfoProjects(declarationInfo.sourceMapFilePath.sourceInfos);
declarationInfo.closeSourceMapFileWatcher();
}
},
},
PollingInterval.High,
WatchType.MissingSourceMapFile,
);
@@ -2650,7 +2649,7 @@ namespace ts.server {
private assignProjectToOpenedScriptInfo(info: ScriptInfo): AssignProjectResult {
let configFileName: NormalizedPath | undefined;
let configFileErrors: ReadonlyArray<Diagnostic> | undefined;
let configFileErrors: readonly Diagnostic[] | undefined;
let project: ConfiguredProject | ExternalProject | undefined = this.findExternalProjectContainingOpenScriptInfo(info);
let defaultConfigProject: ConfiguredProject | undefined;
if (!project && !this.syntaxOnly) { // Checking syntaxOnly is an optimization

View File

@@ -75,7 +75,7 @@ namespace ts.server {
/* @internal */
export interface ProjectFilesWithTSDiagnostics extends protocol.ProjectFiles {
projectErrors: ReadonlyArray<Diagnostic>;
projectErrors: readonly Diagnostic[];
}
export interface PluginCreateInfo {
@@ -133,7 +133,7 @@ namespace ts.server {
* Maop does not contain entries for files that do not have unresolved imports
* This helps in containing the set of files to invalidate
*/
cachedUnresolvedImportsPerFile = createMap<ReadonlyArray<string>>();
cachedUnresolvedImportsPerFile = createMap<readonly string[]>();
/*@internal*/
lastCachedUnresolvedImportsList: SortedReadonlyArray<string> | undefined;
@@ -315,7 +315,7 @@ namespace ts.server {
return this.projectStateVersion.toString();
}
getProjectReferences(): ReadonlyArray<ProjectReference> | undefined {
getProjectReferences(): readonly ProjectReference[] | undefined {
return undefined;
}
@@ -383,7 +383,7 @@ namespace ts.server {
return this.projectService.host.useCaseSensitiveFileNames;
}
readDirectory(path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[] {
readDirectory(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[] {
return this.directoryStructureHost.readDirectory!(path, extensions, exclude, include, depth);
}
@@ -507,11 +507,11 @@ namespace ts.server {
/**
* Get the errors that dont have any file name associated
*/
getGlobalProjectErrors(): ReadonlyArray<Diagnostic> {
getGlobalProjectErrors(): readonly Diagnostic[] {
return emptyArray;
}
getAllProjectErrors(): ReadonlyArray<Diagnostic> {
getAllProjectErrors(): readonly Diagnostic[] {
return emptyArray;
}
@@ -727,7 +727,7 @@ namespace ts.server {
});
}
getExcludedFiles(): ReadonlyArray<NormalizedPath> {
getExcludedFiles(): readonly NormalizedPath[] {
return emptyArray;
}
@@ -871,7 +871,7 @@ namespace ts.server {
const hasAddedorRemovedFiles = this.hasAddedorRemovedFiles;
this.hasAddedorRemovedFiles = false;
const changedFiles: ReadonlyArray<Path> = this.resolutionCache.finishRecordingFilesWithChangedResolutions() || emptyArray;
const changedFiles: readonly Path[] = this.resolutionCache.finishRecordingFilesWithChangedResolutions() || emptyArray;
for (const file of changedFiles) {
// delete cached information for changed files
@@ -1313,6 +1313,7 @@ namespace ts.server {
const pluginModule = pluginModuleFactory({ typescript: ts });
const newLS = pluginModule.create(info);
for (const k of Object.keys(this.languageService)) {
// eslint-disable-next-line no-in-operator
if (!(k in newLS)) {
this.projectService.logger.info(`Plugin activation warning: Missing proxied method ${k} in created LS. Patching.`);
(newLS as any)[k] = (this.languageService as any)[k];
@@ -1342,12 +1343,12 @@ namespace ts.server {
}
}
function getUnresolvedImports(program: Program, cachedUnresolvedImportsPerFile: Map<ReadonlyArray<string>>): SortedReadonlyArray<string> {
function getUnresolvedImports(program: Program, cachedUnresolvedImportsPerFile: Map<readonly string[]>): SortedReadonlyArray<string> {
const ambientModules = program.getTypeChecker().getAmbientModules().map(mod => stripQuotes(mod.getName()));
return sortAndDeduplicate(flatMap(program.getSourceFiles(), sourceFile =>
extractUnresolvedImportsFromSourceFile(sourceFile, ambientModules, cachedUnresolvedImportsPerFile)));
}
function extractUnresolvedImportsFromSourceFile(file: SourceFile, ambientModules: ReadonlyArray<string>, cachedUnresolvedImportsPerFile: Map<ReadonlyArray<string>>): ReadonlyArray<string> {
function extractUnresolvedImportsFromSourceFile(file: SourceFile, ambientModules: readonly string[], cachedUnresolvedImportsPerFile: Map<readonly string[]>): readonly string[] {
return getOrUpdate(cachedUnresolvedImportsPerFile, file.path, () => {
if (!file.resolvedModules) return emptyArray;
let unresolvedImports: string[] | undefined;
@@ -1511,7 +1512,7 @@ namespace ts.server {
private projectErrors: Diagnostic[] | undefined;
private projectReferences: ReadonlyArray<ProjectReference> | undefined;
private projectReferences: readonly ProjectReference[] | undefined;
/*@internal*/
projectOptions?: ProjectOptions | true;
@@ -1624,11 +1625,11 @@ namespace ts.server {
return asNormalizedPath(this.getProjectName());
}
getProjectReferences(): ReadonlyArray<ProjectReference> | undefined {
getProjectReferences(): readonly ProjectReference[] | undefined {
return this.projectReferences;
}
updateReferences(refs: ReadonlyArray<ProjectReference> | undefined) {
updateReferences(refs: readonly ProjectReference[] | undefined) {
this.projectReferences = refs;
}
@@ -1676,14 +1677,14 @@ namespace ts.server {
/**
* Get the errors that dont have any file name associated
*/
getGlobalProjectErrors(): ReadonlyArray<Diagnostic> {
getGlobalProjectErrors(): readonly Diagnostic[] {
return filter(this.projectErrors, diagnostic => !diagnostic.file) || emptyArray;
}
/**
* Get all the project errors
*/
getAllProjectErrors(): ReadonlyArray<Diagnostic> {
getAllProjectErrors(): readonly Diagnostic[] {
return this.projectErrors || emptyArray;
}
@@ -1790,7 +1791,7 @@ namespace ts.server {
* These are created only if a host explicitly calls `openExternalProject`.
*/
export class ExternalProject extends Project {
excludedFiles: ReadonlyArray<NormalizedPath> = [];
excludedFiles: readonly NormalizedPath[] = [];
private typeAcquisition!: TypeAcquisition; // TODO: GH#18217
/*@internal*/
constructor(public externalProjectName: string,

View File

@@ -1,4 +1,4 @@
// tslint:disable no-unnecessary-qualifier
/* eslint-disable @typescript-eslint/no-unnecessary-qualifier */
/**
* Declaration module describing the TypeScript Server protocol
@@ -633,7 +633,7 @@ namespace ts.server.protocol {
}
export interface OrganizeImportsResponse extends Response {
body: ReadonlyArray<FileCodeEdits>;
body: readonly FileCodeEdits[];
}
export interface GetEditsForFileRenameRequest extends Request {
@@ -648,7 +648,7 @@ namespace ts.server.protocol {
}
export interface GetEditsForFileRenameResponse extends Response {
body: ReadonlyArray<FileCodeEdits>;
body: readonly FileCodeEdits[];
}
/**
@@ -717,7 +717,7 @@ namespace ts.server.protocol {
/**
* Errorcodes we want to get the fixes for.
*/
errorCodes: ReadonlyArray<number>;
errorCodes: readonly number[];
}
export interface GetCombinedCodeFixRequestArgs {
@@ -907,7 +907,7 @@ namespace ts.server.protocol {
}
export interface DefinitionInfoAndBoundSpan {
definitions: ReadonlyArray<FileSpanWithContext>;
definitions: readonly FileSpanWithContext[];
textSpan: TextSpan;
}
@@ -1067,7 +1067,7 @@ namespace ts.server.protocol {
/**
* The file locations referencing the symbol.
*/
refs: ReadonlyArray<ReferencesResponseItem>;
refs: readonly ReferencesResponseItem[];
/**
* The name of the symbol.
@@ -1125,7 +1125,7 @@ namespace ts.server.protocol {
/* @internal */
export interface RenameFullResponse extends Response {
readonly body: ReadonlyArray<RenameLocation>;
readonly body: readonly RenameLocation[];
}
/**
@@ -1198,7 +1198,7 @@ namespace ts.server.protocol {
/**
* An array of span groups (one per file) that refer to the item to be renamed.
*/
locs: ReadonlyArray<SpanGroup>;
locs: readonly SpanGroup[];
}
/**
@@ -1876,8 +1876,8 @@ namespace ts.server.protocol {
}
export interface CombinedCodeActions {
changes: ReadonlyArray<FileCodeEdits>;
commands?: ReadonlyArray<{}>;
changes: readonly FileCodeEdits[];
commands?: readonly {}[];
}
export interface CodeFixAction extends CodeAction {
@@ -2106,7 +2106,7 @@ namespace ts.server.protocol {
readonly isGlobalCompletion: boolean;
readonly isMemberCompletion: boolean;
readonly isNewIdentifierLocation: boolean;
readonly entries: ReadonlyArray<CompletionEntry>;
readonly entries: readonly CompletionEntry[];
}
export interface CompletionDetailsResponse extends Response {
@@ -2214,9 +2214,9 @@ namespace ts.server.protocol {
export type SignatureHelpTriggerCharacter = "," | "(" | "<";
export type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")";
/**
* Arguments of a signature help request.
*/
/**
* Arguments of a signature help request.
*/
export interface SignatureHelpRequestArgs extends FileLocationRequestArgs {
/**
* Reason why signature help was invoked.
@@ -2612,8 +2612,17 @@ namespace ts.server.protocol {
}
/*@internal*/
export type AnyEvent = RequestCompletedEvent | DiagnosticEvent | ConfigFileDiagnosticEvent | ProjectLanguageServiceStateEvent | TelemetryEvent |
ProjectsUpdatedInBackgroundEvent | ProjectLoadingStartEvent | ProjectLoadingFinishEvent | SurveyReadyEvent | LargeFileReferencedEvent;
export type AnyEvent =
RequestCompletedEvent
| DiagnosticEvent
| ConfigFileDiagnosticEvent
| ProjectLanguageServiceStateEvent
| TelemetryEvent
| ProjectsUpdatedInBackgroundEvent
| ProjectLoadingStartEvent
| ProjectLoadingFinishEvent
| SurveyReadyEvent
| LargeFileReferencedEvent;
/**
* Arguments for reload request.
@@ -2874,14 +2883,15 @@ namespace ts.server.protocol {
payload: TypingsInstalledTelemetryEventPayload;
}
/* __GDPR__
"typingsinstalled" : {
"${include}": ["${TypeScriptCommonProperties}"],
"installedPackages": { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight" },
"installSuccess": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"typingsInstallerVersion": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
/*
* __GDPR__
* "typingsinstalled" : {
* "${include}": ["${TypeScriptCommonProperties}"],
* "installedPackages": { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight" },
* "installSuccess": { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
* "typingsInstallerVersion": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
* }
*/
export interface TypingsInstalledTelemetryEventPayload {
/**
* Comma separated list of installed typing packages
@@ -2919,7 +2929,7 @@ namespace ts.server.protocol {
/**
* list of packages to install
*/
packages: ReadonlyArray<string>;
packages: readonly string[];
}
export interface BeginInstallTypesEventBody extends InstallTypesEventBody {

View File

@@ -597,8 +597,7 @@ namespace ts.server {
*/
lineOffsetToPosition(line: number, offset: number): number;
/*@internal*/
// tslint:disable-next-line:unified-signatures
lineOffsetToPosition(line: number, offset: number, allowEdits?: true): number;
lineOffsetToPosition(line: number, offset: number, allowEdits?: true): number; // eslint-disable-line @typescript-eslint/unified-signatures
lineOffsetToPosition(line: number, offset: number, allowEdits?: true): number {
return this.textStorage.lineOffsetToPosition(line, offset, allowEdits);
}

View File

@@ -363,7 +363,7 @@ namespace ts.server {
}
class LineIndexSnapshot implements IScriptSnapshot {
constructor(readonly version: number, readonly cache: ScriptVersionCache, readonly index: LineIndex, readonly changesSincePreviousVersion: ReadonlyArray<TextChange> = emptyArray) {
constructor(readonly version: number, readonly cache: ScriptVersionCache, readonly index: LineIndex, readonly changesSincePreviousVersion: readonly TextChange[] = emptyArray) {
}
getText(rangeStart: number, rangeEnd: number) {

View File

@@ -113,7 +113,7 @@ namespace ts.server {
project: Project;
}
function allEditsBeforePos(edits: ReadonlyArray<TextChange>, pos: number): boolean {
function allEditsBeforePos(edits: readonly TextChange[], pos: number): boolean {
return edits.every(edit => textSpanEnd(edit.span) < pos);
}
@@ -123,7 +123,7 @@ namespace ts.server {
// we want to ensure the value is maintained in the out since the file is
// built using --preseveConstEnum.
export type CommandNames = protocol.CommandTypes;
export const CommandNames = (<any>protocol).CommandTypes; // tslint:disable-line variable-name
export const CommandNames = (<any>protocol).CommandTypes;
export function formatMessage<T extends protocol.Message>(msg: T, logger: Logger, byteLength: (s: string, encoding: string) => number, newLine: string): string {
const verboseLogging = logger.hasLevel(LogLevel.verbose);
@@ -258,8 +258,8 @@ namespace ts.server {
};
}
type Projects = ReadonlyArray<Project> | {
readonly projects: ReadonlyArray<Project>;
type Projects = readonly Project[] | {
readonly projects: readonly Project[];
readonly symLinkedProjects: MultiMap<Project>;
};
@@ -270,7 +270,7 @@ namespace ts.server {
defaultValue: T,
getValue: (path: Path) => T,
projects: Projects,
action: (project: Project, value: T) => ReadonlyArray<U> | U | undefined,
action: (project: Project, value: T) => readonly U[] | U | undefined,
): U[] {
const outputs = flatMapToMutable(isArray(projects) ? projects : projects.projects, project => action(project, defaultValue));
if (!isArray(projects) && projects.symLinkedProjects) {
@@ -282,7 +282,7 @@ namespace ts.server {
return deduplicate(outputs, equateValues);
}
function combineProjectOutputFromEveryProject<T>(projectService: ProjectService, action: (project: Project) => ReadonlyArray<T>, areEqual: (a: T, b: T) => boolean) {
function combineProjectOutputFromEveryProject<T>(projectService: ProjectService, action: (project: Project) => readonly T[], areEqual: (a: T, b: T) => boolean) {
const outputs: T[] = [];
projectService.forEachEnabledProject(project => {
const theseOutputs = action(project);
@@ -294,7 +294,7 @@ namespace ts.server {
function combineProjectOutputWhileOpeningReferencedProjects<T>(
projects: Projects,
defaultProject: Project,
action: (project: Project) => ReadonlyArray<T>,
action: (project: Project) => readonly T[],
getLocation: (t: T) => DocumentPosition,
resultsEqual: (a: T, b: T) => boolean,
): T[] {
@@ -321,7 +321,7 @@ namespace ts.server {
findInStrings: boolean,
findInComments: boolean,
hostPreferences: UserPreferences
): ReadonlyArray<RenameLocation> {
): readonly RenameLocation[] {
const outputs: RenameLocation[] = [];
combineProjectOutputWorker<DocumentPosition>(
@@ -329,7 +329,7 @@ namespace ts.server {
defaultProject,
initialLocation,
({ project, location }, tryAddToTodo) => {
for (const output of project.getLanguageService().findRenameLocations(location.fileName, location.pos, findInStrings, findInComments, hostPreferences.providePrefixAndSuffixTextForRename) || emptyArray) {
for (const output of project.getLanguageService().findRenameLocations(location.fileName, location.pos, findInStrings, findInComments, hostPreferences.providePrefixAndSuffixTextForRename) || emptyArray) {
if (!contains(outputs, output, documentSpansEqual) && !tryAddToTodo(project, documentSpanLocation(output))) {
outputs.push(output);
}
@@ -351,7 +351,7 @@ namespace ts.server {
projects: Projects,
defaultProject: Project,
initialLocation: DocumentPosition
): ReadonlyArray<ReferencedSymbol> {
): readonly ReferencedSymbol[] {
const outputs: ReferencedSymbol[] = [];
combineProjectOutputWorker<DocumentPosition>(
@@ -547,8 +547,8 @@ namespace ts.server {
throttleWaitMilliseconds?: number;
noGetErrOnBackgroundUpdate?: boolean;
globalPlugins?: ReadonlyArray<string>;
pluginProbeLocations?: ReadonlyArray<string>;
globalPlugins?: readonly string[];
pluginProbeLocations?: readonly string[];
allowLocalPluginLoads?: boolean;
typesMapLocation?: string;
}
@@ -710,7 +710,7 @@ namespace ts.server {
msg += `\n\nFile text of ${fileRequest.file}:${indent(text)}\n`;
}
}
catch { } // tslint:disable-line no-empty
catch { } // eslint-disable-line no-empty
}
@@ -767,8 +767,8 @@ namespace ts.server {
let metadata: unknown;
if (isArray(info)) {
res.body = info;
metadata = (info as WithMetadata<ReadonlyArray<any>>).metadata;
delete (info as WithMetadata<ReadonlyArray<any>>).metadata;
metadata = (info as WithMetadata<readonly any[]>).metadata;
delete (info as WithMetadata<readonly any[]>).metadata;
}
else if (typeof info === "object") {
if ((info as WithMetadata<{}>).metadata) {
@@ -809,7 +809,7 @@ namespace ts.server {
this.sendDiagnosticsEvent(file, project, project.getLanguageService().getSuggestionDiagnostics(file), "suggestionDiag");
}
private sendDiagnosticsEvent(file: NormalizedPath, project: Project, diagnostics: ReadonlyArray<Diagnostic>, kind: protocol.DiagnosticEventKind): void {
private sendDiagnosticsEvent(file: NormalizedPath, project: Project, diagnostics: readonly Diagnostic[], kind: protocol.DiagnosticEventKind): void {
try {
this.event<protocol.DiagnosticEventBody>({ file, diagnostics: diagnostics.map(diag => formatDiag(file, project, diag)) }, kind);
}
@@ -931,7 +931,7 @@ namespace ts.server {
);
}
private convertToDiagnosticsWithLinePositionFromDiagnosticFile(diagnostics: ReadonlyArray<Diagnostic>): protocol.DiagnosticWithLinePosition[] {
private convertToDiagnosticsWithLinePositionFromDiagnosticFile(diagnostics: readonly Diagnostic[]): protocol.DiagnosticWithLinePosition[] {
return diagnostics.map<protocol.DiagnosticWithLinePosition>(d => ({
message: flattenDiagnosticMessageText(d.messageText, this.host.newLine),
start: d.start!, // TODO: GH#18217
@@ -958,7 +958,7 @@ namespace ts.server {
);
}
private convertToDiagnosticsWithLinePosition(diagnostics: ReadonlyArray<Diagnostic>, scriptInfo: ScriptInfo | undefined): protocol.DiagnosticWithLinePosition[] {
private convertToDiagnosticsWithLinePosition(diagnostics: readonly Diagnostic[], scriptInfo: ScriptInfo | undefined): protocol.DiagnosticWithLinePosition[] {
return diagnostics.map(d => <protocol.DiagnosticWithLinePosition>{
message: flattenDiagnosticMessageText(d.messageText, this.host.newLine),
start: d.start,
@@ -974,8 +974,8 @@ namespace ts.server {
}
private getDiagnosticsWorker(
args: protocol.FileRequestArgs, isSemantic: boolean, selector: (project: Project, file: string) => ReadonlyArray<Diagnostic>, includeLinePosition: boolean
): ReadonlyArray<protocol.DiagnosticWithLinePosition> | ReadonlyArray<protocol.Diagnostic> {
args: protocol.FileRequestArgs, isSemantic: boolean, selector: (project: Project, file: string) => readonly Diagnostic[], includeLinePosition: boolean
): readonly protocol.DiagnosticWithLinePosition[] | readonly protocol.Diagnostic[] {
const { project, file } = this.getFileAndProject(args);
if (isSemantic && isDeclarationFileInJSOnlyNonConfiguredProject(project, file)) {
return emptyArray;
@@ -987,14 +987,14 @@ namespace ts.server {
: diagnostics.map(d => formatDiag(file, project, d));
}
private getDefinition(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.FileSpanWithContext> | ReadonlyArray<DefinitionInfo> {
private getDefinition(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): readonly protocol.FileSpanWithContext[] | readonly DefinitionInfo[] {
const { file, project } = this.getFileAndProject(args);
const position = this.getPositionInFile(args, file);
const definitions = this.mapDefinitionInfoLocations(project.getLanguageService().getDefinitionAtPosition(file, position) || emptyArray, project);
return simplifiedResult ? this.mapDefinitionInfo(definitions, project) : definitions.map(Session.mapToOriginalLocation);
}
private mapDefinitionInfoLocations(definitions: ReadonlyArray<DefinitionInfo>, project: Project): ReadonlyArray<DefinitionInfo> {
private mapDefinitionInfoLocations(definitions: readonly DefinitionInfo[], project: Project): readonly DefinitionInfo[] {
return definitions.map((info): DefinitionInfo => {
const newDocumentSpan = getMappedDocumentSpan(info, project);
return !newDocumentSpan ? info : {
@@ -1044,7 +1044,7 @@ namespace ts.server {
{ emitSkipped: true, outputFiles: [] };
}
private mapDefinitionInfo(definitions: ReadonlyArray<DefinitionInfo>, project: Project): ReadonlyArray<protocol.FileSpanWithContext> {
private mapDefinitionInfo(definitions: readonly DefinitionInfo[], project: Project): readonly protocol.FileSpanWithContext[] {
return definitions.map(def => this.toFileSpanWithContext(def.fileName, def.textSpan, def.contextSpan, project));
}
@@ -1091,7 +1091,7 @@ namespace ts.server {
fileSpan;
}
private getTypeDefinition(args: protocol.FileLocationRequestArgs): ReadonlyArray<protocol.FileSpanWithContext> {
private getTypeDefinition(args: protocol.FileLocationRequestArgs): readonly protocol.FileSpanWithContext[] {
const { file, project } = this.getFileAndProject(args);
const position = this.getPositionInFile(args, file);
@@ -1099,7 +1099,7 @@ namespace ts.server {
return this.mapDefinitionInfo(definitions, project);
}
private mapImplementationLocations(implementations: ReadonlyArray<ImplementationLocation>, project: Project): ReadonlyArray<ImplementationLocation> {
private mapImplementationLocations(implementations: readonly ImplementationLocation[], project: Project): readonly ImplementationLocation[] {
return implementations.map((info): ImplementationLocation => {
const newDocumentSpan = getMappedDocumentSpan(info, project);
return !newDocumentSpan ? info : {
@@ -1110,7 +1110,7 @@ namespace ts.server {
});
}
private getImplementation(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.FileSpanWithContext> | ReadonlyArray<ImplementationLocation> {
private getImplementation(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): readonly protocol.FileSpanWithContext[] | readonly ImplementationLocation[] {
const { file, project } = this.getFileAndProject(args);
const position = this.getPositionInFile(args, file);
const implementations = this.mapImplementationLocations(project.getLanguageService().getImplementationAtPosition(file, position) || emptyArray, project);
@@ -1119,7 +1119,7 @@ namespace ts.server {
implementations.map(Session.mapToOriginalLocation);
}
private getOccurrences(args: protocol.FileLocationRequestArgs): ReadonlyArray<protocol.OccurrencesResponseItem> {
private getOccurrences(args: protocol.FileLocationRequestArgs): readonly protocol.OccurrencesResponseItem[] {
const { file, project } = this.getFileAndProject(args);
const position = this.getPositionInFile(args, file);
const occurrences = project.getLanguageService().getOccurrencesAtPosition(file, position);
@@ -1137,7 +1137,7 @@ namespace ts.server {
emptyArray;
}
private getSyntacticDiagnosticsSync(args: protocol.SyntacticDiagnosticsSyncRequestArgs): ReadonlyArray<protocol.Diagnostic> | ReadonlyArray<protocol.DiagnosticWithLinePosition> {
private getSyntacticDiagnosticsSync(args: protocol.SyntacticDiagnosticsSyncRequestArgs): readonly protocol.Diagnostic[] | readonly protocol.DiagnosticWithLinePosition[] {
const { configFile } = this.getConfigFileAndProject(args);
if (configFile) {
// all the config file errors are reported as part of semantic check so nothing to report here
@@ -1147,7 +1147,7 @@ namespace ts.server {
return this.getDiagnosticsWorker(args, /*isSemantic*/ false, (project, file) => project.getLanguageService().getSyntacticDiagnostics(file), !!args.includeLinePosition);
}
private getSemanticDiagnosticsSync(args: protocol.SemanticDiagnosticsSyncRequestArgs): ReadonlyArray<protocol.Diagnostic> | ReadonlyArray<protocol.DiagnosticWithLinePosition> {
private getSemanticDiagnosticsSync(args: protocol.SemanticDiagnosticsSyncRequestArgs): readonly protocol.Diagnostic[] | readonly protocol.DiagnosticWithLinePosition[] {
const { configFile, project } = this.getConfigFileAndProject(args);
if (configFile) {
return this.getConfigFileDiagnostics(configFile, project!, !!args.includeLinePosition); // TODO: GH#18217
@@ -1155,7 +1155,7 @@ namespace ts.server {
return this.getDiagnosticsWorker(args, /*isSemantic*/ true, (project, file) => project.getLanguageService().getSemanticDiagnostics(file), !!args.includeLinePosition);
}
private getSuggestionDiagnosticsSync(args: protocol.SuggestionDiagnosticsSyncRequestArgs): ReadonlyArray<protocol.Diagnostic> | ReadonlyArray<protocol.DiagnosticWithLinePosition> {
private getSuggestionDiagnosticsSync(args: protocol.SuggestionDiagnosticsSyncRequestArgs): readonly protocol.Diagnostic[] | readonly protocol.DiagnosticWithLinePosition[] {
const { configFile } = this.getConfigFileAndProject(args);
if (configFile) {
// Currently there are no info diagnostics for config files.
@@ -1172,7 +1172,7 @@ namespace ts.server {
return tag === undefined ? undefined : { newText: tag.newText, caretOffset: 0 };
}
private getDocumentHighlights(args: protocol.DocumentHighlightsRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.DocumentHighlightsItem> | ReadonlyArray<DocumentHighlights> {
private getDocumentHighlights(args: protocol.DocumentHighlightsRequestArgs, simplifiedResult: boolean): readonly protocol.DocumentHighlightsItem[] | readonly DocumentHighlights[] {
const { file, project } = this.getFileAndProject(args);
const position = this.getPositionInFile(args, file);
const documentHighlights = project.getLanguageService().getDocumentHighlights(file, position, args.filesToSearch);
@@ -1218,7 +1218,7 @@ namespace ts.server {
}
private getProjects(args: protocol.FileRequestArgs, getScriptInfoEnsuringProjectsUptoDate?: boolean, ignoreNoProjectError?: boolean): Projects {
let projects: ReadonlyArray<Project> | undefined;
let projects: readonly Project[] | undefined;
let symLinkedProjects: MultiMap<Project> | undefined;
if (args.projectFileName) {
const project = this.getProject(args.projectFileName);
@@ -1258,7 +1258,7 @@ namespace ts.server {
return info.getDefaultProject();
}
private getRenameLocations(args: protocol.RenameRequestArgs, simplifiedResult: boolean): protocol.RenameResponseBody | ReadonlyArray<RenameLocation> {
private getRenameLocations(args: protocol.RenameRequestArgs, simplifiedResult: boolean): protocol.RenameResponseBody | readonly RenameLocation[] {
const file = toNormalizedPath(args.file);
const position = this.getPositionInFile(args, file);
const projects = this.getProjects(args);
@@ -1289,7 +1289,7 @@ namespace ts.server {
}
}
private toSpanGroups(locations: ReadonlyArray<RenameLocation>): ReadonlyArray<protocol.SpanGroup> {
private toSpanGroups(locations: readonly RenameLocation[]): readonly protocol.SpanGroup[] {
const map = createMap<protocol.SpanGroup>();
for (const { fileName, textSpan, contextSpan, originalContextSpan: _2, originalTextSpan: _, originalFileName: _1, ...prefixSuffixText } of locations) {
let group = map.get(fileName);
@@ -1300,7 +1300,7 @@ namespace ts.server {
return arrayFrom(map.values());
}
private getReferences(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.ReferencesResponseBody | undefined | ReadonlyArray<ReferencedSymbol> {
private getReferences(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.ReferencesResponseBody | undefined | readonly ReferencedSymbol[] {
const file = toNormalizedPath(args.file);
const projects = this.getProjects(args);
const position = this.getPositionInFile(args, file);
@@ -1319,7 +1319,7 @@ namespace ts.server {
const nameSpan = nameInfo && nameInfo.textSpan;
const symbolStartOffset = nameSpan ? scriptInfo.positionToLineOffset(nameSpan.start).offset : 0;
const symbolName = nameSpan ? scriptInfo.getSnapshot().getText(nameSpan.start, textSpanEnd(nameSpan)) : "";
const refs: ReadonlyArray<protocol.ReferencesResponseItem> = flatMap(references, referencedSymbol =>
const refs: readonly protocol.ReferencesResponseItem[] = flatMap(references, referencedSymbol =>
referencedSymbol.references.map(({ fileName, textSpan, contextSpan, isWriteAccess, isDefinition }): protocol.ReferencesResponseItem => {
const scriptInfo = Debug.assertDefined(this.projectService.getScriptInfo(fileName));
const span = toProtocolTextSpanWithContext(textSpan, contextSpan, scriptInfo);
@@ -1553,7 +1553,7 @@ namespace ts.server {
});
}
private getCompletions(args: protocol.CompletionsRequestArgs, kind: protocol.CommandTypes.CompletionInfo | protocol.CommandTypes.Completions | protocol.CommandTypes.CompletionsFull): WithMetadata<ReadonlyArray<protocol.CompletionEntry>> | protocol.CompletionInfo | CompletionInfo | undefined {
private getCompletions(args: protocol.CompletionsRequestArgs, kind: protocol.CommandTypes.CompletionInfo | protocol.CommandTypes.Completions | protocol.CommandTypes.CompletionsFull): WithMetadata<readonly protocol.CompletionEntry[]> | protocol.CompletionInfo | CompletionInfo | undefined {
const { file, project } = this.getFileAndProject(args);
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!;
const position = this.getPosition(args, scriptInfo);
@@ -1579,7 +1579,7 @@ namespace ts.server {
}).sort((a, b) => compareStringsCaseSensitiveUI(a.name, b.name));
if (kind === protocol.CommandTypes.Completions) {
if (completions.metadata) (entries as WithMetadata<ReadonlyArray<protocol.CompletionEntry>>).metadata = completions.metadata;
if (completions.metadata) (entries as WithMetadata<readonly protocol.CompletionEntry[]>).metadata = completions.metadata;
return entries;
}
@@ -1590,7 +1590,7 @@ namespace ts.server {
return res;
}
private getCompletionEntryDetails(args: protocol.CompletionDetailsRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.CompletionEntryDetails> | ReadonlyArray<CompletionEntryDetails> {
private getCompletionEntryDetails(args: protocol.CompletionDetailsRequestArgs, simplifiedResult: boolean): readonly protocol.CompletionEntryDetails[] | readonly CompletionEntryDetails[] {
const { file, project } = this.getFileAndProject(args);
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!;
const position = this.getPosition(args, scriptInfo);
@@ -1605,7 +1605,7 @@ namespace ts.server {
: result;
}
private getCompileOnSaveAffectedFileList(args: protocol.FileRequestArgs): ReadonlyArray<protocol.CompileOnSaveAffectedFileListSingleProject> {
private getCompileOnSaveAffectedFileList(args: protocol.FileRequestArgs): readonly protocol.CompileOnSaveAffectedFileListSingleProject[] {
const projects = this.getProjects(args, /*getScriptInfoEnsuringProjectsUptoDate*/ true, /*ignoreNoProjectError*/ true);
const info = this.projectService.getScriptInfo(args.file);
if (!info) {
@@ -1779,7 +1779,7 @@ namespace ts.server {
: tree;
}
private getNavigateToItems(args: protocol.NavtoRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.NavtoItem> | ReadonlyArray<NavigateToItem> {
private getNavigateToItems(args: protocol.NavtoRequestArgs, simplifiedResult: boolean): readonly protocol.NavtoItem[] | readonly NavigateToItem[] {
const full = this.getFullNavigateToItems(args);
return !simplifiedResult ? full : full.map((navItem) => {
const { file, project } = this.getFileAndProject({ file: navItem.fileName });
@@ -1806,7 +1806,7 @@ namespace ts.server {
});
}
private getFullNavigateToItems(args: protocol.NavtoRequestArgs): ReadonlyArray<NavigateToItem> {
private getFullNavigateToItems(args: protocol.NavtoRequestArgs): readonly NavigateToItem[] {
const { currentFileOnly, searchValue, maxResultCount } = args;
if (currentFileOnly) {
const { file, project } = this.getFileAndProject(args);
@@ -1905,7 +1905,7 @@ namespace ts.server {
}
}
private organizeImports({ scope }: protocol.OrganizeImportsRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.FileCodeEdits> | ReadonlyArray<FileTextChanges> {
private organizeImports({ scope }: protocol.OrganizeImportsRequestArgs, simplifiedResult: boolean): readonly protocol.FileCodeEdits[] | readonly FileTextChanges[] {
Debug.assert(scope.type === "file");
const { file, project } = this.getFileAndProject(scope.args);
const changes = project.getLanguageService().organizeImports({ type: "file", fileName: file }, this.getFormatOptions(file), this.getPreferences(file));
@@ -1917,7 +1917,7 @@ namespace ts.server {
}
}
private getEditsForFileRename(args: protocol.GetEditsForFileRenameRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.FileCodeEdits> | ReadonlyArray<FileTextChanges> {
private getEditsForFileRename(args: protocol.GetEditsForFileRenameRequestArgs, simplifiedResult: boolean): readonly protocol.FileCodeEdits[] | readonly FileTextChanges[] {
const oldPath = toNormalizedPath(args.oldFilePath);
const newPath = toNormalizedPath(args.newFilePath);
const formatOptions = this.getHostFormatOptions();
@@ -1929,7 +1929,7 @@ namespace ts.server {
return simplifiedResult ? changes.map(c => this.mapTextChangeToCodeEdit(c)) : changes;
}
private getCodeFixes(args: protocol.CodeFixRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.CodeFixAction> | ReadonlyArray<CodeFixAction> | undefined {
private getCodeFixes(args: protocol.CodeFixRequestArgs, simplifiedResult: boolean): readonly protocol.CodeFixAction[] | readonly CodeFixAction[] | undefined {
const { file, project } = this.getFileAndProject(args);
const scriptInfo = project.getScriptInfoForNormalizedPath(file)!;
@@ -1992,7 +1992,7 @@ namespace ts.server {
return { fixName, description, changes: this.mapTextChangesToCodeEdits(changes), commands, fixId, fixAllDescription };
}
private mapTextChangesToCodeEdits(textChanges: ReadonlyArray<FileTextChanges>): protocol.FileCodeEdits[] {
private mapTextChangesToCodeEdits(textChanges: readonly FileTextChanges[]): protocol.FileCodeEdits[] {
return textChanges.map(change => this.mapTextChangeToCodeEdit(change));
}
@@ -2634,13 +2634,13 @@ namespace ts.server {
}
/* @internal */ // Exported only for tests
export function getLocationInNewDocument(oldText: string, renameFilename: string, renameLocation: number, edits: ReadonlyArray<FileTextChanges>): protocol.Location {
export function getLocationInNewDocument(oldText: string, renameFilename: string, renameLocation: number, edits: readonly FileTextChanges[]): protocol.Location {
const newText = applyEdits(oldText, renameFilename, edits);
const { line, character } = computeLineAndCharacterOfPosition(computeLineStarts(newText), renameLocation);
return { line: line + 1, offset: character + 1 };
}
function applyEdits(text: string, textFilename: string, edits: ReadonlyArray<FileTextChanges>): string {
function applyEdits(text: string, textFilename: string, edits: readonly FileTextChanges[]): string {
for (const { fileName, textChanges } of edits) {
if (fileName !== textFilename) {
continue;

View File

@@ -4,7 +4,8 @@ namespace ts.server {
projectRootPath: Path;
}
// tslint:disable-next-line interface-name (for backwards-compatibility)
// for backwards-compatibility
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface ITypingsInstaller {
isKnownTypesPackageName(name: string): boolean;
installPackage(options: InstallPackageOptionsWithProject): Promise<ApplyCodeActionCommandResult>;