Skip to content

Commit

Permalink
Formatted all code with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
dpar39 committed Dec 2, 2024
1 parent 78a7df4 commit aa3bec4
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 42 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"test-watch": "tsc -watch -p ./",
"pretest": "npm run test-compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "xvfb-run -a node ./out/test/runTest.js"
"test": "xvfb-run -a node ./out/test/runTest.js",
"format": "npx prettier --write './**/*.{js,jsx,mjs,cjs,ts,tsx}'"
},
"devDependencies": {
"@types/glob": "^7.1.6",
Expand Down
10 changes: 5 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const startHttpServer = async (
context: vscode.ExtensionContext,
host: string,
port: number,
fallbackPorts: number[]
fallbackPorts: number[],
): Promise<void> => {
let isInUse = false;
if (port) {
Expand Down Expand Up @@ -127,15 +127,15 @@ const startHttpServer = async (
function getDefaultPortForWorkspace(): number {
const identifier = vscode.workspace.workspaceFile
? vscode.workspace.workspaceFile.toString()
: vscode.workspace.workspaceFolders?.map(f => f.uri.toString()).join("");
: vscode.workspace.workspaceFolders?.map((f) => f.uri.toString()).join("");
if (!identifier) {
return 37100;
}
const hash = identifier.split("").reduce((a: number, b: string) => {
a = (a << 5) - a + b.charCodeAt(0);
return a & a;
}, 0);
const port = 37100 + (Math.abs(hash) % (65535-37100));
const port = 37100 + (Math.abs(hash) % (65535 - 37100));
return port;
}

Expand All @@ -149,7 +149,7 @@ function httpPortToPid(context: vscode.ExtensionContext, port: number): string {

function killPreviousVscodeProcessIfUsingTcpPort(
context: vscode.ExtensionContext,
port: number | undefined
port: number | undefined,
) {
Logger.info(`Checking if we need to kill previous process using port = ${port}`);
if (!port) {
Expand Down Expand Up @@ -188,7 +188,7 @@ function setupRestControl(context: vscode.ExtensionContext) {
context,
"127.0.0.1",
port,
(fallbackPorts || []).filter((p: number) => p !== port)
(fallbackPorts || []).filter((p: number) => p !== port),
);
Logger.info("VSCode REST Control is now active!");
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/services/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function registerExternalFormatter(
formatterEndpoint: string,
languages: string[],
httpMethod: string,
onErrorMessage: string
onErrorMessage: string,
) {
languages = languages || (await vscode.languages.getLanguages());
httpMethod = httpMethod || "POST";
Expand All @@ -21,7 +21,7 @@ export async function registerExternalFormatter(
const url = new URL(formatterEndpoint);
formatterRegistration = vscode.languages.registerDocumentFormattingEditProvider(languages, {
provideDocumentFormattingEdits(
doc: vscode.TextDocument
doc: vscode.TextDocument,
): vscode.ProviderResult<vscode.TextEdit[]> {
const payload = JSON.stringify({
file: doc.fileName,
Expand All @@ -40,7 +40,7 @@ export async function registerExternalFormatter(
};
const range = new vscode.Range(
doc.lineAt(0).range.start,
doc.lineAt(doc.lineCount - 1).range.end
doc.lineAt(doc.lineCount - 1).range.end,
);
return new Promise((accept, reject) => {
const httpModule = url.protocol.startsWith("https") ? https : http;
Expand All @@ -56,7 +56,7 @@ export async function registerExternalFormatter(
accept([]); // no edits
vscode.window.showErrorMessage(
`Failed to format document with custom formatter: ${err}`,
"OK"
"OK",
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/services/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class Logger {
}

Logger.channel?.appendLine(
`["${type}" - ${new Date().getHours()}:${new Date().getMinutes()}] ${message}`
`["${type}" - ${new Date().getHours()}:${new Date().getMinutes()}] ${message}`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/quickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function quickPick(data: any) {
picker.onDidHide(() => {
resolve(picker.selectedItems);
disposable.dispose();
})
}),
);
for (const item of picker.items) {
if (item.label === defaultLabel) {
Expand Down
18 changes: 12 additions & 6 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,37 @@ import { EXTENSION_ID } from "../../extension";
import { makeRequest } from "./sendPostRequest";

suite("Extension Test Suite", () => {
suiteSetup(async () => { });
suiteSetup(async () => {});

suiteTeardown(async () => { });
suiteTeardown(async () => {});

test("check can list extensions", async () => {
const extensionIds: string[] = (await makeRequest("custom.listInstalledExtensions")) as string[];
const extensionIds: string[] = (await makeRequest(
"custom.listInstalledExtensions",
)) as string[];
assert(extensionIds.includes(EXTENSION_ID));
}).timeout(5000);

test("get workspace folders", async () => {
const workspaceFolders = (await makeRequest("custom.workspaceFolders")) as string[];
assert(workspaceFolders.length === 1);
const ws = workspaceFolders[0] as any;
assert(ws.name === 'workspace1');
assert(ws.name === "workspace1");
assert(ws.index === 0);
assert(ws.uri.startsWith("file://"));
assert(ws.uri.endsWith("/workspace1"));

const workspaceFile = await makeRequest("custom.workspaceFile", undefined, undefined, false) as any;
const workspaceFile = (await makeRequest(
"custom.workspaceFile",
undefined,
undefined,
false,
)) as any;
assert(workspaceFile === null); // no workspace file
});

test("get all commands registred in vscode", async () => {
const commands: string[] = (await makeRequest("custom.getCommands")) as string[];
assert(commands.length > 100);
});

});
8 changes: 4 additions & 4 deletions src/test/suite/sendPostRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ export async function makeRequest(
command: string,
args: any[] = [],
port: number = 0,
urlEncoded = true
urlEncoded = true,
) {
return new Promise((resolve, reject) => {
const path = urlEncoded
? `/?command=${command}&args=${encodeURIComponent(JSON.stringify(args))}`
: '/';
: "/";
const req = http.request(
{
method: "POST",
hostname: "localhost",
port: port || getListeningPort(),
path: path
path: path,
},
(res) => {
const chunks: any[] = [];
Expand All @@ -25,7 +25,7 @@ export async function makeRequest(
const resBody = Buffer.concat(chunks);
resolve(JSON.parse(resBody.toString()));
});
}
},
);
req.on("error", reject);
if (!urlEncoded) {
Expand Down
40 changes: 20 additions & 20 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
//@ts-check

'use strict';
"use strict";

const path = require('path');
const path = require("path");

/**@type {import('webpack').Configuration}*/
const config = {
target: 'node', // vscode extensions run in a Node.js-context πŸ“– -> https://webpack.js.org/configuration/node/
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
target: "node", // vscode extensions run in a Node.js-context πŸ“– -> https://webpack.js.org/configuration/node/
mode: "none", // this leaves the source code as close as possible to the original (when packaging we set this to 'production')

entry: './src/extension.ts', // the entry point of this extension, πŸ“– -> https://webpack.js.org/configuration/entry-context/
entry: "./src/extension.ts", // the entry point of this extension, πŸ“– -> https://webpack.js.org/configuration/entry-context/
output: {
// the bundle is stored in the 'dist' folder (check package.json), πŸ“– -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, 'out'),
filename: 'extension.js',
libraryTarget: 'commonjs2'
path: path.resolve(__dirname, "out"),
filename: "extension.js",
libraryTarget: "commonjs2",
},
devtool: 'nosources-source-map',
devtool: "nosources-source-map",
externals: {
bufferutil: 'bufferutil',
'utf-8-validate': 'commonjs utf-8-validate',
vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, πŸ“– -> https://webpack.js.org/configuration/externals/
bufferutil: "bufferutil",
"utf-8-validate": "commonjs utf-8-validate",
vscode: "commonjs vscode", // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, πŸ“– -> https://webpack.js.org/configuration/externals/
},
resolve: {
// support reading TypeScript and JavaScript files, πŸ“– -> https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js']
extensions: [".ts", ".js"],
},
module: {
rules: [
Expand All @@ -33,11 +33,11 @@ const config = {
exclude: /node_modules/,
use: [
{
loader: 'ts-loader'
}
]
}
]
}
loader: "ts-loader",
},
],
},
],
},
};
module.exports = config;
module.exports = config;

0 comments on commit aa3bec4

Please sign in to comment.