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

Start on supporting autoimports #46

Merged
merged 42 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a38c647
Start on supporting autoimports
tmcw Dec 11, 2024
6642c7a
Remove unused import
tmcw Dec 11, 2024
e47f70d
move state to peer dep
tmcw Dec 11, 2024
a384128
Bump tshy, render displayParts
tmcw Dec 11, 2024
9cabe77
Update to TypeScript latest, start testing
tmcw Dec 12, 2024
7c46eeb
Start moving away from tshy
tmcw Dec 12, 2024
0772860
Simplify tsconfig
tmcw Dec 12, 2024
b4c703e
Enable coverage and coverage reporting
tmcw Dec 12, 2024
c0874b7
Add explicit reporters
tmcw Dec 12, 2024
0765551
Add getHover test
tmcw Dec 12, 2024
8817e7e
Split out codeAction mapper
tmcw Dec 12, 2024
d31779c
Create test helper
tmcw Dec 12, 2024
013a939
Use getEnv in getHover
tmcw Dec 12, 2024
d1f3efe
Add test for getLints
tmcw Dec 12, 2024
6de366f
Update tsconfig to ignore test files
tmcw Dec 12, 2024
cc22821
Add tsSync test
tmcw Dec 12, 2024
5a3b5f5
Add biome
tmcw Dec 12, 2024
3e0c781
Ban console.log
tmcw Dec 12, 2024
1f5103f
Add stub tests for tsLinter
tmcw Dec 12, 2024
4f73222
Support custom rendering for autocompletion parts
tmcw Dec 12, 2024
8c25514
Add demo of displayParts rendering and description
tmcw Dec 12, 2024
843f309
3.0.0-0
tmcw Dec 12, 2024
a1cd25e
add repository, schema, and homepage fields
tmcw Dec 12, 2024
c1500b8
Stricter config facet detection
tmcw Dec 12, 2024
ad75634
Add additional type exports
tmcw Dec 12, 2024
094558c
3.0.0-1
tmcw Dec 12, 2024
e61f0b8
Add way to manually trigger lint
tmcw Dec 12, 2024
cd9ae8a
Start adding goto functionality
tmcw Dec 12, 2024
f4fac3f
Make gotoHandler configurable
tmcw Dec 12, 2024
98eca24
Refactor demo css
tmcw Dec 12, 2024
2b01a11
Add description, use safer config check
tmcw Dec 16, 2024
cc1943a
Fix completion filtering
tmcw Dec 17, 2024
9d4929c
Fix silly error
tmcw Dec 17, 2024
f7f7d8c
Update gotoWorker
tmcw Dec 17, 2024
6f5904d
Use pnpm, remove tshy dep
tmcw Dec 17, 2024
275fec4
3.0.0-6
tmcw Dec 17, 2024
aa66f28
Pass-through environment
tmcw Dec 17, 2024
590c00c
Try to solve interdep problem
tmcw Dec 17, 2024
3d5a5bb
Make entire options arg promisable
tmcw Dec 17, 2024
af4041e
Update test.yml
tmcw Jan 8, 2025
4336279
Update deploy
tmcw Jan 8, 2025
3760182
Update readme, update types
tmcw Jan 8, 2025
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
19 changes: 15 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,28 @@ jobs:
runs-on: ubuntu-latest

steps:

- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9
run_install: false

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
uses: bahmutov/npm-install@v1
run: pnpm install

- name: Build project
run: npm run build
run: pnpm build

- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
Expand Down
24 changes: 21 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,37 @@ on: push
jobs:
build:
name: Test
runs-on: ubuntu-latest
runs-on: ubuntu-latest

permissions:
# Required to checkout the code
contents: read
# Required to put a comment into the pull-request
pull-requests: write

steps:
- name: Checkout repo
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9
run_install: false

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
uses: bahmutov/npm-install@v1
run: pnpm install

- run: npm run tsc
- run: npm run typecheck
- run: npm run test
- name: 'Report Coverage'
# Set if: always() to also generate the report if tests are failing
# Only works if you set `reportOnFailure: true` in your vite config as specified above
if: always()
uses: davelosert/vitest-coverage-report-action@v2
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
coverage
src/**.js
scripts/**.js
dist
.DS_Store
8 changes: 0 additions & 8 deletions .tshy/build.json

This file was deleted.

16 changes: 0 additions & 16 deletions .tshy/commonjs.json

This file was deleted.

15 changes: 0 additions & 15 deletions .tshy/esm.json

This file was deleted.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ in CodeMirror.
- Hover hints for types
- Autocomplete
- Diagnostics (lints, in CodeMirror's terminology)
- Go-to definition

## Peer dependencies

Expand Down Expand Up @@ -244,6 +245,7 @@ that accept the `worker` instead of `env` as an argument.
override: [tsAutocompleteWorker()],
}),
tsHoverWorker(),
tsGotoWorker(),
];
```

Expand Down Expand Up @@ -294,6 +296,15 @@ in the future.

Comlink is [lightweight](https://bundlephobia.com/package/[email protected]) (4.7kb gzipped).

## Conceptual notes: LSP

This module uses TypeScript’s public APIs to power its functionality:
it _doesn't_ use the [Language Server Protocol](https://en.wikipedia.org/wiki/Language_Server_Protocol), which is
a specification developed by Microsoft and intended for functionality like
this. TypeScript itself does not have a first-party LSP implementation
and LSP is usually used across a network. Most good TypeScript language
tooling, like VS Code’s autocompletion, does not use the LSP specification.

### ❤️ Other great CodeMirror plugins

- [codemirror-vim](https://github.com/replit/codemirror-vim)
Expand Down
36 changes: 36 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": ["demo", "dist", "coverage", "scripts", "test"]
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noNonNullAssertion": "off"
},
"suspicious": {
"noConsole": "error"
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "double"
}
}
}
46 changes: 0 additions & 46 deletions demo/demo.css
Original file line number Diff line number Diff line change
@@ -1,49 +1,3 @@
body {
margin: 0;
font-family: "IBM Plex Mono", monospace;
background: #eee;
color: #333;
}

* {
box-sizing: border-box;
}

h1 {
margin: 0;
}

h2 {
font-weight: normal;
font-size: 18px;
}

p {
line-height: 1.5;
}

a {
color: blue;
}

a:hover {
color: green;
}

.cm-editor {
border: 1px solid #000;
}

main {
max-width: 640px;
min-height: 100vh;
margin: 0 auto;
background: #fff;
padding: 20px;
border-left: 1px solid #aaa;
border-right: 1px solid #aaa;
}

.quick-info-punctuation {
color: #ccc;
}
Expand Down
11 changes: 7 additions & 4 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>codemirror-ts demo</title>
<meta name='description' content='A set of CodeMirror extensions that give it the powers of TypeScript' />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;700&display=swap"
rel="stylesheet"
/>
<link href="./demo.css" rel="stylesheet" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]">
<link rel="stylesheet" href="demo.css">
</head>
<body>
<main>
Expand All @@ -28,16 +30,17 @@ <h2>Currently supported</h2>
<li>Autocomplete</li>
<li>Hover</li>
<li>Diagnostics</li>
<li>Go to definition</li>
</ul>
<h2>Demo</h2>
<h2>Demos</h2>

<h3>TypeScript running on the page</h3>
<div id="app">
<div id="app" class='border'>
<div id="editor"></div>
</div>

<h3>TypeScript environment in a web worker</h3>
<div id="app">
<div id="app" class='border'>
<div id="editor-worker"></div>
</div>
</main>
Expand Down
42 changes: 38 additions & 4 deletions demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ import {
tsSyncWorker,
tsFacet,
tsFacetWorker,
tsGotoWorker,
} from "../src/index.js";
import * as Comlink from "comlink";
import { WorkerShape } from "../src/worker.js";

(async () => {
const fsMap = await createDefaultMapFromCDN(
{ target: ts.ScriptTarget.ES2022 },
"3.7.3",
ts.version,
true,
ts,
);
const system = createSystem(fsMap);
const compilerOpts = {};
const env = createVirtualTypeScriptEnvironment(system, [], ts, compilerOpts);
const env = createVirtualTypeScriptEnvironment(system, [], ts, {
lib: ["ES2022"],
});

const path = "index.ts";

Expand Down Expand Up @@ -61,6 +63,16 @@ increment('not a number');`,
});
})();

function renderDisplayParts(dp: ts.SymbolDisplayPart[]) {
const div = document.createElement("div");
for (const part of dp) {
const span = div.appendChild(document.createElement("span"));
span.className = `quick-info-${part.kind}`;
span.innerText = part.text;
}
return div;
}

(async () => {
const path = "index.ts";

Expand Down Expand Up @@ -89,9 +101,31 @@ increment('not a number');`,
tsSyncWorker(),
tsLinterWorker(),
autocompletion({
override: [tsAutocompleteWorker()],
override: [
tsAutocompleteWorker({
renderAutocomplete(raw) {
return () => {
const div = document.createElement("div");
if (raw.documentation) {
const description = div.appendChild(
document.createElement("div"),
);
description.appendChild(
renderDisplayParts(raw.documentation),
);
}
if (raw?.displayParts) {
const dp = div.appendChild(document.createElement("div"));
dp.appendChild(renderDisplayParts(raw.displayParts));
}
return { dom: div };
};
},
}),
],
}),
tsHoverWorker(),
tsGotoWorker(),
],
parent: document.querySelector("#editor-worker")!,
});
Expand Down
23 changes: 13 additions & 10 deletions demo/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import * as Comlink from "comlink";
import { createWorker } from "../src/worker/createWorker.js";

Comlink.expose(
createWorker(async function () {
const fsMap = await createDefaultMapFromCDN(
{ target: ts.ScriptTarget.ES2022 },
"3.7.3",
false,
ts,
);
const system = createSystem(fsMap);
const compilerOpts = {};
return createVirtualTypeScriptEnvironment(system, [], ts, compilerOpts);
createWorker({
env: (async function () {
const fsMap = await createDefaultMapFromCDN(
{ target: ts.ScriptTarget.ES2022 },
ts.version,
false,
ts,
);
const system = createSystem(fsMap);
return createVirtualTypeScriptEnvironment(system, [], ts, {
lib: ["ES2022"],
});
})(),
}),
);
Loading
Loading