Skip to content

Commit

Permalink
Merge pull request redhat-developer#347 from redhat-developer/console…
Browse files Browse the repository at this point in the history
…-hover-fix

Add isKubernetes option to doHover
  • Loading branch information
JPinkney authored Nov 10, 2020
2 parents 5862fe5 + 4708ed0 commit a3d5aab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/languageservice/parser/isKubernetes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as Parser from './jsonParser07';

export function setKubernetesParserOption(jsonDocuments: Parser.JSONDocument[], option: boolean): void {
for (const jsonDoc of jsonDocuments) {
jsonDoc.isKubernetes = option;
}
}
10 changes: 2 additions & 8 deletions src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ClientCapabilities } from 'vscode-languageserver-protocol';
import { stringifyObject, StringifySettings } from '../utils/json';
import { guessIndentation } from '../utils/indentationGuesser';
import { TextBuffer } from '../utils/textBuffer';
import { setKubernetesParserOption } from '../parser/isKubernetes';
const localize = nls.loadMessageBundle();

export class YAMLCompletion extends JSONCompletion {
Expand Down Expand Up @@ -94,7 +95,7 @@ export class YAMLCompletion extends JSONCompletion {
} else {
this.indentation = this.configuredIndentation;
}
this.setKubernetesParserOption(doc.documents, isKubernetes);
setKubernetesParserOption(doc.documents, isKubernetes);

const offset = document.offsetAt(position);
if (document.getText()[offset] === ':') {
Expand Down Expand Up @@ -1006,13 +1007,6 @@ export class YAMLCompletion extends JSONCompletion {
private is_EOL(c: number): boolean {
return c === 0x0a /* LF */ || c === 0x0d /* CR */;
}

// Called by onCompletion
private setKubernetesParserOption(jsonDocuments: Parser.JSONDocument[], option: boolean): void {
for (const jsonDoc in jsonDocuments) {
jsonDocuments[jsonDoc].isKubernetes = option;
}
}
}

const isNumberExp = /^\d+$/;
Expand Down
4 changes: 3 additions & 1 deletion src/languageservice/services/yamlHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { LanguageSettings } from '../yamlLanguageService';
import { parse as parseYAML } from '../parser/yamlParser07';
import { YAMLSchemaService } from './yamlSchemaService';
import { JSONHover } from 'vscode-json-languageservice/lib/umd/services/jsonHover';
import { setKubernetesParserOption } from '../parser/isKubernetes';

export class YAMLHover {
private promise: PromiseConstructor;
Expand All @@ -30,7 +31,7 @@ export class YAMLHover {
}
}

public doHover(document: TextDocument, position: Position): Thenable<Hover> {
public doHover(document: TextDocument, position: Position, isKubernetes = false): Thenable<Hover> {
if (!this.shouldHover || !document) {
return this.promise.resolve(undefined);
}
Expand All @@ -41,6 +42,7 @@ export class YAMLHover {
return this.promise.resolve(undefined);
}

setKubernetesParserOption(doc.documents, isKubernetes);
const currentDocIndex = doc.documents.indexOf(currentDoc);
currentDoc.currentDocIndex = currentDocIndex;
return this.jsonHover.doHover(document, position, currentDoc);
Expand Down

0 comments on commit a3d5aab

Please sign in to comment.