Skip to content

Commit

Permalink
reduce bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Mar 3, 2024
1 parent 67b1965 commit c7dd789
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/channel.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import vscode from 'vscode';
import { window } from 'vscode';

export default vscode.window.createOutputChannel('NSIS', 'makensis-log');
export default window.createOutputChannel('NSIS', 'makensis');
7 changes: 3 additions & 4 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import * as NSIS from 'makensis';
import { findErrors, findWarnings, getMakensisPath, getNullDevice, getPreprocessMode, getOverrideCompression, getSpawnEnv } from './util';
import { getConfig } from 'vscode-get-config';
import micromatch from 'micromatch';
import vscode from 'vscode';
import type { DiagnosticCollection } from '../types';
import { type DiagnosticCollection, type TextDocument } from 'vscode';

export async function updateDiagnostics(document: vscode.TextDocument | null, collection: vscode.DiagnosticCollection): Promise<void> {
export async function updateDiagnostics(document: TextDocument | null, collection: DiagnosticCollection): Promise<void> {
if (!document) {
return;
}
Expand Down Expand Up @@ -85,4 +84,4 @@ export async function updateDiagnostics(document: vscode.TextDocument | null, co
}

NSIS.events.removeAllListeners();
}
}
12 changes: 6 additions & 6 deletions src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getConfig } from 'vscode-get-config';
import { platform } from 'os';
import { type CompilerOutput } from 'makensis';
import nsisChannel from './channel';
import vscode from 'vscode';
import { window } from 'vscode';

export async function compilerOutputHandler(data: CompilerOutput): Promise<void> {
const { showOutputView } = await getConfig('nsis');
Expand Down Expand Up @@ -48,10 +48,10 @@ export async function compilerExitHandler(data: CompilerOutput): Promise<void> {
nsisChannel.show();
}

const choice = await vscode.window.showWarningMessage(`Compiled with warnings`, openButton, revealButton);
const choice = await window.showWarningMessage(`Compiled with warnings`, openButton, revealButton);
await buttonHandler(choice, data.outFile);
} else if (showNotifications) {
const choice = await vscode.window.showInformationMessage(`Compiled successfully`, openButton, revealButton);
const choice = await window.showInformationMessage(`Compiled successfully`, openButton, revealButton);
await buttonHandler(choice, data.outFile);
}
} else if (showNotifications) {
Expand All @@ -60,7 +60,7 @@ export async function compilerExitHandler(data: CompilerOutput): Promise<void> {
}

if (showNotifications) {
const choice = await vscode.window.showErrorMessage('Compilation failed, see output for details', 'Show Output');
const choice = await window.showErrorMessage('Compilation failed, see output for details', 'Show Output');
await buttonHandler(choice);
}

Expand Down Expand Up @@ -91,9 +91,9 @@ export async function versionHandler(data: unknown): Promise<void> {
const message = `makensis ${output} (${pathToMakensis})`;

if (showVersionAsInfoMessage === true) {
vscode.window.showInformationMessage(message);
window.showInformationMessage(message);
} else {
nsisChannel.append(message);
nsisChannel.show();
}
}
}
14 changes: 7 additions & 7 deletions src/makensis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { compilerOutputHandler, compilerErrorHandler, compilerExitHandler, flags
import { getConfig } from 'vscode-get-config';
import { sendTelemetryEvent } from './telemetry';
import * as NSIS from 'makensis';
import vscode from 'vscode';
import { commands, window } from 'vscode';

import {
getMakensisPath,
Expand All @@ -15,7 +15,7 @@ import {
import nsisChannel from './channel';

export async function compile(strictMode: boolean): Promise<void> {
const activeTextEditor = vscode.window?.activeTextEditor;
const activeTextEditor = window?.activeTextEditor;

if (!activeTextEditor) {
return;
Expand All @@ -35,13 +35,13 @@ export async function compile(strictMode: boolean): Promise<void> {

if (isHeaderFile(document.fileName)) {
if (processHeaders === "Disallow") {
const choice = await vscode.window.showWarningMessage('Compiling header files is blocked by default. You can allow it in the package settings, or mute this warning.', 'Open Settings');
const choice = await window.showWarningMessage('Compiling header files is blocked by default. You can allow it in the package settings, or mute this warning.', 'Open Settings');
if (choice === 'Open Settings') {
vscode.commands.executeCommand('workbench.action.openSettings', '@ext:idleberg.nsis processHeaders');
commands.executeCommand('workbench.action.openSettings', '@ext:idleberg.nsis processHeaders');
return;
}
} else if (processHeaders === "Disallow & Never Ask Me") {
vscode.window.setStatusBarMessage("makensis: Skipped header file", 5000);
window.setStatusBarMessage("makensis: Skipped header file", 5000);
return;
}
}
Expand All @@ -50,7 +50,7 @@ export async function compile(strictMode: boolean): Promise<void> {
await document.save();
} catch (error) {
console.error('[vscode-nsis]', error instanceof Error ? error.message : error);
vscode.window.showErrorMessage('Error saving file, see console for details');
window.showErrorMessage('Error saving file, see console for details');
return;
}

Expand Down Expand Up @@ -172,7 +172,7 @@ export async function showHelp(): Promise<void> {
},
await getSpawnEnv()
);
command = await vscode.window.showQuickPick(Object.keys(output.stdout)) || undefined;
command = await window.showQuickPick(Object.keys(output.stdout)) || undefined;

if (command) {
openURL(command);
Expand Down
8 changes: 4 additions & 4 deletions src/nlf.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { sendTelemetryEvent } from './telemetry';
import * as NLF from '@nsis/nlf';
import vscode from 'vscode';
import { workspace, window } from 'vscode';

export function convert(): void {
const editor = vscode.window.activeTextEditor;
const editor = window.activeTextEditor;

if (!editor) {
return;
Expand All @@ -27,7 +27,7 @@ function convertNLF(document): void {
output = NLF.parse(input, { stringify: true });
} catch (err) {
console.error(err);
vscode.window.showErrorMessage('Conversion failed, see output for details');
window.showErrorMessage('Conversion failed, see output for details');
hasErrors = true;
} finally {
sendTelemetryEvent('convertNLF', {
Expand Down Expand Up @@ -58,5 +58,5 @@ function convertJSON(document): void {
}

function openNewFile(newDocument): void {
vscode.workspace.openTextDocument(newDocument).then( document => vscode.window.showTextDocument(document));
workspace.openTextDocument(newDocument).then( document => window.showTextDocument(document));
}
14 changes: 7 additions & 7 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { getConfig } from 'vscode-get-config';
import { getPrefix, inRange } from './util';
import { join } from 'path';
import { promises as fs } from 'fs';
import vscode from 'vscode';
import { workspace, window } from 'vscode';

export async function createTask(): Promise<unknown> {
if (typeof vscode.workspace.workspaceFolders === 'undefined') {
return vscode.window.showErrorMessage('Task support is only available when working on a workspace folder. It is not available when editing single files.');
if (typeof workspace.workspaceFolders === 'undefined') {
return window.showErrorMessage('Task support is only available when working on a workspace folder. It is not available when editing single files.');
}

const { alwaysOpenBuildTask, compiler } = await getConfig('nsis');
Expand Down Expand Up @@ -43,7 +43,7 @@ export async function createTask(): Promise<unknown> {
};

const jsonString = JSON.stringify(taskFile, null, 2);
const dotFolder = join(vscode.workspace.workspaceFolders[0].uri.fsPath, '/.vscode');
const dotFolder = join(workspace.workspaceFolders[0].uri.fsPath, '/.vscode');
const buildFile = join(dotFolder, 'tasks.json');

try {
Expand All @@ -57,12 +57,12 @@ export async function createTask(): Promise<unknown> {
await fs.writeFile(buildFile, jsonString);

} catch(error) {
vscode.window.showErrorMessage(error.toString());
window.showErrorMessage(error.toString());
}

if (alwaysOpenBuildTask === false) return;

// Open tasks.json
const doc = await vscode.workspace.openTextDocument(buildFile)
vscode.window.showTextDocument(doc);
const doc = await workspace.openTextDocument(buildFile)
window.showTextDocument(doc);
}
32 changes: 16 additions & 16 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { platform } from 'os';
import { resolve } from 'path';
import nsisChannel from './channel';
import open from 'open';
import vscode from 'vscode';
import { commands, DiagnosticSeverity, Position, Range, window, workspace } from 'vscode';
import which from 'which';
import type { DiagnosticCollection } from '../types';

Expand Down Expand Up @@ -61,9 +61,9 @@ export async function getMakensisPath(): Promise<string> {
return result;
} catch (error) {
console.error('[vscode-nsis]', error instanceof Error ? error.message : error);
const choice = await vscode.window.showWarningMessage('Please make sure that makensis is installed and exposed in your PATH environment variable. Alternatively, you can specify its path in the settings.', 'Open Settings');
const choice = await window.showWarningMessage('Please make sure that makensis is installed and exposed in your PATH environment variable. Alternatively, you can specify its path in the settings.', 'Open Settings');
if (choice === 'Open Settings') {
vscode.commands.executeCommand('workbench.action.openSettings', '@ext:idleberg.nsis pathToMakensis');
commands.executeCommand('workbench.action.openSettings', '@ext:idleberg.nsis pathToMakensis');
}

console.error('[vscode-nsis]', error instanceof Error ? error.message : error);
Expand Down Expand Up @@ -92,7 +92,7 @@ export function openURL(cmd: string): void {
}

export async function pathWarning(): Promise<void> {
const choice = await vscode.window.showWarningMessage('makensis is not installed or missing in your PATH environmental variable', 'Download', 'Help')
const choice = await window.showWarningMessage('makensis is not installed or missing in your PATH environmental variable', 'Download', 'Help')

switch (choice) {
case 'Download':
Expand Down Expand Up @@ -142,11 +142,11 @@ export async function runInstaller(outFile: string): Promise<void> {
export async function buttonHandler(choice: string, outFile?: string): Promise<void> {
switch (choice) {
case 'Run':
await runInstaller(outFile);
await runInstaller(outFile!);
break;

case 'Reveal':
await revealInstaller(outFile);
await revealInstaller(outFile!);
break;

case 'Show Output':
Expand Down Expand Up @@ -175,7 +175,7 @@ export async function getOverrideCompression(): Promise<string> {
}

export function getLineLength(line: number): number {
const editorText = vscode.window.activeTextEditor?.document.getText();
const editorText = window.activeTextEditor?.document.getText();

if (editorText && editorText.length) {
const lines: string[] = editorText.split('\n');
Expand All @@ -187,11 +187,11 @@ export function getLineLength(line: number): number {
}

export async function showANSIDeprecationWarning(): Promise<void> {
const choice = await vscode.window.showWarningMessage('ANSI targets are deprecated as of NSIS v3.05, consider moving to Unicode. You can mute this warning in the package settings.', 'Unicode Installer', 'Open Settings')
const choice = await window.showWarningMessage('ANSI targets are deprecated as of NSIS v3.05, consider moving to Unicode. You can mute this warning in the package settings.', 'Unicode Installer', 'Open Settings')

switch (choice) {
case 'Open Settings':
vscode.commands.executeCommand('workbench.action.openSettings', '@ext:idleberg.nsis muteANSIDeprecationWarning');
commands.executeCommand('workbench.action.openSettings', '@ext:idleberg.nsis muteANSIDeprecationWarning');
break;

case 'Unicode Installer':
Expand Down Expand Up @@ -238,8 +238,8 @@ export async function findWarnings(input: string): Promise<DiagnosticCollection[
output.push({
code: '',
message: result.groups?.message,
range: new vscode.Range(new vscode.Position(warningLine, 0), new vscode.Position(warningLine, getLineLength(warningLine))),
severity: vscode.DiagnosticSeverity.Warning
range: new Range(new Position(warningLine, 0), new Position(warningLine, getLineLength(warningLine))),
severity: DiagnosticSeverity.Warning
});
}
});
Expand All @@ -265,8 +265,8 @@ export function findErrors(input: string): DiagnosticCollection {
return {
code: '',
message: result?.groups?.message,
range: new vscode.Range(new vscode.Position(errorLine, 0), new vscode.Position(errorLine, getLineLength(errorLine))),
severity: vscode.DiagnosticSeverity.Error
range: new Range(new Position(errorLine, 0), new Position(errorLine, getLineLength(errorLine))),
severity: DiagnosticSeverity.Error
};
}

Expand All @@ -277,13 +277,13 @@ export async function getProjectPath(): Promise<null | string> {
let editor;

try {
editor = vscode.window.activeTextEditor;
editor = window.activeTextEditor;
} catch (err) {
return null;
}

try {
const workspaceFolder = vscode.workspace.getWorkspaceFolder(editor.document.uri);
const workspaceFolder = workspace.getWorkspaceFolder(editor.document.uri);

return workspaceFolder ? workspaceFolder.uri.fsPath : '';
} catch (error) {
Expand All @@ -292,7 +292,7 @@ export async function getProjectPath(): Promise<null | string> {
}

export async function getSpawnEnv(): Promise<SpawnOptions> {
const { integrated } = vscode.workspace.getConfiguration('terminal');
const { integrated } = workspace.getConfiguration('terminal');
const mappedPlatform = mapPlatform();

return {
Expand Down

0 comments on commit c7dd789

Please sign in to comment.