Skip to content

Commit 1db6287

Browse files
authored
Merge pull request #351 from redhat-developer/remove-promise-constructors
Remove unneeded promise constructors
2 parents 35e3358 + 90598e3 commit 1db6287

7 files changed

Lines changed: 19 additions & 36 deletions

File tree

src/languageservice/services/yamlCompletion.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ASTNode, ObjectASTNode, PropertyASTNode } from '../jsonASTTypes';
1010
import { parse as parseYAML } from '../parser/yamlParser07';
1111
import { YAMLSchemaService } from './yamlSchemaService';
1212
import { JSONSchema, JSONSchemaRef } from '../jsonSchema';
13-
import { PromiseConstructor, Thenable, JSONWorkerContribution, CompletionsCollector } from 'vscode-json-languageservice';
13+
import { Thenable, CompletionsCollector } from 'vscode-json-languageservice';
1414
import {
1515
CompletionItem,
1616
CompletionItemKind,
@@ -26,7 +26,6 @@ import { getLineOffsets, filterInvalidCustomTags, matchOffsetToDocument } from '
2626
import { LanguageSettings } from '../yamlLanguageService';
2727
import { ResolvedSchema } from 'vscode-json-languageservice/lib/umd/services/jsonSchemaService';
2828
import { JSONCompletion } from 'vscode-json-languageservice/lib/umd/services/jsonCompletion';
29-
import { ClientCapabilities } from 'vscode-languageserver-protocol';
3029
import { stringifyObject, StringifySettings } from '../utils/json';
3130
import { guessIndentation } from '../utils/indentationGuesser';
3231
import { TextBuffer } from '../utils/textBuffer';
@@ -35,22 +34,14 @@ const localize = nls.loadMessageBundle();
3534

3635
export class YAMLCompletion extends JSONCompletion {
3736
private schemaService: YAMLSchemaService;
38-
private promise: PromiseConstructor;
3937
private customTags: Array<string>;
4038
private completion: boolean;
41-
private supportsMarkdown: boolean | undefined;
4239
private indentation: string;
4340
private configuredIndentation: string | undefined;
4441

45-
constructor(
46-
schemaService: YAMLSchemaService,
47-
contributions: JSONWorkerContribution[] = [],
48-
promiseConstructor: PromiseConstructor = Promise,
49-
private clientCapabilities: ClientCapabilities = {}
50-
) {
51-
super(schemaService, contributions, promiseConstructor);
42+
constructor(schemaService: YAMLSchemaService) {
43+
super(schemaService, [], Promise);
5244
this.schemaService = schemaService;
53-
this.promise = promiseConstructor || Promise;
5445
this.customTags = [];
5546
this.completion = true;
5647
}
@@ -227,7 +218,7 @@ export class YAMLCompletion extends JSONCompletion {
227218
this.getValueCompletions(newSchema, currentDoc, node, offset, document, collector, types);
228219
}
229220

230-
return this.promise.all(collectionPromises).then(() => {
221+
return Promise.all(collectionPromises).then(() => {
231222
return result;
232223
});
233224
});

src/languageservice/services/yamlHover.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*--------------------------------------------------------------------------------------------*/
66
'use strict';
77

8-
import { PromiseConstructor, Thenable } from 'vscode-json-languageservice';
8+
import { Thenable } from 'vscode-json-languageservice';
99
import { Hover, TextDocument, Position } from 'vscode-languageserver-types';
1010
import { matchOffsetToDocument } from '../utils/arrUtils';
1111
import { LanguageSettings } from '../yamlLanguageService';
@@ -15,12 +15,10 @@ import { JSONHover } from 'vscode-json-languageservice/lib/umd/services/jsonHove
1515
import { setKubernetesParserOption } from '../parser/isKubernetes';
1616

1717
export class YAMLHover {
18-
private promise: PromiseConstructor;
1918
private shouldHover: boolean;
2019
private jsonHover;
2120

22-
constructor(schemaService: YAMLSchemaService, promiseConstructor: PromiseConstructor) {
23-
this.promise = promiseConstructor || Promise;
21+
constructor(schemaService: YAMLSchemaService) {
2422
this.shouldHover = true;
2523
this.jsonHover = new JSONHover(schemaService, [], Promise);
2624
}
@@ -33,13 +31,13 @@ export class YAMLHover {
3331

3432
public doHover(document: TextDocument, position: Position, isKubernetes = false): Thenable<Hover> {
3533
if (!this.shouldHover || !document) {
36-
return this.promise.resolve(undefined);
34+
return Promise.resolve(undefined);
3735
}
3836
const doc = parseYAML(document.getText());
3937
const offset = document.offsetAt(position);
4038
const currentDoc = matchOffsetToDocument(offset, doc);
4139
if (currentDoc === null) {
42-
return this.promise.resolve(undefined);
40+
return Promise.resolve(undefined);
4341
}
4442

4543
setKubernetesParserOption(doc.documents, isKubernetes);

src/languageservice/services/yamlValidation.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77

88
import { Diagnostic } from 'vscode-languageserver-types';
9-
import { PromiseConstructor, LanguageSettings } from '../yamlLanguageService';
9+
import { LanguageSettings } from '../yamlLanguageService';
1010
import { parse as parseYAML, YAMLDocument } from '../parser/yamlParser07';
1111
import { SingleYAMLDocument } from '../parser/yamlParser07';
1212
import { YAMLSchemaService } from './yamlSchemaService';
@@ -30,17 +30,15 @@ export const yamlDiagToLSDiag = (yamlDiag: YAMLDocDiagnostic, textDocument: Text
3030
};
3131

3232
export class YAMLValidation {
33-
private promise: PromiseConstructor;
3433
private validationEnabled: boolean;
3534
private customTags: string[];
3635
private jsonValidation;
3736

3837
private MATCHES_MULTIPLE = 'Matches multiple schemas when only one must validate.';
3938

40-
public constructor(schemaService: YAMLSchemaService, promiseConstructor: PromiseConstructor) {
41-
this.promise = promiseConstructor || Promise;
39+
public constructor(schemaService: YAMLSchemaService) {
4240
this.validationEnabled = true;
43-
this.jsonValidation = new JSONValidation(schemaService, this.promise);
41+
this.jsonValidation = new JSONValidation(schemaService, Promise);
4442
}
4543

4644
public configure(settings: LanguageSettings): void {
@@ -52,7 +50,7 @@ export class YAMLValidation {
5250

5351
public async doValidation(textDocument: TextDocument, isKubernetes = false): Promise<Diagnostic[]> {
5452
if (!this.validationEnabled) {
55-
return this.promise.resolve([]);
53+
return Promise.resolve([]);
5654
}
5755

5856
const yamlDocument: YAMLDocument = parseYAML(textDocument.getText(), this.customTags);

src/languageservice/yamlLanguageService.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,13 @@ export interface LanguageService {
146146

147147
export function getLanguageService(
148148
schemaRequestService: SchemaRequestService,
149-
workspaceContext: WorkspaceContextService,
150-
contributions: JSONWorkerContribution[],
151-
promiseConstructor?: PromiseConstructor
149+
workspaceContext: WorkspaceContextService
152150
): LanguageService {
153-
const promise = promiseConstructor || Promise;
154-
155151
const schemaService = new YAMLSchemaService(schemaRequestService, workspaceContext);
156-
const completer = new YAMLCompletion(schemaService, contributions, promise);
157-
const hover = new YAMLHover(schemaService, promise);
152+
const completer = new YAMLCompletion(schemaService);
153+
const hover = new YAMLHover(schemaService);
158154
const yamlDocumentSymbols = new YAMLDocumentSymbols(schemaService);
159-
const yamlValidation = new YAMLValidation(schemaService, promise);
155+
const yamlValidation = new YAMLValidation(schemaService);
160156
const formatter = new YAMLFormatter();
161157

162158
return {

src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ documents.listen(connection);
375375

376376
const schemaRequestService = schemaRequestHandler.bind(this, connection);
377377

378-
export const customLanguageService = getCustomLanguageService(schemaRequestService, workspaceContext, []);
378+
export const customLanguageService = getCustomLanguageService(schemaRequestService, workspaceContext);
379379

380380
/***********************
381381
* Connection listeners

test/integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as assert from 'assert';
88
import { MarkedString } from '../src';
99
import { Diagnostic, CompletionList, Hover } from 'vscode-languageserver';
1010

11-
const languageService = getLanguageService(schemaRequestService, workspaceContext, [], null);
11+
const languageService = getLanguageService(schemaRequestService, workspaceContext);
1212

1313
const uri = 'https://raw.githubusercontent.com/instrumenta/kubernetes-json-schema/master/v1.17.0-standalone-strict/all.json';
1414
const languageSettings: LanguageSettings = {

test/utils/testHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function toFsPath(str: unknown): string {
103103
}
104104

105105
export function configureLanguageService(languageSettings: LanguageSettings): LanguageService {
106-
const languageService = getLanguageService(schemaRequestService, workspaceContext, [], null);
106+
const languageService = getLanguageService(schemaRequestService, workspaceContext);
107107

108108
languageService.configure(languageSettings);
109109
return languageService;

0 commit comments

Comments
 (0)