Skip to content

Commit 8da7029

Browse files
committed
for selectXPathInDocument ensure uri passed in args is used to get document reference
1 parent fd24fb5 commit 8da7029

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/extension.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ export function activate(context: vscode.ExtensionContext) {
139139
let cachedSymbols: vscode.DocumentSymbol[] = [];
140140
let cachedSymbolsDocUri = vscode.Uri.parse('file:/empty');
141141

142-
async function getSymbolFromXPath(args: any[]) {
142+
async function getSymbolFromXPath(args: any[], textDocument?: vscode.TextDocument) {
143143
const { xpath, uri } = args[0];
144144
const docUri = vscode.Uri.parse(uri);
145145
const useCachedSymbols = cachedSymbolsDocUri === docUri;
146146
const docs = vscode.workspace.textDocuments;
147-
const foundDoc = docs.find(doc => doc.uri.toString() === uri);
147+
const foundDoc = textDocument? textDocument : docs.find(doc => doc.uri.toString() === uri);
148148
if (!useCachedSymbols && foundDoc) {
149149
const sp = new XsltSymbolProvider(XMLConfiguration.configuration, null);
150150
const newSymbols = await sp.getDocumentSymbols(foundDoc, false);
@@ -165,9 +165,12 @@ export function activate(context: vscode.ExtensionContext) {
165165
let doc = await vscode.workspace.openTextDocument(docUri);
166166
const viewColumn = vscode.ViewColumn.Beside;
167167
const keepFocus = true;
168-
await vscode.window.showTextDocument(doc, viewColumn, keepFocus);
169-
selectTextFromXPath(xpath);
170-
168+
const editor = await vscode.window.showTextDocument(doc, viewColumn, keepFocus);
169+
const symbol = await getSymbolFromXPath(args, doc);
170+
if (symbol) {
171+
editor.selection = new vscode.Selection(symbol.range.start, symbol.range.end);
172+
XsltSymbolProvider.selectTextWithSymbol(symbol);
173+
}
171174
}
172175

173176
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(editor => {

0 commit comments

Comments
 (0)