✨ Add implementationProvider for filters
This commit is contained in:
parent
3b0b58e44b
commit
62c25bc693
3 changed files with 81 additions and 3 deletions
|
@ -4,6 +4,7 @@ import { colorProvider, iconDefinitionProvider } from "./generic";
|
|||
import {
|
||||
filterCompletionProvider,
|
||||
filterDefinitionProvider,
|
||||
filterImplementationProvider,
|
||||
tagRenderingCompletionProvider,
|
||||
tagRenderingDefinitionProvider,
|
||||
tagRenderingImplementationProvider,
|
||||
|
@ -21,7 +22,8 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
tagRenderingDefinitionProvider,
|
||||
filterCompletionProvider,
|
||||
filterDefinitionProvider,
|
||||
tagRenderingImplementationProvider
|
||||
tagRenderingImplementationProvider,
|
||||
filterImplementationProvider
|
||||
);
|
||||
|
||||
// Activate all license info related features
|
||||
|
|
|
@ -405,3 +405,79 @@ export const filterDefinitionProvider =
|
|||
},
|
||||
}
|
||||
);
|
||||
|
||||
export const filterImplementationProvider =
|
||||
vscode.languages.registerImplementationProvider(
|
||||
{
|
||||
language: "json",
|
||||
scheme: "file",
|
||||
pattern: "**/assets/*/*/*.json",
|
||||
},
|
||||
{
|
||||
async provideImplementation(
|
||||
document: vscode.TextDocument,
|
||||
position: vscode.Position,
|
||||
_token: vscode.CancellationToken
|
||||
) {
|
||||
console.log("filterImplementationProvider");
|
||||
const text = document.getText();
|
||||
const jsonPath = getCursorPath(text, position);
|
||||
const rawJsonPath = getRawCursorPath(text, position);
|
||||
|
||||
const regex = /^filter(\+)?\.\d+\.id$/;
|
||||
|
||||
if (regex.exec(jsonPath)) {
|
||||
const filterId = getValueFromPath(text, rawJsonPath);
|
||||
const layerName = document.fileName.split("/").pop()?.split(".")[0];
|
||||
const to = `layers.${layerName}.filter.${filterId}`;
|
||||
|
||||
try {
|
||||
const cache = await Cache.create();
|
||||
const references = cache.getReferences(to);
|
||||
|
||||
if (references.length === 0) {
|
||||
console.log("No references found to", to);
|
||||
return null;
|
||||
} else {
|
||||
console.log(`Found ${references.length} references to ${to}`);
|
||||
|
||||
const links: vscode.DefinitionLink[] = [];
|
||||
for (const reference of references) {
|
||||
console.log(
|
||||
`Pushing link from ${document.fileName} to ${reference.reference?.from.uri?.fsPath} at ${reference.reference?.to.range?.[0]?.line}:${reference.reference?.to.range?.[0]?.character}`,
|
||||
reference
|
||||
);
|
||||
|
||||
// Check if we have a targetUri
|
||||
if (reference.reference?.from.uri) {
|
||||
links.push({
|
||||
originSelectionRange: new vscode.Range(
|
||||
reference.reference?.to?.range?.[0]?.line ?? 0,
|
||||
reference.reference?.to?.range?.[0]?.character ?? 0,
|
||||
reference.reference?.to?.range?.[1]?.line ?? 0,
|
||||
reference.reference?.to?.range?.[1]?.character ?? 0
|
||||
),
|
||||
targetRange: new vscode.Range(
|
||||
reference.reference?.from?.range?.[0]?.line ?? 0,
|
||||
reference.reference?.from?.range?.[0]?.character ?? 0,
|
||||
reference.reference?.from?.range?.[1]?.line ?? 0,
|
||||
reference.reference?.from?.range?.[1]?.character ?? 0
|
||||
),
|
||||
targetUri: reference.reference?.from?.uri,
|
||||
});
|
||||
} else {
|
||||
console.error("Incomplete reference", reference);
|
||||
}
|
||||
}
|
||||
console.log(`Found ${links.length} implementations`);
|
||||
return links;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error get implementation", error);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
}
|
||||
);
|
||||
|
|
|
@ -640,8 +640,8 @@ export class CacheWorker {
|
|||
: getStartEnd(text, path);
|
||||
const filterId = filter.includes(".") ? filter.split(".")[1] : filter;
|
||||
const to = filter.includes(".")
|
||||
? `layers.${filter.split(".")[0]}`
|
||||
: `layers.filters`;
|
||||
? `layers.${filter.split(".")[0]}.filter.${filterId}`
|
||||
: `layers.filters.filter.${filterId}`;
|
||||
// Now we'll need to determine what file we need to look in
|
||||
const toFileName = filter.includes(".")
|
||||
? `**/assets/layers/${filter.split(".")[0]}/${
|
||||
|
|
Loading…
Reference in a new issue