Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize #664

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,431 changes: 3,924 additions & 4,507 deletions package-lock.json

Large diffs are not rendered by default.

41 changes: 20 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"homepage": "https://clangd.llvm.org/",
"icon": "icon.png",
"engines": {
"vscode": "^1.65.0"
"vscode": "^1.75.0"
},
"categories": [
"Programming Languages",
Expand All @@ -35,9 +35,9 @@
"main": "./out/bundle",
"scripts": {
"esbuild": "esbuild ./src/extension.ts --bundle --outfile=out/bundle.js --external:vscode --format=cjs --platform=node",
"vscode:prepublish": "npm run check-ts && npm run esbuild -- --minify --keep-names",
"vscode:prepublish": "npm run prepare && npm run esbuild -- --minify --keep-names",
"compile": "npm run esbuild -- --sourcemap",
"check-ts": "tsc -noEmit -p ./",
"prepare": "tsc -p ./",
"format": "clang-format -i --glob=\"{src,test}/*.ts\"",
"test-compile": "tsc -p ./ && npm run compile",
"test": "npm run test-compile && node ./out/test/index.js",
Expand All @@ -47,25 +47,24 @@
"git-clang-format": "git-clang-format --extensions=ts"
},
"dependencies": {
"@clangd/install": "0.1.17",
"abort-controller": "^3.0.0",
"vscode-languageclient": "8.0.2"
"@clangd/install": "0.1.19",
"vscode-languageclient": "^9.0.1"
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "^7.0.2",
"@types/node": "^6.0.40",
"@types/sinon": "^10.0.16",
"@types/vscode": "1.65.0",
"clang-format": "^1.7.0",
"esbuild": "^0.14.13",
"glob": "^7.1.4",
"mocha": "^9.2.0",
"ovsx": "^0.3.0",
"sinon": "^15.2.0",
"typescript": "^4.5.5",
"vsce": "^2.7.0",
"vscode-test": "^1.3.0"
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.7",
"@types/node": "^22.0.2",
"@types/sinon": "^17.0.3",
"@types/vscode": "1.97.0",
"@vscode/test-electron": "^2.4.1",
"@vscode/vsce": "^3.2.2",
"clang-format": "^1.8.0",
"esbuild": "^0.25.0",
"glob": "^11.0.0",
"mocha": "^11.1.0",
"ovsx": "^0.10.1",
"sinon": "^19.0.2",
"typescript": "^5.5.4"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -404,4 +403,4 @@
]
}
}
}
}
2 changes: 1 addition & 1 deletion src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ASTFeature implements vscodelc.StaticFeature {
'astProvider' in capabilities);
}
getState(): vscodelc.FeatureState { return {kind: 'static'}; }
dispose() {}
clear() {}
}

// Icons used for nodes of particular roles and kinds. (Kind takes precedence).
Expand Down
2 changes: 1 addition & 1 deletion src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class EnableEditsNearCursorFeature implements vscodelc.StaticFeature {
extendedCompletionCapabilities.editsNearCursor = true;
}
getState(): vscodelc.FeatureState { return {kind: 'static'}; }
dispose() {}
clear() {}
}

export class ClangdContext implements vscode.Disposable {
Expand Down
4 changes: 2 additions & 2 deletions src/config-file-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class ConfigFileWatcherFeature implements vscodelc.StaticFeature {
this.context.subscriptions.push(new ConfigFileWatcher(this.context));
}
getState(): vscodelc.FeatureState { return {kind: 'static'}; }
dispose() {}
clear() {}
}

class ConfigFileWatcher implements vscode.Disposable {
private databaseWatcher?: vscode.FileSystemWatcher;
private debounceTimer?: NodeJS.Timer;
private debounceTimer?: NodeJS.Timeout;

dispose() {
if (this.databaseWatcher)
Expand Down
9 changes: 5 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ function substitute<T>(val: T): T {
// If there's no replacement available, keep the placeholder.
return replacement(name) ?? match;
}) as unknown as T;
} else if (Array.isArray(val))
} else if (Array.isArray(val)) {
val = val.map((x) => substitute(x)) as unknown as T;
else if (typeof val === 'object') {
} else if (typeof val === 'object') {
// Substitute values but not keys, so we don't deal with collisions.
const result = {} as {[k: string]: any};
for (let [k, v] of Object.entries(val))
result[k] = substitute(v);
for (const key in val) {
result[key] = substitute(val[key]);
}
val = result as T;
}
return val;
Expand Down
4 changes: 2 additions & 2 deletions src/inactive-regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ export class InactiveRegionsFeature implements vscodelc.StaticFeature {

// clears inactive region decorations on disposal so they don't persist after
// extension is deactivated
dispose() { this.decorationType?.dispose(); }
}
clear() { this.decorationType?.dispose(); }
}
2 changes: 1 addition & 1 deletion src/inlay-hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class InlayHintsFeature implements vscodelc.StaticFeature {
clangdDocumentSelector, new Provider(this.context)));
}
getState(): vscodelc.FeatureState { return {kind: 'static'}; }
dispose() {}
clear() {}
}

class Provider implements vscode.InlayHintsProvider {
Expand Down
8 changes: 7 additions & 1 deletion src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This wraps `@clangd/install` in the VSCode UI. See that package for more.

import * as common from '@clangd/install';
import AbortController from 'abort-controller';
import * as path from 'path';
import * as vscode from 'vscode';

Expand Down Expand Up @@ -57,6 +56,13 @@ class UI {
});
return Promise.resolve(result); // Thenable to real promise.
}
localize(message: string, ...args: Array<string|number|boolean>): string {
let ret = message;
for (const i in args) {
ret.replace(`{${i}}`, args[i].toString());
}
return ret;
}
error(s: string) { vscode.window.showErrorMessage(s); }
info(s: string) { vscode.window.showInformationMessage(s); }
command(name: string, body: () => any) {
Expand Down
2 changes: 1 addition & 1 deletion src/memory-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class MemoryUsageFeature implements vscodelc.StaticFeature {
'memoryUsageProvider' in capabilities);
}
getState(): vscodelc.FeatureState { return {kind: 'static'}; }
dispose() {}
clear() {}
}

class TreeAdapter implements vscode.TreeDataProvider<InternalTree> {
Expand Down
4 changes: 2 additions & 2 deletions src/type-hierarchy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class TypeHierarchyFeature implements vscodelc.StaticFeature {
!serverCapabilities.standardTypeHierarchyProvider) {
// Disable mis-guided support for standard type-hierarchy feature.
this.context.client.getFeature('textDocument/prepareTypeHierarchy')
.dispose();
.clear();
this.serverSupportsTypeHierarchy = true;
this.recomputeEnableTypeHierarchy();
} else {
Expand All @@ -136,7 +136,7 @@ class TypeHierarchyFeature implements vscodelc.StaticFeature {
}
}
getState(): vscodelc.FeatureState { return {kind: 'static'}; }
dispose() {}
clear() {}

private recomputeEnableTypeHierarchy() {
if (this.state === vscodelc.State.Running) {
Expand Down
32 changes: 10 additions & 22 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
// Entry point for all tests.
// Spawns VSCode with our extension, and then runs *.test.ts in that context.

import * as glob from 'glob';
import {runTests} from '@vscode/test-electron';
import {glob} from 'glob';
import * as Mocha from 'mocha';
import * as path from 'path';
import {runTests} from 'vscode-test';

// The entry point under VSCode - find the test files and run them in Mocha.
export function run(): Promise<void> {
export async function run(): Promise<void> {
const mocha = new Mocha({ui: 'tdd', color: true});
const testsRoot = path.resolve(__dirname, '..');

return new Promise((c, e) => {
glob('**/**.test.js', {cwd: testsRoot}, (err, files) => {
if (err) {
return e(err);
}
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
const files = await glob('**/**.test.ts', {cwd: testsRoot});
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));

try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
e(err);
}
});
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
throw new Error(`${failures} tests failed.`);
}
});
}

Expand Down