Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions client/src/embeddedHTML.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DocumentSymbol, SymbolInformation } from 'vscode';


interface EmbeddedRegion {
Expand All @@ -7,9 +8,18 @@ interface EmbeddedRegion {
attributeValue?: boolean;
}

export function isValidRustYew(documentText: string) {
if (documentText.match(/html! {.*}/gs)) {
// valid if there is at least one html! { ... } macro
return true;
} else {
return false;
}
}

export function isInsideHTMLRegion(documentText: string, offset: number) {
// Don't parse on no html! macro document
if (documentText.match(/html! {.*}/g)) {
// Don't parse on no html! macro documents
if (!isValidRustYew(documentText)) {
return false;
}

Expand Down Expand Up @@ -102,4 +112,14 @@ export function getRegions(documentText: string) {
});

return regions;
}
}

export function unpackDocumentSymbolChildren(symbol: DocumentSymbol): DocumentSymbol[] {
let result: DocumentSymbol[] = [];
result.push(symbol);
if (symbol.children.length > 0) {
symbol.children.forEach(s => result = result.concat(unpackDocumentSymbolChildren(s)));
}
console.debug(result);
return result;
}
32 changes: 20 additions & 12 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ServerOptions,
TransportKind
} from 'vscode-languageclient/node';
import { getHTMLVirtualContent, isInsideHTMLRegion } from './embeddedHTML';
import { getHTMLVirtualContent, isInsideHTMLRegion, isValidRustYew, unpackDocumentSymbolChildren as unpackDocumentSymbolChildren } from './embeddedHTML';

let client: LanguageClient;

Expand Down Expand Up @@ -100,28 +100,36 @@ export function activate(context: ExtensionContext) {
if (!isInsideHTMLRegion(document.getText(), document.offsetAt(position))) {
return await next(document, position, token);
}
console.log("doing hover!");
const result = await commands.executeCommand<Hover[]>(
'vscode.executeHoverProvider',
vdocUri(document),
position,
);
console.debug(result);
return result[0];
},
async provideDocumentSymbols(document, token, next) {
if (!isValidRustYew(document.getText())) {
return next(document, token);
}
console.log("doing symbol!");
let result = undefined;

// FIXME: [1] result is undefined for a long time, perhaps HTML Language Service isn't started yet?
// FIXME: [2] HTML document symbol provided are greatly missing!
result = await commands.executeCommand<DocumentSymbol[]>(
'vscode.executeDocumentSymbolProvider',
vdocUri(document),
);

console.debug(result);
return result;
},
let result: undefined | DocumentSymbol[] = undefined;
let count = 0;
while (result === undefined && count < 5) {
await new Promise(r => setTimeout(r, 1000));
result = await commands.executeCommand<DocumentSymbol[]>(
'vscode.executeDocumentSymbolProvider',
vdocUri(document),
);
count++;
}
let answer: DocumentSymbol[] = [];
result.forEach(s => answer = answer.concat(unpackDocumentSymbolChildren(s)));
console.debug(answer);
return answer;
}
}
};

Expand Down