vscode-xml/src/xpath/commands/getCurrentXPath.ts
Josh Johnson 6a92fa96f2 Add Get Current XPath
This commit also moves some shared code to a common class.

Issue: #85
2018-05-29 21:38:11 -04:00

21 lines
656 B
TypeScript

import { window } from "vscode";
import { TextEditor, TextEditorEdit } from "vscode";
import { DOMParser } from "xmldom";
import { XPathBuilder } from "../xpath-builder";
export function getCurrentXPath(editor: TextEditor, edit: TextEditorEdit): void {
if (!editor.selection) {
window.showInformationMessage("Please put your cursor in an element or attribute name.");
return;
}
const document = new DOMParser().parseFromString(editor.document.getText());
const xpath = new XPathBuilder(document).build(editor.selection.start);
window.showInputBox({
value: xpath,
valueSelection: undefined
});
}