Skip to content

Commit

Permalink
fix(restquery): prefer the docs that are visible
Browse files Browse the repository at this point in the history
If the get/docs/<id> id is not the document path but a number (e.g. 0)
the id'th one from the tree view - so the visible dlt docs - is used and not
from the known/still in mem documents.
Fallback to prev method if e.g. no document is visble.
Added a deprecated warning for the case where more than 1 document is know.
This fallback should be removed in the future.
  • Loading branch information
mbehr1 committed Jan 4, 2021
1 parent da4d344 commit 44efe26
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/dltDocumentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,12 @@ export class DltDocumentProvider implements vscode.TreeDataProvider<TreeViewNode
var re = /^\/(?<cmd>.*?)\/(?<path>.*?)($|\?(?<options>.+)$)/;
const regRes = re.exec(query);
if (regRes?.length && regRes.groups) {
console.log(`got regRes.length=${regRes.length}`);
regRes.forEach(regR => console.log(JSON.stringify(regR)));
//console.log(`got regRes.length=${regRes.length}`);
//regRes.forEach(regR => console.log(JSON.stringify(regR)));
const cmd = regRes.groups['cmd'];
const path = regRes.groups['path'];
const options = regRes.groups['options'];
console.log(` cmd='${cmd}' path='${path}' options='${options}'`);
console.log(` restQuery cmd='${cmd}' path='${path}' options='${options}'`);
switch (cmd) {
case 'get':
{
Expand Down Expand Up @@ -809,11 +809,23 @@ export class DltDocumentProvider implements vscode.TreeDataProvider<TreeViewNode
// fallback to index:
if (!doc) {
const docIdx: number = Number(docId);
if (docIdx >= 0 && docIdx < this._documents.size) {
const iter = this._documents.entries();
for (let i = 0; i <= docIdx; ++i) {
const [, aDoc] = iter.next().value;
if (i === docIdx) { doc = aDoc; }

// take the docIdx th. dlt doc that is visible:
if (this._treeRootNodes.length > docIdx) {
const childNode = this._treeRootNodes[docIdx];
// now find the document for that:
this._documents.forEach(aDoc => {
if (aDoc.treeNode === childNode) { doc = aDoc; }
});
}
if (!doc) { // fallback to prev. method. which is ok for one doc, but not for mult....
if (this._documents.size > 1) { console.warn(`DltDocumentProvider.restQuery: you're using a deprecated method to access documents! Please only refer to visible documents!`); }
if (docIdx >= 0 && docIdx < this._documents.size) {
const iter = this._documents.entries();
for (let i = 0; i <= docIdx; ++i) {
const [, aDoc] = iter.next().value;
if (i === docIdx) { doc = aDoc; }
}
}
}
}
Expand Down

0 comments on commit 44efe26

Please sign in to comment.