-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
dockerSymbols.ts
38 lines (33 loc) · 1.37 KB
/
dockerSymbols.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* --------------------------------------------------------------------------------------------
* Copyright (c) Remy Suen. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
import {
TextDocument, SymbolInformation, SymbolKind, Range
} from 'vscode-languageserver';
import { DockerfileParser } from 'dockerfile-ast';
export class DockerSymbols {
private createSymbolInformation(name: string, textDocumentURI: string, range: Range, kind: SymbolKind) {
return {
name: name,
location: {
uri: textDocumentURI,
range: range
},
kind: kind
};
}
public parseSymbolInformation(document: TextDocument, textDocumentURI: string): SymbolInformation[] {
let dockerfile = DockerfileParser.parse(document.getText());
let directive = dockerfile.getDirective();
let symbols: SymbolInformation[] = [];
if (directive !== null) {
symbols.push(this.createSymbolInformation(directive.getName(), textDocumentURI, directive.getNameRange(), SymbolKind.Property));
}
for (let instruction of dockerfile.getInstructions()) {
symbols.push(this.createSymbolInformation(instruction.getInstruction(), textDocumentURI, instruction.getInstructionRange(), SymbolKind.Function));
}
return symbols;
}
}