Skip to content

Commit

Permalink
Greatly cleanup and works towards ESM (#32)
Browse files Browse the repository at this point in the history
* Revert "Add Vitest for unit tests (#30)"

This reverts commit 52aa813.

* Revert "Remove dupe config file (#31)"

This reverts commit aae4f9e.

* Remove rootDirs from client

* Remove rootDirs from server

* Add compile-ts to client

* Resolve modules via NodeNext

* Make client an ESM module

* Add compile-ts to server

* Update module resolution of server

* Make server an ESM module

* Use bundler resolution in client

* Remove unused tsconfig.json

* Use NodeNext for compatibility with AHK++

* Add logs

* Progress

* ESM but still not quite working

* More CJS building

* Fix clean

* Use server.cjs

* Further cleanup

* Ignore extension.cts when prettifying
  • Loading branch information
mark-wiemer authored Sep 28, 2024
1 parent aae4f9e commit b10a3ed
Show file tree
Hide file tree
Showing 42 changed files with 189 additions and 2,073 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ node_modules
*.vsix
scripts/*
*.js
*.cjs
*.js.map
*.tsbuildinfo
**/dist/**/*.d.ts

# Vitest
coverage
**/dist/**/*.d.ts
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ scripts/*
server/expr_parser/*

client/src/browserClientMain.ts
client/src/extension.ts
client/src/extension.cts
client/src/test/utils.ts
server/src/ahkProvider.ts
server/src/browserServerMain.ts
Expand Down
19 changes: 0 additions & 19 deletions .vscode-test.mjs

This file was deleted.

3 changes: 1 addition & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"recommendations": [
"aaron-bond.better-comments",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"vitest.explorer"
"esbenp.prettier-vscode"
]
}
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"env": {
"VSCODE_AHK_SERVER_PATH": "server/dist/server.js",
"VSCODE_AHK_SERVER_PATH": "server/dist/server.cjs",
"SYNTAXES_PATH": "syntaxes"
},
"outFiles": ["${workspaceFolder}/client/dist/**/*.js"],
Expand Down
40 changes: 0 additions & 40 deletions .vscode/snippets.code-snippets

This file was deleted.

6 changes: 3 additions & 3 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ console.log(
build({
entryPoints: [path.join('./server/src/server.ts')],
bundle: true,
outfile: path.join('./server/dist/server.js'),
outfile: path.join('./server/dist/server.cjs'),
external: ['vscode'],
format: 'cjs',
platform: 'node',
Expand All @@ -25,9 +25,9 @@ build({
// Node client (not necessary for AHK++, but super fast)
// https://esbuild.github.io/api
build({
entryPoints: [path.join('./client/src/extension.ts')],
entryPoints: [path.join('./client/src/extension.cts')],
bundle: true,
outfile: path.join('./client/dist/extension.js'),
outfile: path.join('./client/dist/extension.cjs'),
external: ['vscode'],
format: 'cjs',
platform: 'node',
Expand Down
4 changes: 4 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"description": "VSCode part of a language server",
"license": "MIT",
"version": "0.0.1",
"type": "module",
"scripts": {
"compile-ts": "tsc"
},
"engines": {
"vscode": "^1.43.0"
}
Expand Down
127 changes: 0 additions & 127 deletions client/src/browserClientMain.ts

This file was deleted.

File renamed without changes.
39 changes: 35 additions & 4 deletions client/src/extension.ts → client/src/extension.cts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ import {
LanguageClientOptions,
ServerOptions,
TransportKind
} from 'vscode-languageclient/node';
} from 'vscode-languageclient/node.js';
import { resolve } from 'path';
import { ChildProcess, execSync, spawn } from 'child_process';
import { readdirSync, readFileSync, lstatSync, readlinkSync, unlinkSync, writeFileSync } from 'fs';
import { CfgKey, getAhkppConfig, getCfg, ShowOutput } from './config';
import { resolvePath } from './utils';
import { CfgKey, getAhkppConfig, getCfg, ShowOutput } from './config.cjs';

let client: LanguageClient, outputchannel: OutputChannel, ahkStatusBarItem: StatusBarItem;
const ahkprocesses = new Map<number, ChildProcess & { path?: string }>();
let v2Interpreter = getCfg<string>(CfgKey.InterpreterPathV2), server_is_ready = false
const textdecoders: TextDecoder[] = [new TextDecoder('utf8', { fatal: true }), new TextDecoder('utf-16le', { fatal: true })];
const isWindows = process.platform === 'win32';
let extlist: string[] = [], debugexts: Record<string, string> = {}, langs: string[] = [];
const loadedCollection = {
'ahk2.browse': 'Browse your file system to find AutoHotkey2 interpreter',
Expand All @@ -61,8 +61,11 @@ const loadedCollection = {
};

export function activate(context: ExtensionContext): Promise<LanguageClient> {
// when debugging, this goes into the Debug Console (Ctrl + Shift + Y)
console.log('Activating AHK v2 language server');

/** Absolute path to `server.js` */
const defaultServerModule = context.asAbsolutePath(`ahk2/server/dist/server.js`);
const defaultServerModule = context.asAbsolutePath(`ahk2/server/dist/server.cjs`);
const serverModule = process.env.VSCODE_AHK_SERVER_PATH ? context.asAbsolutePath(process.env.VSCODE_AHK_SERVER_PATH) : defaultServerModule;

// If the extension is launched in debug mode then the debug server options are used
Expand Down Expand Up @@ -623,6 +626,34 @@ async function onDidChangegetInterpreter() {
}
}

/**
* Returns the provided path as an absolute path.
* Resolves the provided path against the provided workspace.
* Resolves symbolic links by default.
* Returns empty string if resolution fails.
*/
export function resolvePath(path: string | undefined, workspace?: string, resolveSymbolicLink = true): string {
if (!path)
return '';
const paths: string[] = [];
// If the path does not contain a colon, resolve it relative to the workspace
if (!path.includes(':'))
paths.push(resolve(workspace ?? '', path));
// If there are no slashes or backslashes in the path and the platform is Windows
if (!/[\\/]/.test(path) && isWindows)
paths.push(execSync(`where ${path}`, { encoding: 'utf-8' }).trim());
paths.push(path);
for (let path of paths) {
if (!path) continue;
try {
if (lstatSync(path).isSymbolicLink() && resolveSymbolicLink)
path = resolve(path, '..', readlinkSync(path));
return path;
} catch { }
}
return '';
}

/**
* Returns whether the given path exists.
* Only returns false if lstatSync give an ENOENT error.
Expand Down
Loading

0 comments on commit b10a3ed

Please sign in to comment.