Skip to content

Commit f124e19

Browse files
author
Andy
authored
Session: don't return undefined if a response is required (microsoft#17165)
* Session: don't return undefined if a response is required * Use ReadonlyArray and emptyArray * Remove inferred return type
1 parent b8c37bb commit f124e19

File tree

5 files changed

+48
-46
lines changed

5 files changed

+48
-46
lines changed

src/harness/unittests/projectErrors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace ts.projectSystem {
66
describe("Project errors", () => {
7-
function checkProjectErrors(projectFiles: server.ProjectFilesWithTSDiagnostics, expectedErrors: string[]) {
7+
function checkProjectErrors(projectFiles: server.ProjectFilesWithTSDiagnostics, expectedErrors: ReadonlyArray<string>): void {
88
assert.isTrue(projectFiles !== undefined, "missing project files");
99
checkProjectErrorsWorker(projectFiles.projectErrors, expectedErrors);
1010
}
1111

12-
function checkProjectErrorsWorker(errors: Diagnostic[], expectedErrors: string[]) {
12+
function checkProjectErrorsWorker(errors: ReadonlyArray<Diagnostic>, expectedErrors: ReadonlyArray<string>): void {
1313
assert.equal(errors ? errors.length : 0, expectedErrors.length, `expected ${expectedErrors.length} error in the list`);
1414
if (expectedErrors.length) {
1515
for (let i = 0; i < errors.length; i++) {

src/server/editorServices.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace ts.server {
2222

2323
export interface ConfigFileDiagEvent {
2424
eventName: typeof ConfigFileDiagEvent;
25-
data: { triggerFile: string, configFileName: string, diagnostics: Diagnostic[] };
25+
data: { triggerFile: string, configFileName: string, diagnostics: ReadonlyArray<Diagnostic> };
2626
}
2727

2828
export interface ProjectLanguageServiceStateEvent {
@@ -200,7 +200,7 @@ namespace ts.server {
200200
/**
201201
* This helper function processes a list of projects and return the concatenated, sortd and deduplicated output of processing each project.
202202
*/
203-
export function combineProjectOutput<T>(projects: Project[], action: (project: Project) => T[], comparer?: (a: T, b: T) => number, areEqual?: (a: T, b: T) => boolean) {
203+
export function combineProjectOutput<T>(projects: ReadonlyArray<Project>, action: (project: Project) => ReadonlyArray<T>, comparer?: (a: T, b: T) => number, areEqual?: (a: T, b: T) => boolean) {
204204
const result = flatMap(projects, action).sort(comparer);
205205
return projects.length > 1 ? deduplicate(result, areEqual) : result;
206206
}
@@ -220,14 +220,14 @@ namespace ts.server {
220220

221221
interface OpenConfigFileResult {
222222
success: boolean;
223-
errors?: Diagnostic[];
223+
errors?: ReadonlyArray<Diagnostic>;
224224

225225
project?: ConfiguredProject;
226226
}
227227

228228
export interface OpenConfiguredProjectResult {
229229
configFileName?: NormalizedPath;
230-
configFileErrors?: Diagnostic[];
230+
configFileErrors?: ReadonlyArray<Diagnostic>;
231231
}
232232

233233
interface FilePropertyReader<T> {
@@ -1100,18 +1100,18 @@ namespace ts.server {
11001100
}
11011101
}
11021102

1103-
private reportConfigFileDiagnostics(configFileName: string, diagnostics: Diagnostic[], triggerFile: string) {
1103+
private reportConfigFileDiagnostics(configFileName: string, diagnostics: ReadonlyArray<Diagnostic>, triggerFile: string) {
11041104
if (!this.eventHandler) {
11051105
return;
11061106
}
11071107

11081108
this.eventHandler(<ConfigFileDiagEvent>{
11091109
eventName: ConfigFileDiagEvent,
1110-
data: { configFileName, diagnostics: diagnostics || [], triggerFile }
1110+
data: { configFileName, diagnostics: diagnostics || emptyArray, triggerFile }
11111111
});
11121112
}
11131113

1114-
private createAndAddConfiguredProject(configFileName: NormalizedPath, projectOptions: ProjectOptions, configFileErrors: Diagnostic[], clientFileName?: string) {
1114+
private createAndAddConfiguredProject(configFileName: NormalizedPath, projectOptions: ProjectOptions, configFileErrors: ReadonlyArray<Diagnostic>, clientFileName?: string) {
11151115
const sizeLimitExceeded = this.exceededTotalSizeLimitForNonTsFiles(configFileName, projectOptions.compilerOptions, projectOptions.files, fileNamePropertyReader);
11161116
const project = new ConfiguredProject(
11171117
configFileName,
@@ -1143,7 +1143,7 @@ namespace ts.server {
11431143
}
11441144
}
11451145

1146-
private addFilesToProjectAndUpdateGraph<T>(project: ConfiguredProject | ExternalProject, files: T[], propertyReader: FilePropertyReader<T>, clientFileName: string, typeAcquisition: TypeAcquisition, configFileErrors: Diagnostic[]): void {
1146+
private addFilesToProjectAndUpdateGraph<T>(project: ConfiguredProject | ExternalProject, files: T[], propertyReader: FilePropertyReader<T>, clientFileName: string, typeAcquisition: TypeAcquisition, configFileErrors: ReadonlyArray<Diagnostic>): void {
11471147
let errors: Diagnostic[];
11481148
for (const f of files) {
11491149
const rootFilename = propertyReader.getFileName(f);
@@ -1456,7 +1456,7 @@ namespace ts.server {
14561456

14571457
openClientFileWithNormalizedPath(fileName: NormalizedPath, fileContent?: string, scriptKind?: ScriptKind, hasMixedContent?: boolean, projectRootPath?: NormalizedPath): OpenConfiguredProjectResult {
14581458
let configFileName: NormalizedPath;
1459-
let configFileErrors: Diagnostic[];
1459+
let configFileErrors: ReadonlyArray<Diagnostic>;
14601460

14611461
let project: ConfiguredProject | ExternalProject = this.findContainingExternalProject(fileName);
14621462
if (!project) {

src/server/project.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace ts.server {
5454

5555
/* @internal */
5656
export interface ProjectFilesWithTSDiagnostics extends protocol.ProjectFiles {
57-
projectErrors: Diagnostic[];
57+
projectErrors: ReadonlyArray<Diagnostic>;
5858
}
5959

6060
export class UnresolvedImportsMap {
@@ -147,7 +147,7 @@ namespace ts.server {
147147

148148
private typingFiles: SortedReadonlyArray<string>;
149149

150-
protected projectErrors: Diagnostic[];
150+
protected projectErrors: ReadonlyArray<Diagnostic>;
151151

152152
public typesVersion = 0;
153153

@@ -1045,7 +1045,7 @@ namespace ts.server {
10451045
return getDirectoryPath(this.getConfigFilePath());
10461046
}
10471047

1048-
setProjectErrors(projectErrors: Diagnostic[]) {
1048+
setProjectErrors(projectErrors: ReadonlyArray<Diagnostic>) {
10491049
this.projectErrors = projectErrors;
10501050
}
10511051

@@ -1189,7 +1189,7 @@ namespace ts.server {
11891189
return this.typeAcquisition;
11901190
}
11911191

1192-
setProjectErrors(projectErrors: Diagnostic[]) {
1192+
setProjectErrors(projectErrors: ReadonlyArray<Diagnostic>) {
11931193
this.projectErrors = projectErrors;
11941194
}
11951195

src/server/protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ namespace ts.server.protocol {
914914
/**
915915
* An array of span groups (one per file) that refer to the item to be renamed.
916916
*/
917-
locs: SpanGroup[];
917+
locs: ReadonlyArray<SpanGroup>;
918918
}
919919

920920
/**

0 commit comments

Comments
 (0)