mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-04 15:25:47 +01:00
Enable strict mode in JS extension
This commit is contained in:
@@ -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<any> {
|
||||
public collectPropertySuggestions(resource: string, location: Location, currentWord: string, addValue: boolean, isLast: boolean, collector: ISuggestionsCollector): Thenable<any> | 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<CompletionItem> {
|
||||
public resolveSuggestion(item: CompletionItem): Thenable<CompletionItem | null> | 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<string> {
|
||||
private getInfo(pack: string): Thenable<string | undefined> {
|
||||
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<MarkedString[]> {
|
||||
public getInfoContribution(resource: string, location: Location): Thenable<MarkedString[] | null> | null {
|
||||
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']))) {
|
||||
let pack = location.path[location.path.length - 1];
|
||||
if (typeof pack === 'string') {
|
||||
|
||||
@@ -24,11 +24,11 @@ export interface ISuggestionsCollector {
|
||||
|
||||
export interface IJSONContribution {
|
||||
getDocumentSelector(): DocumentSelector;
|
||||
getInfoContribution(fileName: string, location: Location): Thenable<MarkedString[]>;
|
||||
collectPropertySuggestions(fileName: string, location: Location, currentWord: string, addValue: boolean, isLast: boolean, result: ISuggestionsCollector): Thenable<any>;
|
||||
collectValueSuggestions(fileName: string, location: Location, result: ISuggestionsCollector): Thenable<any>;
|
||||
getInfoContribution(fileName: string, location: Location): Thenable<MarkedString[] | null> | null;
|
||||
collectPropertySuggestions(fileName: string, location: Location, currentWord: string, addValue: boolean, isLast: boolean, result: ISuggestionsCollector): Thenable<any> | null;
|
||||
collectValueSuggestions(fileName: string, location: Location, result: ISuggestionsCollector): Thenable<any> | null;
|
||||
collectDefaultSuggestions(fileName: string, result: ISuggestionsCollector): Thenable<any>;
|
||||
resolveSuggestion?(item: CompletionItem): Thenable<CompletionItem>;
|
||||
resolveSuggestion?(item: CompletionItem): Thenable<CompletionItem | null> | 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<Hover> {
|
||||
public provideHover(document: TextDocument, position: Position, token: CancellationToken): Thenable<Hover> | 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<CompletionItem> {
|
||||
public resolveCompletionItem(item: CompletionItem, token: CancellationToken): Thenable<CompletionItem | null> {
|
||||
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<CompletionList> {
|
||||
public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Thenable<CompletionList | null> | null {
|
||||
|
||||
let fileName = basename(document.fileName);
|
||||
|
||||
@@ -118,7 +121,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
|
||||
log: (message: string) => console.log(message)
|
||||
};
|
||||
|
||||
let collectPromise: Thenable<any> = null;
|
||||
let collectPromise: Thenable<any> | null = null;
|
||||
|
||||
if (location.isAtPropertyKey) {
|
||||
let addValue = !location.previousNode || !location.previousNode.columnOffset;
|
||||
|
||||
@@ -54,7 +54,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
addValue: boolean,
|
||||
isLast: boolean,
|
||||
collector: ISuggestionsCollector
|
||||
): Thenable<any> {
|
||||
): Thenable<any> | 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<any> {
|
||||
): Thenable<any> | 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<CompletionItem> {
|
||||
public resolveSuggestion(item: CompletionItem): Thenable<CompletionItem | null> | 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<MarkedString[]> {
|
||||
public getInfoContribution(fileName: string, location: Location): Thenable<MarkedString[] | null> | 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') {
|
||||
|
||||
Reference in New Issue
Block a user