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

fmt: remove gts and use prettier #19

Merged
merged 2 commits into from
Feb 5, 2024
Merged
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
11 changes: 4 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module.exports = {
root: true,
extends: ['./node_modules/gts/'],
extends: ["plugin:prettier/recommended"],
ignorePatterns: [
'node_modules', // Self-explanatory.
'out', // Don't lint built library.
"kanata",
"kanata-local",
],
overrides: [
{
Expand All @@ -13,12 +15,7 @@ module.exports = {
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
parserOptions: {
tsconfigRootDir: __dirname,
project: [
'./client/tsconfig.json',
'./server/tsconfig.json',
'./test/tsconfig.json',
],
project: true,
},
},
],
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"rust-analyzer.cargo.target": "wasm32-unknown-unknown",
"rust-analyzer.cargo.features": "all",
"todo-tree.tree.showBadges": false,
"eslint.format.enable": true,
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
}
65 changes: 34 additions & 31 deletions client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */

import { platform } from 'os';
import { platform } from "os";

import { join } from 'path';
import { join } from "path";

import {
ExtensionContext,
Expand All @@ -16,39 +16,39 @@ import {
FileSystemWatcher,
commands,
ConfigurationTarget,
} from 'vscode';
} from "vscode";
import {
LanguageClient,
LanguageClientOptions,
SettingMonitor,
TransportKind,
MessageActionItem,
} from 'vscode-languageclient/node';
} from "vscode-languageclient/node";

const extensionName = 'Kanata Configuration Language';
const extensionName = "Kanata Configuration Language";
const outputChannel = window.createOutputChannel(extensionName);

// global extension instance
let ext: Extension;

export async function activate(ctx: ExtensionContext): Promise<void> {
const cmd1 = commands.registerCommand(
'vscode-kanata.setSetCurrentFileAsMain',
"vscode-kanata.setSetCurrentFileAsMain",
async () => {
const editor = window.activeTextEditor;
if (editor) {
const fileName = editor.document.fileName;
const cfg = workspace.getConfiguration();
await cfg.update(
'vscode-kanata.mainConfigFile',
"vscode-kanata.mainConfigFile",
fileName,
ConfigurationTarget.Workspace,
);
// await window.showInformationMessage(
// `Set vscode-kanata.mainConfigFile to ${fileName}`
// );
} else {
await window.showErrorMessage('No active editor');
await window.showErrorMessage("No active editor");
}
},
);
Expand Down Expand Up @@ -85,7 +85,7 @@ class Extension implements Disposable {
if (openedWorkspaces) {
if (openedWorkspaces.length >= 2) {
await window.showInformationMessage(
'Multiple workspaces are currently not supported, only the first workspaces folder will be regarded.',
"Multiple workspaces are currently not supported, only the first workspaces folder will be regarded.",
);
}
root = openedWorkspaces.at(0);
Expand All @@ -106,7 +106,7 @@ class Extension implements Disposable {
}

async startClient(root: WorkspaceFolder | undefined) {
const serverModulePath = this.ctx.asAbsolutePath(join('out', 'server.js'));
const serverModulePath = this.ctx.asAbsolutePath(join("out", "server.js"));

let deleteWatcher: FileSystemWatcher | undefined = undefined;
let changeWatcher: FileSystemWatcher | undefined = undefined;
Expand Down Expand Up @@ -143,7 +143,7 @@ class Extension implements Disposable {

const clientOpts: LanguageClientOptions = {
documentSelector: [
{ scheme: 'file', language: 'kanata', pattern: '**/*.kbd' },
{ scheme: "file", language: "kanata", pattern: "**/*.kbd" },
],
synchronize: { fileEvents: deleteWatcher },
diagnosticCollectionName: extensionName,
Expand All @@ -152,10 +152,10 @@ class Extension implements Disposable {
initializationOptions: {
mainConfigFile: workspace
.getConfiguration()
.get<string>('vscode-kanata.mainConfigFile', ''),
.get<string>("vscode-kanata.mainConfigFile", ""),
includesAndWorkspaces: workspace
.getConfiguration()
.get<string>('vscode-kanata.includesAndWorkspaces', ''),
.get<string>("vscode-kanata.includesAndWorkspaces", ""),
localKeysVariant: localKeysVariant as string,
format: getFormatterSettings(),
},
Expand All @@ -177,8 +177,8 @@ class Extension implements Disposable {

restart() {
return async (e: ConfigurationChangeEvent) => {
if (e.affectsConfiguration('vscode-kanata')) {
outputChannel.appendLine('vscode-kanata configuration has changed!');
if (e.affectsConfiguration("vscode-kanata")) {
outputChannel.appendLine("vscode-kanata configuration has changed!");
await this.stop();
this.dispose();
outputChannel.clear();
Expand All @@ -199,7 +199,7 @@ class Extension implements Disposable {
}

function kanataFilesInFolderPattern(folder: Uri) {
return new RelativePattern(folder, '**/*.kbd');
return new RelativePattern(folder, "**/*.kbd");
}

async function openKanataFilesInFolder(folder: Uri) {
Expand All @@ -219,49 +219,52 @@ async function openDocument(uri: Uri) {
async function showLocalkeysManualInterventionNeeded() {
const message =
"Cannot select `deflocalkeys` variant automatically. Please go to extension settings and select it manually.";
const openSettingsAction: MessageActionItem = { title: 'Open Settings' };
const openSettingsAction: MessageActionItem = { title: "Open Settings" };

await window
.showInformationMessage(message, openSettingsAction)
.then(async (selectedAction) => {
if (selectedAction === openSettingsAction) {
await commands.executeCommand(
'workbench.action.openSettings',
'vscode-kanata.localKeysVariant',
"workbench.action.openSettings",
"vscode-kanata.localKeysVariant",
);
}
});
}

type LocalKeysVariant = 'deflocalkeys-win' | 'deflocalkeys-wintercept' | 'deflocalkeys-linux' | 'deflocalkeys-macos';
type LocalKeysVariant =
| "deflocalkeys-win"
| "deflocalkeys-wintercept"
| "deflocalkeys-linux"
| "deflocalkeys-macos";

// Gets localkeys variant from config and when set to auto, detects it based on current OS.
function getLocalKeysVariant(): LocalKeysVariant {
const localKeysVariant = workspace
.getConfiguration()
.get<string>('vscode-kanata.localKeysVariant', '');
.get<string>("vscode-kanata.localKeysVariant", "");

if (localKeysVariant == 'auto') {
if (localKeysVariant == "auto") {
switch (platform()) {
case 'linux':
return 'deflocalkeys-linux';
case 'darwin':
return 'deflocalkeys-macos';
case "linux":
return "deflocalkeys-linux";
case "darwin":
return "deflocalkeys-macos";
default: // Catches both unsupported systems as well as windows, since there are 2 possible variants for windows.
showLocalkeysManualInterventionNeeded()
.then(null)
.catch((e) => {
outputChannel.appendLine(`error: ${e}`);
});
// Use 'deflocalkeys-win' as a fallback, since that's the most common variant, I guess.
return 'deflocalkeys-win'
return "deflocalkeys-win";
}
}

return localKeysVariant as LocalKeysVariant;
}


interface FormatterSettings {
enable: boolean;
useDefsrcLayoutOnDeflayers: boolean;
Expand All @@ -270,13 +273,13 @@ interface FormatterSettings {
function getFormatterSettings(): FormatterSettings {
const formatSettings = workspace
.getConfiguration()
.get<FormatterSettings>('vscode-kanata.format');
.get<FormatterSettings>("vscode-kanata.format");

if (formatSettings === undefined) {
throw new Error('should be defined')
throw new Error("should be defined");
}

console.log("formatSettings:", formatSettings)
console.log("formatSettings:", formatSettings);

return formatSettings;
}
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@
"package": "vsce package --yarn --githubBranch main --out kanata.vsix",
"publish": "vsce publish --yarn --githubBranch main --packagePath kanata.vsix",
"typecheck": "tsc --noEmit",
"fix": "gts fix",
"lint": "gts lint -- . --max-warnings 0",
"fmtwrite": "prettier --write 'client/**/*.ts' 'server/**/*.ts' 'test/**/*.ts'",
"fmtcheck": "prettier --check 'client/**/*.ts' 'server/**/*.ts' 'test/**/*.ts'",
"test": "tsc --build test && yarn esbuild-all && node ./out/test/src/runTest.js",
Expand All @@ -133,19 +131,18 @@
"vscode-languageserver": "^8.1.0"
},
"devDependencies": {
"@types/glob": "^8.1.0",
"@types/jest": "^29.5.3",
"@types/lodash": "^4.14.196",
"@types/node": "^20.4.6",
"@types/semver": "^7.5.0",
"@types/vscode": "^1.80.0",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"@vscode/test-electron": "^2.3.4",
"@vscode/vsce": "^2.20.0",
"esbuild": "^0.18.17",
"glob": "^10.3.3",
"gts": "^5.0.0",
"jest": "^29.6.2",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "3.2.5",
"semver": "^7.5.4",
"typescript": "^5.1.6"
"typescript": "^5.3.3"
}
}
10 changes: 6 additions & 4 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
TextDocumentSyncKind,
InitializeParams,
PositionEncodingKind,
} from 'vscode-languageserver/node';
import { KanataLanguageServer } from '../../out/kls'; // eslint-disable-line node/no-unpublished-import
} from "vscode-languageserver/node";
import { KanataLanguageServer } from "../../out/kls";

// Create LSP connection
const connection = createConnection(ProposedFeatures.all);
Expand All @@ -18,7 +18,9 @@ connection.onInitialize((params: InitializeParams) => {
const kls = new KanataLanguageServer(params, sendDiagnosticsCallback);

connection.onNotification((...args) => kls.onNotification(...args));
connection.onDocumentFormatting((...args) => kls.onDocumentFormatting(...args));
connection.onDocumentFormatting((...args) =>
kls.onDocumentFormatting(...args),
);

return {
capabilities: {
Expand All @@ -35,7 +37,7 @@ connection.onInitialize((params: InitializeParams) => {
workspaceFolders: { supported: false },
fileOperations: {
didDelete: {
filters: [{ pattern: { /* matches: 'folder', */ glob: '**' } }],
filters: [{ pattern: { /* matches: 'folder', */ glob: "**" } }],
},
},
},
Expand Down
19 changes: 10 additions & 9 deletions test/src/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { resolve } from 'path';
import { resolve } from "path";

import { runTests } from '@vscode/test-electron'; // eslint-disable-line node/no-unpublished-import
import { minVersion } from 'semver'; // eslint-disable-line node/no-unpublished-import
import { runTests } from "@vscode/test-electron";
import { minVersion } from "semver";

import { engines } from '../../package.json';
import { engines } from "../../package.json";

void (async function () {
try {
Expand All @@ -12,20 +12,21 @@ void (async function () {
const minSupportedVSCodeVersion =
minVersion(engines.vscode)?.toString() || engines.vscode;

const extensionDevelopmentPath = resolve(__dirname, '../../..');
const extensionTestsPath = resolve(__dirname, './suite');
const extensionDevelopmentPath = resolve(__dirname, "../../..");
const extensionTestsPath = resolve(__dirname, "./suite");
const workspace = resolve(
__dirname,
'../../../test-fixtures/workspace/test.code-workspace',
"../../../test-fixtures/workspace/test.code-workspace",
);

await runTests({
version: minSupportedVSCodeVersion,
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [workspace, '--disable-extensions', '--disable-telemetry'],
launchArgs: [workspace, "--disable-extensions", "--disable-telemetry"],
});
} catch (e) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
console.error(`====== ERROR ======\n${e}\n==================`);
process.exitCode = 1;
}
Expand Down
37 changes: 29 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,41 @@
"composite": true,
"esModuleInterop": true,
"isolatedModules": true,
"lib": ["ES2019"],
"lib": [
"ES2019"
],
"module": "commonjs",
"outDir": "out",
"resolveJsonModule": true,
"rootDir": ".",
"sourceMap": true,
"target": "es2019"
"target": "ES2022",
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"declaration": true,
"forceConsistentCasingInFileNames": true,
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"pretty": true,
"strict": true,
},
"exclude": ["./node_modules", "./out"],
"extends": "./node_modules/gts/tsconfig-google.json",
"exclude": [
"./node_modules",
"./out",
"kanata",
"kanata-local"
],
"include": [],
"references": [
{ "path": "./client" },
{ "path": "./server" },
{ "path": "./test" }
{
"path": "./client"
},
{
"path": "./server"
},
{
"path": "./test"
}
]
}
}
Loading
Loading