Skip to content

Commit e4c45bf

Browse files
committed
satisfy stricter compiler constraints
1 parent 753f364 commit e4c45bf

12 files changed

+275
-343
lines changed

src/connection.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,25 @@ import {
33
createConnection,
44
InitializeParams,
55
InitializeResult,
6-
TextDocuments,
76
TextDocumentPositionParams,
8-
TextDocumentSyncKind,
97
Definition,
108
ReferenceParams,
119
Location,
1210
Hover,
13-
WorkspaceSymbolParams,
1411
DocumentSymbolParams,
1512
SymbolInformation,
16-
RequestType,
17-
Range,
1813
DidOpenTextDocumentParams,
1914
DidCloseTextDocumentParams,
2015
DidChangeTextDocumentParams,
2116
DidSaveTextDocumentParams
2217
} from 'vscode-languageserver';
2318

24-
import * as ts from 'typescript';
25-
import * as types from 'vscode-languageserver-types';
26-
2719
import * as util from './util';
28-
import { TypeScriptService } from './typescript-service';
29-
import { LanguageHandler } from './lang-handler';
3020
import * as fs from './fs';
31-
3221
import * as rt from './request-type';
3322

23+
import { LanguageHandler } from './lang-handler';
24+
3425
export function newConnection(input: any, output: any): IConnection {
3526
const connection = createConnection(input, output);
3627
input.removeAllListeners('end');
@@ -141,7 +132,7 @@ export function registerLanguageHandler(connection: IConnection, strict: boolean
141132
return Promise.resolve(result || { contents: [] });
142133
} catch (e) {
143134
console.error(params, e);
144-
Promise.reject(e);
135+
return Promise.reject(e);
145136
}
146137
});
147138

src/fs.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export interface FileInfo {
1212
}
1313

1414
export interface FileSystem {
15-
readDir(path: string, callback: (err: Error, result?: FileInfo[]) => void)
16-
readFile(path: string, callback: (err: Error, result?: string) => void)
15+
readDir(path: string, callback: (err: Error, result?: FileInfo[]) => void): void
16+
readFile(path: string, callback: (err: Error, result?: string) => void): void
1717
}
1818

1919
namespace ReadDirRequest {
@@ -32,20 +32,16 @@ export class RemoteFileSystem implements FileSystem {
3232
this.connection = connection
3333
}
3434

35-
readDir(path: string, callback: (err: Error, result?: FileInfo[]) => void) {
35+
readDir(path: string, callback: (err: Error | null, result?: FileInfo[]) => void) {
3636
this.connection.sendRequest(ReadDirRequest.type, path).then((f: FileInfo[]) => {
3737
return callback(null, f)
38-
}, (err: Error) => {
39-
return callback(err)
40-
})
38+
}, callback)
4139
}
4240

43-
readFile(path: string, callback: (err: Error, result?: string) => void) {
41+
readFile(path: string, callback: (err: Error | null, result?: string) => void) {
4442
this.connection.sendRequest(ReadFileRequest.type, path).then((content: string) => {
4543
return callback(null, Buffer.from(content, 'base64').toString())
46-
}, (err: Error) => {
47-
return callback(err)
48-
})
44+
}, callback)
4945
}
5046

5147
}
@@ -58,7 +54,7 @@ export class LocalFileSystem implements FileSystem {
5854
this.root = root
5955
}
6056

61-
readDir(path: string, callback: (err: Error, result?: FileInfo[]) => void) {
57+
readDir(path: string, callback: (err: Error | null, result?: FileInfo[]) => void): void {
6258
path = path_.resolve(this.root, path);
6359
fs.readdir(path, (err: Error, files: string[]) => {
6460
if (err) {
@@ -77,7 +73,7 @@ export class LocalFileSystem implements FileSystem {
7773
});
7874
}
7975

80-
readFile(path: string, callback: (err: Error, result?: string) => void) {
76+
readFile(path: string, callback: (err: Error | null, result?: string) => void): void {
8177
path = path_.resolve(this.root, path);
8278
fs.readFile(path, (err: Error, buf: Buffer) => {
8379
if (err) {

src/lang-handler.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
import {
2-
IConnection,
3-
createConnection,
42
InitializeParams,
53
InitializeResult,
6-
TextDocuments,
74
TextDocumentPositionParams,
8-
TextDocumentSyncKind,
9-
Definition,
105
ReferenceParams,
11-
Position,
126
Location,
137
Hover,
14-
WorkspaceSymbolParams,
158
DocumentSymbolParams,
169
SymbolInformation,
17-
RequestType,
18-
Range,
1910
DidOpenTextDocumentParams,
2011
DidCloseTextDocumentParams,
2112
DidChangeTextDocumentParams,
@@ -41,10 +32,10 @@ export interface LanguageHandler {
4132
getWorkspaceSymbols(params: rt.WorkspaceSymbolParamsWithLimit): Promise<SymbolInformation[]>;
4233
getDocumentSymbol(params: DocumentSymbolParams): Promise<SymbolInformation[]>;
4334
getWorkspaceReference(params: rt.WorkspaceReferenceParams): Promise<rt.ReferenceInformation[]>;
44-
didOpen(params: DidOpenTextDocumentParams);
45-
didChange(params: DidChangeTextDocumentParams);
46-
didClose(params: DidCloseTextDocumentParams);
47-
didSave(params: DidSaveTextDocumentParams);
35+
didOpen(params: DidOpenTextDocumentParams): Promise<void>;
36+
didChange(params: DidChangeTextDocumentParams): Promise<void>;
37+
didClose(params: DidCloseTextDocumentParams): Promise<void>;
38+
didSave(params: DidSaveTextDocumentParams): Promise<void>;
4839
}
4940

5041

src/language-server-stdio.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
var fs = require('fs');
2-
var path = require('path');
3-
var os = require('os');
4-
5-
var program = require('commander');
6-
71
import { newConnection, registerLanguageHandler } from './connection';
82
import { TypeScriptService } from './typescript-service';
93
import * as util from './util';
104

11-
process.on('uncaughtException', (err) => {
5+
var program = require('commander');
6+
7+
process.on('uncaughtException', (err: string) => {
128
console.error(err);
139
});
1410

src/language-server.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
/// <reference path="../node_modules/vscode/thenable.d.ts" />
22

33
import * as net from 'net';
4-
import * as fs from 'fs';
5-
import * as path from 'path';
6-
import * as os from 'os';
74
import * as cluster from 'cluster';
85

96
import { newConnection, registerLanguageHandler } from './connection';
@@ -12,7 +9,7 @@ import * as util from './util';
129

1310
const program = require('commander');
1411

15-
process.on('uncaughtException', (err) => {
12+
process.on('uncaughtException', (err: string) => {
1613
console.error(err);
1714
});
1815

src/match-files.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ function getFileMatcherPatterns(path: string, extensions: string[], excludes: st
8484
const absolutePath = combinePaths(currentDirectory, path);
8585

8686
return {
87-
includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath, "files"),
88-
includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath, "directories"),
89-
excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, "exclude"),
90-
basePaths: getBasePaths(path, includes, useCaseSensitiveFileNames)
87+
includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath, "files") || "",
88+
includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath, "directories") || "",
89+
excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, "exclude") || "",
90+
basePaths: getBasePaths(path, includes, useCaseSensitiveFileNames) || [],
9191
};
9292
}
9393

@@ -105,10 +105,6 @@ function fileExtensionIsAny(path: string, extensions: string[]): boolean {
105105
return false;
106106
}
107107

108-
function normalizeSlashes(path: string): string {
109-
return path.replace(/\\/g, "/");
110-
}
111-
112108
function getRegularExpressionForWildcard(specs: string[], basePath: string, usage: "files" | "directories" | "exclude") {
113109
if (specs === undefined || specs.length === 0) {
114110
return undefined;
@@ -385,7 +381,7 @@ function removeTrailingDirectorySeparator(path: string) {
385381
return path;
386382
}
387383

388-
function lastOrUndefined<T>(array: T[]): T {
384+
function lastOrUndefined<T>(array: T[]): T | void {
389385
return array && array.length > 0
390386
? array[array.length - 1]
391387
: undefined;
@@ -573,3 +569,7 @@ function contains<T>(array: T[], value: T): boolean {
573569
}
574570
return false;
575571
}
572+
573+
function normalizeSlashes(path: string): string {
574+
return path.replace(/\\/g, "/");
575+
}

0 commit comments

Comments
 (0)