Merge pull request #2461 from aibaars/selected-line-column

View CFG: export selected line and column position
This commit is contained in:
Andrew Eisenberg
2023-06-01 10:15:54 -07:00
committed by GitHub
3 changed files with 30 additions and 15 deletions

View File

@@ -42,9 +42,14 @@ export function getAstCfgCommands({
const viewCfg = async () => const viewCfg = async () =>
withProgress( withProgress(
async (progress, token) => { async (progress, token) => {
const res = await cfgTemplateProvider.provideCfgUri( const editor = window.activeTextEditor;
window.activeTextEditor?.document, const res = !editor
); ? undefined
: await cfgTemplateProvider.provideCfgUri(
editor.document,
editor.selection.active.line + 1,
editor.selection.active.character + 1,
);
if (res) { if (res) {
await localQueries.compileAndRunQuery( await localQueries.compileAndRunQuery(
QuickEvalType.None, QuickEvalType.None,

View File

@@ -24,7 +24,9 @@ import { QueryResultType } from "../../pure/new-messages";
import { fileRangeFromURI } from "./file-range-from-uri"; import { fileRangeFromURI } from "./file-range-from-uri";
export const SELECT_QUERY_NAME = "#select"; export const SELECT_QUERY_NAME = "#select";
export const TEMPLATE_NAME = "selectedSourceFile"; export const SELECTED_SOURCE_FILE = "selectedSourceFile";
export const SELECTED_SOURCE_LINE = "selectedSourceLine";
export const SELECTED_SOURCE_COLUMN = "selectedSourceColumn";
export interface FullLocationLink extends LocationLink { export interface FullLocationLink extends LocationLink {
originUri: Uri; originUri: Uri;
@@ -124,7 +126,7 @@ async function getLinksFromResults(
function createTemplates(path: string): Record<string, string> { function createTemplates(path: string): Record<string, string> {
return { return {
[TEMPLATE_NAME]: path, [SELECTED_SOURCE_FILE]: path,
}; };
} }

View File

@@ -23,7 +23,9 @@ import { KeyType } from "./key-type";
import { import {
FullLocationLink, FullLocationLink,
getLocationsForUriString, getLocationsForUriString,
TEMPLATE_NAME, SELECTED_SOURCE_FILE,
SELECTED_SOURCE_LINE,
SELECTED_SOURCE_COLUMN,
} from "./location-finder"; } from "./location-finder";
import { import {
qlpackOfDatabase, qlpackOfDatabase,
@@ -253,7 +255,7 @@ export class TemplatePrintAstProvider {
const query = queries[0]; const query = queries[0];
const templates: Record<string, string> = { const templates: Record<string, string> = {
[TEMPLATE_NAME]: zippedArchive.pathWithinSourceArchive, [SELECTED_SOURCE_FILE]: zippedArchive.pathWithinSourceArchive,
}; };
const results = await runContextualQuery( const results = await runContextualQuery(
@@ -284,15 +286,17 @@ export class TemplatePrintCfgProvider {
} }
async provideCfgUri( async provideCfgUri(
document?: TextDocument, document: TextDocument,
line: number,
character: number,
): Promise<[Uri, Record<string, string>] | undefined> { ): Promise<[Uri, Record<string, string>] | undefined> {
if (!document) {
return;
}
return this.shouldUseCache() return this.shouldUseCache()
? await this.cache.get(document.uri.toString()) ? await this.cache.get(
: await this.getCfgUri(document.uri.toString()); `${document.uri.toString()}#${line}:${character}`,
line,
character,
)
: await this.getCfgUri(document.uri.toString(), line, character);
} }
private shouldUseCache() { private shouldUseCache() {
@@ -301,6 +305,8 @@ export class TemplatePrintCfgProvider {
private async getCfgUri( private async getCfgUri(
uriString: string, uriString: string,
line: number,
character: number,
): Promise<[Uri, Record<string, string>]> { ): Promise<[Uri, Record<string, string>]> {
const uri = Uri.parse(uriString, true); const uri = Uri.parse(uriString, true);
if (uri.scheme !== zipArchiveScheme) { if (uri.scheme !== zipArchiveScheme) {
@@ -342,7 +348,9 @@ export class TemplatePrintCfgProvider {
const queryUri = Uri.file(queries[0]); const queryUri = Uri.file(queries[0]);
const templates: Record<string, string> = { const templates: Record<string, string> = {
[TEMPLATE_NAME]: zippedArchive.pathWithinSourceArchive, [SELECTED_SOURCE_FILE]: zippedArchive.pathWithinSourceArchive,
[SELECTED_SOURCE_LINE]: line.toString(),
[SELECTED_SOURCE_COLUMN]: character.toString(),
}; };
return [queryUri, templates]; return [queryUri, templates];