-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from davelopez/basic_yaml_language_service
Basic YAML language service implementation
- Loading branch information
Showing
50 changed files
with
1,280 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 8 additions & 55 deletions
63
server/gx-workflow-ls-format2/src/gxFormat2WorkflowDocument.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,17 @@ | ||
import { ObjectASTNode } from "vscode-json-languageservice"; | ||
import { TextDocument, Range, Position, ASTNode, WorkflowDocument } from "@gxwf/server-common/src/languageTypes"; | ||
import { TextDocument, WorkflowDocument } from "@gxwf/server-common/src/languageTypes"; | ||
import { YAMLDocument } from "@gxwf/yaml-language-service/src"; | ||
|
||
/** | ||
* This class provides information about a gxformat2 workflow document structure. | ||
*/ | ||
export class GxFormat2WorkflowDocument extends WorkflowDocument { | ||
constructor(textDocument: TextDocument) { | ||
super(textDocument); | ||
private _yamlDocument: YAMLDocument; | ||
constructor(textDocument: TextDocument, yamlDocument: YAMLDocument) { | ||
super(textDocument, yamlDocument); | ||
this._yamlDocument = yamlDocument; | ||
} | ||
|
||
public get rootNode(): ASTNode | undefined { | ||
return; | ||
} | ||
|
||
public override getNodeAtPosition(position: Position): ASTNode | undefined { | ||
return; | ||
} | ||
|
||
public override getDocumentRange(): Range { | ||
return Range.create(this.textDocument.positionAt(0), this.textDocument.positionAt(1)); | ||
} | ||
|
||
public getNodeRange(node: ASTNode): Range { | ||
return Range.create( | ||
this.textDocument.positionAt(node.offset), | ||
this.textDocument.positionAt(node.offset + node.length) | ||
); | ||
} | ||
|
||
public getNodeRangeAtPosition(position: Position): Range { | ||
const node = this.getNodeAtPosition(position); | ||
return node ? this.getNodeRange(node) : this.getDefaultRangeAtPosition(position); | ||
} | ||
|
||
public isLastNodeInParent(node: ASTNode): boolean { | ||
const parent = node.parent; | ||
if (!parent || !parent.children) { | ||
return true; // Must be root | ||
} | ||
const lastNode = parent.children[parent.children.length - 1]; | ||
return node === lastNode; | ||
} | ||
|
||
public getPreviousSiblingNode(node: ASTNode): ASTNode | null { | ||
const parent = node.parent; | ||
if (!parent || !parent.children) { | ||
return null; | ||
} | ||
const previousNodeIndex = parent.children.indexOf(node) - 1; | ||
if (previousNodeIndex < 0) { | ||
return null; | ||
} | ||
return parent.children[previousNodeIndex]; | ||
} | ||
|
||
public override getNodeFromPath(path: string): ASTNode | null { | ||
return null; | ||
} | ||
|
||
public override getStepNodes(): ObjectASTNode[] { | ||
return []; | ||
public get yamlDocument(): YAMLDocument { | ||
return this._yamlDocument; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ASTNode } from "@gxwf/server-common/src/ast/types"; | ||
import { TextDocument } from "@gxwf/server-common/src/languageTypes"; | ||
import { getLanguageService, YAMLDocument } from "@gxwf/yaml-language-service/src"; | ||
import { GxFormat2WorkflowDocument } from "../src/gxFormat2WorkflowDocument"; | ||
|
||
export function toYamlDocument(contents: string): { textDoc: TextDocument; yamlDoc: YAMLDocument } { | ||
const textDoc = TextDocument.create("foo://bar/file.gxwf.yaml", "gxformat2", 0, contents); | ||
|
||
const ls = getLanguageService(); | ||
const yamlDoc = ls.parseYAMLDocument(textDoc) as YAMLDocument; | ||
return { textDoc, yamlDoc }; | ||
} | ||
|
||
export function getYamlDocumentRoot(contents: string): ASTNode { | ||
const { yamlDoc } = toYamlDocument(contents); | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
return yamlDoc.root!; | ||
} | ||
|
||
export function createFormat2WorkflowDocument(contents: string): GxFormat2WorkflowDocument { | ||
const { textDoc, yamlDoc } = toYamlDocument(contents); | ||
return new GxFormat2WorkflowDocument(textDoc, yamlDoc); | ||
} |
41 changes: 41 additions & 0 deletions
41
server/gx-workflow-ls-format2/tests/unit/astUtils-yaml.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { getPropertyNodeFromPath } from "@gxwf/server-common/src/ast/utils"; | ||
import { getYamlDocumentRoot } from "../testHelpers"; | ||
import { expectPropertyNodeToHaveKey } from "@gxwf/server-common/tests/testHelpers"; | ||
|
||
describe("AST Utility Functions with YAML", () => { | ||
describe("getPropertyNodeFromPath", () => { | ||
describe("with valid path", () => { | ||
it.each([ | ||
["key:\n key2: 0\n", "key"], | ||
["key:\n key2: 0\n", "key/key2"], | ||
["key:\n key2: 0\nkey3: val", "key3"], | ||
["key:\n key2: 0}\n key3: val", "key/key3"], | ||
["key:\n key2:\n key3: val", "key/key2"], | ||
["key:\n key2:\n key3: val", "key/key2/key3"], | ||
])("returns the expected property node at the given path", (contents: string, path: string) => { | ||
const root = getYamlDocumentRoot(contents); | ||
const pathItems = path.split("/"); | ||
const expectedPropertyKey = pathItems[pathItems.length - 1] as string; | ||
|
||
const propertyNode = getPropertyNodeFromPath(root, path); | ||
|
||
expectPropertyNodeToHaveKey(propertyNode, expectedPropertyKey); | ||
}); | ||
}); | ||
|
||
describe("with invalid path", () => { | ||
it.each([ | ||
["key:\n key2: 0\n", "key2"], | ||
["key:\n key2: 0\n", "key3"], | ||
["key:\n key2: 0\n", "key/5"], | ||
["key:\n key2:\n key3: val", "key/key3"], | ||
])("returns null", (contents: string, path: string) => { | ||
const root = getYamlDocumentRoot(contents); | ||
|
||
const propertyNode = getPropertyNodeFromPath(root, path); | ||
|
||
expect(propertyNode).toBeNull(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.