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

Add typechecking for TypeScript #946

Merged
merged 24 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ba1c002
feat: use the typescript-language-server for TS
vixalien Jun 18, 2024
892a4ce
feat: add the gi-types submodule
vixalien Jun 18, 2024
cb3defd
feat: use the gi-types for GTK types
vixalien Jun 18, 2024
3c7bf25
feat: add lspc to typescript codeview
vixalien Jun 18, 2024
0f2dbe7
chore: dont save/restore state with the Typescript LSP
vixalien Jun 18, 2024
7555fd0
chore: remove the gi-types path from tsconfig
vixalien Jun 18, 2024
dd2c241
fix: the LSPClient using a one-based position.character
vixalien Jun 18, 2024
ebd62de
chore: return name of copied files in `copy`/`copyDirectory`
vixalien Jun 20, 2024
985742e
feat: notify the LSP after setting up typescript project
vixalien Jun 20, 2024
cde5bfa
chore: add commented types for the global workbench object
vixalien Jul 2, 2024
2df4d72
chore: move `gi-types` submodules from template folder
vixalien Jul 3, 2024
e3ac8f5
feat: dont copy over all types
vixalien Jul 3, 2024
ac6078e
chore: make notify tsconfig message clearer
vixalien Jul 3, 2024
81a94e3
chore: return `Gio.FIle` from `copy`
vixalien Jul 3, 2024
f8a4f69
chore: use single meson.build for typescript
vixalien Jul 3, 2024
080c898
chore: fix unwanted change
vixalien Jul 3, 2024
9a9ac53
chore: add TODO when for fixing ambient.d.ts
vixalien Jul 3, 2024
8868eff
chore: use correct notify for tsconfig change
vixalien Jul 3, 2024
75531a0
chore: revery util.js changes
vixalien Jul 3, 2024
a06b0ec
chore: remove unnecessary change
vixalien Jul 3, 2024
6aad42a
Merge branch 'main' into wip/vixalien/typechecking
sonnyp Jul 3, 2024
b3bdeb9
Merge branch 'main' into wip/vixalien/typechecking
sonnyp Jul 6, 2024
e3553d6
Use pkgdatadir in tsconfig.json
sonnyp Jul 6, 2024
3c4dc9d
fix make ci
sonnyp Jul 6, 2024
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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
[submodule "blueprint-compiler"]
path = blueprint-compiler
url = https://gitlab.gnome.org/jwestman/blueprint-compiler.git
[submodule "src/langs/typescript/template/gi-types"]
path = src/langs/typescript/template/gi-types
url = https://gitlab.gnome.org/BrainBlasted/gi-typescript-definitions.git
branch = nightly
9 changes: 1 addition & 8 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,7 @@ export const languages = [
document: null,
default_file: "main.ts",
index: 4,
language_server: [
"biome",
"lsp-proxy",
// src/meson.build installs biome.json there
GLib.getenv("FLATPAK_ID")
? `--config-path=${pkg.pkgdatadir}`
: `--config-path=src/langs/typescript`,
],
language_server: ["typescript-language-server", "--stdio"],
formatting_options: {
...formatting_options,
tabSize: 2,
Expand Down
6 changes: 1 addition & 5 deletions src/langs/typescript/TypeScriptDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export class TypeScriptDocument extends Document {
super(...args);

this.lspc = setup({ document: this });
this.code_view.lspc = this.lspc;
}

vixalien marked this conversation as resolved.
Show resolved Hide resolved
async format() {
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_formatting
const text_edits = await this.lspc.request("textDocument/formatting", {
Expand All @@ -25,10 +25,6 @@ export class TypeScriptDocument extends Document {
},
});

// Biome doesn't support diff - it just returns one edit
// we don't want to loose the cursor position so we use this
const state = this.code_view.saveState();
applyTextEdits(text_edits, this.buffer);
await this.code_view.restoreState(state);
vixalien marked this conversation as resolved.
Show resolved Hide resolved
}
}
1 change: 1 addition & 0 deletions src/langs/typescript/template/gi-types
Submodule gi-types added at 396fe1
5 changes: 4 additions & 1 deletion src/langs/typescript/template/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
install_data(['types/ambient.d.ts', 'types/gi-module.d.ts', 'tsconfig.json'],
install_data(['types/ambient.d.ts', 'tsconfig.json'],
install_dir : join_paths(pkgdatadir, 'langs/typescript/template'),
preserve_path: true)

install_subdir('gi-types',
install_dir : join_paths(pkgdatadir, 'langs/typescript/template'))
8 changes: 5 additions & 3 deletions src/langs/typescript/template/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
// currently supported by the latest GJS
"target": "ESNext",
"outDir": "compiled_javascript",
"baseUrl": ".",
"paths": {
"gi://*": ["./types/gi-module.d.ts"]
}
"*": ["*", "types/*"]
},
"skipLibCheck": true
},
"include": ["main.ts", "types/ambient.d.ts", "types/gi-module.d.ts"]
"include": ["main.ts", "types/ambient.d.ts", "gi-types/gi.d.ts"]
}
6 changes: 0 additions & 6 deletions src/langs/typescript/template/types/gi-module.d.ts

This file was deleted.

16 changes: 7 additions & 9 deletions src/langs/typescript/typescript.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Gio from "gi://Gio";

import { createLSPClient } from "../../common.js";
import { getLanguage, copy } from "../../util.js";
import { copy, copyDirectory, ensureDir, getLanguage } from "../../util.js";
import { isTypeScriptEnabled } from "../../Extensions/Extensions.js";

export function setup({ document }) {
Expand Down Expand Up @@ -42,10 +42,10 @@ const typescript_template_dir = Gio.File.new_for_path(

export async function setupTypeScriptProject(destination) {
const types_destination = destination.get_child("types");
ensureDir(types_destination);

if (!types_destination.query_exists(null)) {
types_destination.make_directory_with_parents(null);
}
const gi_types_destination = destination.get_child("gi-types");
ensureDir(gi_types_destination);

return Promise.all([
copy(
Expand All @@ -54,11 +54,9 @@ export async function setupTypeScriptProject(destination) {
types_destination,
Gio.FileCopyFlags.NONE,
),
copy(
"types/gi-module.d.ts",
typescript_template_dir,
types_destination,
Gio.FileCopyFlags.NONE,
copyDirectory(
typescript_template_dir.get_child("gi-types"),
gi_types_destination,
),
copy(
"tsconfig.json",
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/LSPClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export default class LSPClient {
},
position: {
line: iter_cursor.get_line(),
character: iter_cursor.get_line_offset() - 1,
character: iter_cursor.get_line_offset(),
vixalien marked this conversation as resolved.
Show resolved Hide resolved
},
});

Expand Down
Loading