Skip to content

Commit

Permalink
Addresses issue #55 by jumping to symbol definitions in external docu…
Browse files Browse the repository at this point in the history
…ments; resolves the canonical paths of includes; corrects off-by-one errors on changes to the line numbers from lfortran; adds support for matching completions against all symbols in the document; corrects the completion kinds by mapping them from type SymbolKind to type CompletionItemKind; corrects the mtime type of FileCacheEntry to Date; resolves file paths while extracting definitions; corrects highlighting and query extraction logic by matching against type strings in additional to symbol literals; depends on lfortran when extracting hover previews; removes LFortranLanguageServer.renameSymbol since it has been deprecated and replaced with the analogous method of LFortranCLIAccessor; corrects unit and integration tests for latest changes
  • Loading branch information
dylon committed Dec 27, 2024
1 parent bc065ca commit 2bba6aa
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 439 deletions.
2 changes: 1 addition & 1 deletion integ/spec/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export async function getErrorAlert(driver: WebDriver): Promise<string> {
const errorAlert: WebElement =
await driver.wait(
until.elementLocated(
By.css('div.message[role="alert"][aria-label^="error"] div')),
By.css('div.message[role="alert"] div')),
TIMEOUT);
const errorMessage: string =
await driver.executeScript(
Expand Down
108 changes: 69 additions & 39 deletions server/src/lfortran-accessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,51 @@ export class LFortranCLIAccessor implements LFortranAccessor {
return output;
}

resolve(filename: string, flags: string[], resolved?: Map<string, string>): string {
const fnid: string = "resolve";
const start: number = performance.now();

let filePath: string = filename;

if (!fs.existsSync(filePath)) {
let resolution: string | undefined = resolved?.get(filePath);
if (resolution === undefined) {
for (const flag of flags) {
if (flag.startsWith("-I")) {
const includeDir = flag.substring(2);
resolution = path.join(includeDir, filename);
if (fs.existsSync(resolution)) {
resolution = fs.realpathSync(resolution);
resolved?.set(filename, resolution);
filePath = resolution;
break;
}
}
}
} else {
filePath = resolution;
}
}

if (!fs.existsSync(filePath)) {
this.logWarn("Failed to find file by URI: %s", filePath);
}

if (this.logger.isBenchmarkOrTraceEnabled()) {
this.logBenchmarkAndTrace(
fnid, start,
[
"filename", filename,
"flags", flags,
"resolved", resolved,
],
filePath
);
}

return filePath;
}

async showDocumentSymbols(uri: string,
text: string,
settings: LFortranSettings): Promise<SymbolInformation[]> {
Expand All @@ -324,30 +369,8 @@ export class LFortranCLIAccessor implements LFortranAccessor {
const resolved: Map<string, string> = new Map();
for (let i = 0, k = symbols.length; i < k; i++) {
const symbol: Record<string, any> = symbols[i];
let symbolPath: string = symbol.filename;

if (!fs.existsSync(symbolPath)) {
let resolution = resolved.get(symbolPath);
if (resolution === undefined) {
for (const flag of settings.compiler.flags) {
if (flag.startsWith("-I")) {
const includeDir = flag.substring(2);
resolution = path.join(includeDir, symbolPath);
if (fs.existsSync(resolution)) {
resolved.set(symbolPath, resolution);
break;
}
}
}
}
if (fs.existsSync(resolution as string)) {
symbolPath = resolution as string;
}
}

if (!fs.existsSync(symbolPath)) {
this.logWarn("Failed to find file by URI: %s", symbolPath);
}
const symbolPath: string =
this.resolve(symbol.filename, settings.compiler.flags, resolved);

const location: Location = symbol.location;
// location.uri = uri;
Expand All @@ -356,9 +379,11 @@ export class LFortranCLIAccessor implements LFortranAccessor {
const range: Range = location.range;

const start: Position = range.start;
start.line--;
start.character--;

const end: Position = range.end;
end.line--;
end.character--;
}
}
Expand Down Expand Up @@ -396,26 +421,31 @@ export class LFortranCLIAccessor implements LFortranAccessor {
"--continue-compilation"
];
const stdout = await this.runCompiler(settings, flags, text, "[]");
const results = JSON.parse(stdout);
const results: Record<string, any>[] = JSON.parse(stdout);
for (let i = 0, k = results.length; i < k; i++) {
const location = results[i].location;
if (location !== undefined) {
const range: Range = location.range;
const result: Record<string, any> = results[i];
const symbolPath: string =
this.resolve(result.filename, settings.compiler.flags);

const start: Position = range.start;
start.character--;
const location = result.location;

const end: Position = range.end;
end.character--;
const range: Range = location.range;

definitions.push({
targetUri: uri,
targetRange: range,
targetSelectionRange: range
});
const start: Position = range.start;
start.line--;
start.character--;

break;
}
const end: Position = range.end;
end.line--;
end.character--;

definitions.push({
targetUri: symbolPath,
targetRange: range,
targetSelectionRange: range
});

break;
}
} catch (error: any) {
this.logError(
Expand Down
Loading

0 comments on commit 2bba6aa

Please sign in to comment.