Skip to content

Commit

Permalink
Moving asset extraction into the initialize step, plus clearing a nod…
Browse files Browse the repository at this point in the history
…e deprecation warning
  • Loading branch information
bscan committed Apr 6, 2024
1 parent 21e8886 commit cffe367
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 34 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@
},
"devDependencies": {
"@types/mocha": "^10.0.1",
"@types/node": "^12.12.0",
"@types/node": "^15.0.0",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0",
"@types/webpack-env": "^1.16.0",
Expand Down
4 changes: 2 additions & 2 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions server/src/assets.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import "process";
import { tmpdir } from "os";
import { rmdirSync, mkdirSync, mkdtempSync, createReadStream, createWriteStream } from "fs";
import { rmSync, mkdirSync, mkdtempSync, createReadStream, createWriteStream } from "fs";
import { dirname, join } from "path";

let haveExtractedAssets = false;
let pkgAssetPath: string;

function extractAssetsIfNecessary(): string {
async function extractAssetsIfNecessary(): Promise<string> {
if (!haveExtractedAssets) {
pkgAssetPath = mkdtempSync(join(tmpdir(), "perl-navigator"));
let assets: string[] = [
"src/perl/lib_bs22/ModHunter.pl",
"src/perl/Inquisitor.pm",
"src/perl/criticWrapper.pl",
"src/perl/lib_bs22/Class/Inspector.pm",
"src/perl/lib_bs22/Devel/Symdump.pm",
"src/perl/lib_bs22/Devel/Symdump/Export.pm",
"src/perl/lib_bs22/Inspectorito.pm",
"src/perl/lib_bs22/ModHunter.pl",
"src/perl/lib_bs22/SubUtilPP.pm",
"src/perl/lib_bs22/SourceStash.pm",
"src/perl/lib_bs22/pltags.pm",
"src/perl/Inquisitor.pm",
"src/perl/criticWrapper.pl",
"src/perl/defaultCriticProfile",
"src/perl/tidyWrapper.pl",
"src/perl/perlimportsWrapper.pl",
Expand All @@ -33,11 +33,13 @@ function extractAssetsIfNecessary(): string {
});

haveExtractedAssets = true;
// Allow time to copy. TODO: Change writeStreams to be async and just wait on them
return new Promise(resolve => setTimeout(() => resolve(pkgAssetPath), 50));
}
return pkgAssetPath;
}

export function getAssetsPath(): string {
async function getAssetsPath(): Promise<string> {
let anyProcess = <any>process;
if (anyProcess.pkg) {
// When running inside of a pkg built executable, the assets
Expand All @@ -51,13 +53,13 @@ export function getAssetsPath(): string {
return dirname(__dirname);
}

export function getPerlAssetsPath(): string {
return join(getAssetsPath(), "src", "perl");
export async function getPerlAssetsPath(): Promise<string> {
return join(await getAssetsPath(), "src", "perl");
}

export function cleanupTemporaryAssetPath() {
if (haveExtractedAssets) {
rmdirSync(pkgAssetPath, { recursive: true }); // Create all parent folders
rmSync(pkgAssetPath, { recursive: true }); // Create all parent folders
haveExtractedAssets = false;
}
}
18 changes: 9 additions & 9 deletions server/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function perlcompile(textDocument: TextDocument, workspaceFolders:

if (settings.enableWarnings) perlParams = perlParams.concat(["-Mwarnings", "-M-warnings=redefine"]); // Force enable some warnings.
perlParams = perlParams.concat(getIncPaths(workspaceFolders, settings));
perlParams = perlParams.concat(getInquisitor());
perlParams = perlParams.concat(await getInquisitor());
nLog("Starting perl compilation check with the equivalent of: " + settings.perlPath + " " + perlParams.join(" ") + " " + filePath, settings);


Expand Down Expand Up @@ -56,14 +56,14 @@ export async function perlcompile(textDocument: TextDocument, workspaceFolders:
perlProcess?.child?.stdin?.end();
const out = await perlProcess;

output = out.stderr;
stdout = out.stdout;
output = out.stderr.toString();
stdout = out.stdout.toString();
severity = DiagnosticSeverity.Warning;
} catch (error: any) {
// TODO: Check if we overflowed the buffer.
if ("stderr" in error && "stdout" in error) {
output = error.stderr;
stdout = error.stdout;
output = error.stderr.toString();
stdout = error.stdout.toString();
severity = DiagnosticSeverity.Error;
} else {
nLog("Perlcompile failed with unknown error", settings);
Expand All @@ -85,8 +85,8 @@ export async function perlcompile(textDocument: TextDocument, workspaceFolders:
return { diags: uniq_diagnostics, perlDoc: mergedDoc };
}

function getInquisitor(): string[] {
const inq_path = getPerlAssetsPath();
async function getInquisitor(): Promise<string[]> {
const inq_path = await getPerlAssetsPath();
let inq: string[] = ["-I", inq_path, "-MInquisitor"];
return inq;
}
Expand Down Expand Up @@ -175,7 +175,7 @@ function localizeErrors(violation: string, filePath: string, perlDoc: PerlDocume

export async function perlcritic(textDocument: TextDocument, workspaceFolders: WorkspaceFolder[] | null, settings: NavigatorSettings): Promise<Diagnostic[]> {
if (!settings.perlcriticEnabled) return [];
const critic_path = join(getPerlAssetsPath(), "criticWrapper.pl");
const critic_path = join(await getPerlAssetsPath(), "criticWrapper.pl");
let criticParams: string[] = [...settings.perlParams, critic_path].concat(getCriticProfile(workspaceFolders, settings));
criticParams = criticParams.concat(["--file", Uri.parse(textDocument.uri).fsPath]);

Expand Down Expand Up @@ -215,7 +215,7 @@ export async function perlcritic(textDocument: TextDocument, workspaceFolders: W

export async function perlimports(textDocument: TextDocument, workspaceFolders: WorkspaceFolder[] | null, settings: NavigatorSettings): Promise<Diagnostic[]> {
if (!settings.perlimportsLintEnabled) return [];
const importsPath = join(getPerlAssetsPath(), "perlimportsWrapper.pl");
const importsPath = join(await getPerlAssetsPath(), "perlimportsWrapper.pl");
const cliParams = [...settings.perlParams, importsPath, ...getPerlimportsProfile(settings), "--lint", "--json", "--filename", Uri.parse(textDocument.uri).fsPath];

nLog("Now starting perlimports with: " + cliParams.join(" "), settings);
Expand Down
4 changes: 2 additions & 2 deletions server/src/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function maybeReturnEdits(

async function perlimports(doc: TextDocument, code: string, settings: NavigatorSettings): Promise<string | undefined> {
if (!settings.perlimportsTidyEnabled) return;
const importsPath = join(getPerlAssetsPath(), "perlimportsWrapper.pl");
const importsPath = join(await getPerlAssetsPath(), "perlimportsWrapper.pl");
let cliParams: string[] = [importsPath].concat(getPerlimportsProfile(settings));
cliParams = cliParams.concat(["--filename", Uri.parse(doc.uri).fsPath]);
nLog("Now starting perlimports with: " + cliParams.join(" "), settings);
Expand All @@ -98,7 +98,7 @@ async function perlimports(doc: TextDocument, code: string, settings: NavigatorS

async function perltidy(code: string, settings: NavigatorSettings, workspaceFolders: WorkspaceFolder[] | null): Promise<string | undefined> {
if (!settings.perltidyEnabled) return;
const tidy_path = join(getPerlAssetsPath(), "tidyWrapper.pl");
const tidy_path = join(await getPerlAssetsPath(), "tidyWrapper.pl");
let tidyParams: string[] = [tidy_path].concat(getTidyProfile(workspaceFolders, settings));

nLog("Now starting perltidy with: " + tidyParams.join(" "), settings);
Expand Down
2 changes: 1 addition & 1 deletion server/src/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function badFile(uri: string): boolean {
export async function getAvailableMods(workspaceFolders: WorkspaceFolder[] | null, settings: NavigatorSettings): Promise<Map<string, string>> {
let perlParams = settings.perlParams;
perlParams = perlParams.concat(getIncPaths(workspaceFolders, settings));
const modHunterPath = join(getPerlAssetsPath(), "lib_bs22", "ModHunter.pl");
const modHunterPath = join(await getPerlAssetsPath(), "lib_bs22", "ModHunter.pl");
perlParams.push(modHunterPath);
nLog("Starting to look for perl modules with " + perlParams.join(" "), settings);

Expand Down
4 changes: 3 additions & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { formatDoc, formatRange } from "./formatting";
import { nLog } from "./utils";
import { startProgress, endProgress } from "./progress";
import { getSignature } from "./signatures";
import { getPerlAssetsPath } from "./assets";

var LRU = require("lru-cache");

Expand All @@ -51,7 +52,7 @@ const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
let hasConfigurationCapability = false;
let hasWorkspaceFolderCapability = false;

connection.onInitialize((params: InitializeParams) => {
connection.onInitialize(async (params: InitializeParams) => {
const capabilities = params.capabilities;

// Does the client support the `workspace/configuration` request?
Expand Down Expand Up @@ -87,6 +88,7 @@ connection.onInitialize((params: InitializeParams) => {
},
};
}
await getPerlAssetsPath(); // Ensures assets are unpacked. Should this be in onInitialized?
return result;
});

Expand Down

0 comments on commit cffe367

Please sign in to comment.