From 04ccc517a93ce4065167225475cec8048648e025 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Mon, 6 Nov 2017 11:50:28 -0800 Subject: [PATCH] Enable strict mode in JS extension --- .../src/features/bowerJSONContribution.ts | 8 +++---- .../src/features/jsonContributions.ts | 23 +++++++++++-------- .../src/features/packageJSONContribution.ts | 8 +++---- extensions/javascript/tsconfig.json | 3 ++- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/extensions/javascript/src/features/bowerJSONContribution.ts b/extensions/javascript/src/features/bowerJSONContribution.ts index c8ecb91aeb3..ffc26905082 100644 --- a/extensions/javascript/src/features/bowerJSONContribution.ts +++ b/extensions/javascript/src/features/bowerJSONContribution.ts @@ -46,7 +46,7 @@ export class BowerJSONContribution implements IJSONContribution { return Promise.resolve(null); } - public collectPropertySuggestions(resource: string, location: Location, currentWord: string, addValue: boolean, isLast: boolean, collector: ISuggestionsCollector): Thenable { + public collectPropertySuggestions(resource: string, location: Location, currentWord: string, addValue: boolean, isLast: boolean, collector: ISuggestionsCollector): Thenable | null { if ((location.matches(['dependencies']) || location.matches(['devDependencies']))) { if (currentWord.length > 0) { let queryUrl = 'https://bower.herokuapp.com/packages/search/' + encodeURIComponent(currentWord); @@ -126,7 +126,7 @@ export class BowerJSONContribution implements IJSONContribution { return Promise.resolve(null); } - public resolveSuggestion(item: CompletionItem): Thenable { + public resolveSuggestion(item: CompletionItem): Thenable | null { if (item.kind === CompletionItemKind.Property && item.documentation === '') { return this.getInfo(item.label).then(documentation => { if (documentation) { @@ -139,7 +139,7 @@ export class BowerJSONContribution implements IJSONContribution { return null; } - private getInfo(pack: string): Thenable { + private getInfo(pack: string): Thenable { let queryUrl = 'https://bower.herokuapp.com/packages/' + encodeURIComponent(pack); return this.xhr({ @@ -166,7 +166,7 @@ export class BowerJSONContribution implements IJSONContribution { }); } - public getInfoContribution(resource: string, location: Location): Thenable { + public getInfoContribution(resource: string, location: Location): Thenable | null { if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']))) { let pack = location.path[location.path.length - 1]; if (typeof pack === 'string') { diff --git a/extensions/javascript/src/features/jsonContributions.ts b/extensions/javascript/src/features/jsonContributions.ts index 6aca3ebd416..1e31adad9d6 100644 --- a/extensions/javascript/src/features/jsonContributions.ts +++ b/extensions/javascript/src/features/jsonContributions.ts @@ -24,11 +24,11 @@ export interface ISuggestionsCollector { export interface IJSONContribution { getDocumentSelector(): DocumentSelector; - getInfoContribution(fileName: string, location: Location): Thenable; - collectPropertySuggestions(fileName: string, location: Location, currentWord: string, addValue: boolean, isLast: boolean, result: ISuggestionsCollector): Thenable; - collectValueSuggestions(fileName: string, location: Location, result: ISuggestionsCollector): Thenable; + getInfoContribution(fileName: string, location: Location): Thenable | null; + collectPropertySuggestions(fileName: string, location: Location, currentWord: string, addValue: boolean, isLast: boolean, result: ISuggestionsCollector): Thenable | null; + collectValueSuggestions(fileName: string, location: Location, result: ISuggestionsCollector): Thenable | null; collectDefaultSuggestions(fileName: string, result: ISuggestionsCollector): Thenable; - resolveSuggestion?(item: CompletionItem): Thenable; + resolveSuggestion?(item: CompletionItem): Thenable | null; } export function addJSONProviders(xhr: XHRRequest): Disposable { @@ -47,18 +47,21 @@ export class JSONHoverProvider implements HoverProvider { constructor(private jsonContribution: IJSONContribution) { } - public provideHover(document: TextDocument, position: Position, token: CancellationToken): Thenable { + public provideHover(document: TextDocument, position: Position, token: CancellationToken): Thenable | null { let fileName = basename(document.fileName); let offset = document.offsetAt(position); let location = getLocation(document.getText(), offset); - let node = location.previousNode; + if (!location.previousNode) { + return null; + } + const node = location.previousNode; if (node && node.offset <= offset && offset <= node.offset + node.length) { let promise = this.jsonContribution.getInfoContribution(fileName, location); if (promise) { return promise.then(htmlContent => { let range = new Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length)); let result: Hover = { - contents: htmlContent, + contents: htmlContent || [], range: range }; return result; @@ -74,7 +77,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider { constructor(private jsonContribution: IJSONContribution) { } - public resolveCompletionItem(item: CompletionItem, token: CancellationToken): Thenable { + public resolveCompletionItem(item: CompletionItem, token: CancellationToken): Thenable { if (this.jsonContribution.resolveSuggestion) { let resolver = this.jsonContribution.resolveSuggestion(item); if (resolver) { @@ -84,7 +87,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider { return Promise.resolve(item); } - public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Thenable { + public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Thenable | null { let fileName = basename(document.fileName); @@ -118,7 +121,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider { log: (message: string) => console.log(message) }; - let collectPromise: Thenable = null; + let collectPromise: Thenable | null = null; if (location.isAtPropertyKey) { let addValue = !location.previousNode || !location.previousNode.columnOffset; diff --git a/extensions/javascript/src/features/packageJSONContribution.ts b/extensions/javascript/src/features/packageJSONContribution.ts index 7da0bf235dd..3f891ee46ee 100644 --- a/extensions/javascript/src/features/packageJSONContribution.ts +++ b/extensions/javascript/src/features/packageJSONContribution.ts @@ -54,7 +54,7 @@ export class PackageJSONContribution implements IJSONContribution { addValue: boolean, isLast: boolean, collector: ISuggestionsCollector - ): Thenable { + ): Thenable | null { if ((location.matches(['dependencies']) || location.matches(['devDependencies']) || location.matches(['optionalDependencies']) || location.matches(['peerDependencies']))) { let queryUrl: string; if (currentWord.length > 0) { @@ -129,7 +129,7 @@ export class PackageJSONContribution implements IJSONContribution { fileName: string, location: Location, result: ISuggestionsCollector - ): Thenable { + ): Thenable | null { if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) { let currentKey = location.path[location.path.length - 1]; if (typeof currentKey === 'string') { @@ -174,7 +174,7 @@ export class PackageJSONContribution implements IJSONContribution { return null; } - public resolveSuggestion(item: CompletionItem): Thenable { + public resolveSuggestion(item: CompletionItem): Thenable | null { if (item.kind === CompletionItemKind.Property && item.documentation === '') { return this.getInfo(item.label).then(infos => { if (infos.length > 0) { @@ -218,7 +218,7 @@ export class PackageJSONContribution implements IJSONContribution { }); } - public getInfoContribution(fileName: string, location: Location): Thenable { + public getInfoContribution(fileName: string, location: Location): Thenable | null { if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) { let pack = location.path[location.path.length - 1]; if (typeof pack === 'string') { diff --git a/extensions/javascript/tsconfig.json b/extensions/javascript/tsconfig.json index 4445bb27fd7..c0601facf73 100644 --- a/extensions/javascript/tsconfig.json +++ b/extensions/javascript/tsconfig.json @@ -5,7 +5,8 @@ "outDir": "./out", "lib": [ "es2015" - ] + ], + "strict": true }, "include": [ "src/**/*" -- GitLab