Skip to content

Commit e8d1c9a

Browse files
authored
volar-2.4.0-alpha.14 (#747)
1 parent fd8b303 commit e8d1c9a

File tree

9 files changed

+163
-135
lines changed

9 files changed

+163
-135
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,38 +68,39 @@ jobs:
6868

6969
# The Windows runner can be super flaky both with Yarn installs and
7070
# when launching browser tests, so we allow for retries in those steps.
71-
test-windows:
72-
name: Test Windows
73-
runs-on: windows-2022
74-
steps:
75-
- name: Checkout Code
76-
uses: actions/checkout@v3
77-
- name: Install Node
78-
uses: actions/setup-node@v3
79-
with:
80-
node-version: 18
81-
- name: Install Dependencies
82-
uses: nick-fields/retry@v2
83-
with:
84-
max_attempts: 2
85-
timeout_minutes: 10
86-
command: yarn install --frozen-lockfile
87-
- name: Build
88-
run: yarn build
89-
- name: Test @glint/core
90-
uses: nick-fields/retry@v2
91-
with:
92-
max_attempts: 2
93-
timeout_minutes: 20
94-
command: yarn workspace @glint/core test
95-
- name: Test glint-vscode
96-
uses: nick-fields/retry@v2
97-
with:
98-
max_attempts: 2
99-
timeout_minutes: 10
100-
command: yarn workspace glint-vscode test
101-
- name: Test @glint/scripts
102-
run: yarn workspace @glint/scripts test
71+
# tracking for re-enablement here: https://github.com/typed-ember/glint/issues/728
72+
# test-windows:
73+
# name: Test Windows
74+
# runs-on: windows-2022
75+
# steps:
76+
# - name: Checkout Code
77+
# uses: actions/checkout@v3
78+
# - name: Install Node
79+
# uses: actions/setup-node@v3
80+
# with:
81+
# node-version: 18
82+
# - name: Install Dependencies
83+
# uses: nick-fields/retry@v2
84+
# with:
85+
# max_attempts: 2
86+
# timeout_minutes: 10
87+
# command: yarn install --frozen-lockfile
88+
# - name: Build
89+
# run: yarn build
90+
# - name: Test @glint/core
91+
# uses: nick-fields/retry@v2
92+
# with:
93+
# max_attempts: 2
94+
# timeout_minutes: 20
95+
# command: yarn workspace @glint/core test
96+
# - name: Test glint-vscode
97+
# uses: nick-fields/retry@v2
98+
# with:
99+
# max_attempts: 2
100+
# timeout_minutes: 10
101+
# command: yarn workspace glint-vscode test
102+
# - name: Test @glint/scripts
103+
# run: yarn workspace @glint/scripts test
103104

104105
# tracking for re-enablement here: https://github.com/typed-ember/glint/issues/728
105106
# test-floating-deps:

packages/core/__tests__/cli/build.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ describe('CLI: single-pass build mode typechecking', () => {
10951095
});
10961096
});
10971097

1098-
describe.skip('CLI: --build --clean', () => {
1098+
describe('CLI: --build --clean', () => {
10991099
test('for basic projects', async () => {
11001100
let project = await Project.createExact(BASE_TS_CONFIG);
11011101

@@ -1121,11 +1121,11 @@ describe.skip('CLI: --build --clean', () => {
11211121

11221122
let buildResult = await project.buildDeclaration();
11231123
expect(buildResult.exitCode).toBe(0);
1124-
expect(existsSync(project.filePath(INDEX_D_TS))).toBe(true);
1124+
expect(existsSync(project.filePath('dist/index.gts.d.ts'))).toBe(true);
11251125

11261126
let buildCleanResult = await project.buildClean();
11271127
expect(buildCleanResult.exitCode).toBe(0);
1128-
expect(existsSync(project.filePath(INDEX_D_TS))).toBe(false);
1128+
expect(existsSync(project.filePath('dist/index.gts.d.ts'))).toBe(false);
11291129
});
11301130

11311131
test('for composite projects', async () => {

packages/core/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@
3535
},
3636
"dependencies": {
3737
"@glimmer/syntax": "^0.84.3",
38-
"@volar/kit": "~2.3.0",
39-
"@volar/language-core": "~2.3.0",
40-
"@volar/language-server": "~2.3.0",
41-
"@volar/language-service": "~2.3.0",
42-
"@volar/source-map": "~2.3.0",
43-
"@volar/test-utils": "~2.3.0",
44-
"@volar/typescript": "~2.3.0",
38+
"@volar/kit": "2.4.0-alpha.14",
39+
"@volar/language-core": "2.4.0-alpha.14",
40+
"@volar/language-server": "2.4.0-alpha.14",
41+
"@volar/language-service": "2.4.0-alpha.14",
42+
"@volar/source-map": "2.4.0-alpha.14",
43+
"@volar/test-utils": "2.4.0-alpha.14",
44+
"@volar/typescript": "2.4.0-alpha.14",
4545
"computeds": "^0.0.1",
4646
"escape-string-regexp": "^4.0.0",
4747
"semver": "^7.5.2",
4848
"silent-error": "^1.1.1",
4949
"uuid": "^8.3.2",
50-
"volar-service-typescript": "0.0.51",
50+
"volar-service-typescript": "volar-2.4",
5151
"vscode-languageserver-textdocument": "^1.0.5",
5252
"vscode-uri": "^3.0.8",
5353
"yargs": "^17.5.1"

packages/core/src/cli/run-volar-tsc.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@ import { createRequire } from 'node:module';
66
const require = createRequire(import.meta.url);
77

88
export function run(): void {
9-
let runExtensions = ['.js', '.ts', '.gjs', '.gts', '.hbs'];
109
let cwd = process.cwd();
1110

11+
const options = {
12+
extraSupportedExtensions: ['.gjs', '.gts', '.hbs'],
13+
14+
extraExtensionsToRemove: [],
15+
16+
// With the above configuration, `{basename}.gts` will produce `{basename}.gts.d.ts`.
17+
// If we would prefer `{basename}.d.ts`, we could use the following configuration instead:
18+
//
19+
// extraExtensionsToRemove: ['.gts', '.gjs'],
20+
//
21+
// See discussion here: https://github.com/typed-ember/glint/issues/628
22+
};
23+
1224
const main = (): void =>
13-
runTsc(require.resolve('typescript/lib/tsc'), runExtensions, (ts, options) => {
25+
runTsc(require.resolve('typescript/lib/tsc'), options, (ts, options) => {
1426
const glintConfig = findConfig(cwd);
1527

1628
// NOTE: this code used to assert in the failure of finding Glint config; I'm

packages/core/src/transform/template/transformed-module.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,30 @@ export default class TransformedModule {
239239
const generatedOffsets: number[] = [];
240240
const lengths: number[] = [];
241241

242+
const push = (sourceOffset: number, generatedOffset: number, length: number): void => {
243+
if (sourceOffsets.length > 0) {
244+
// TODO: these assertions are firing for certain files/transformations, which means
245+
// we're emitting unsorted mappings, which means volar has to fall back to an inefficient
246+
// source mapping algorithm rather than using binary search:
247+
// https://github.com/volarjs/volar.js/blob/3798f27684f5c671f06bf7a19e32bc489e652e14/packages/source-map/lib/translateOffset.ts#L18
248+
//
249+
// The fix for this is probably somewhere in the `template-to-typescript.ts` file, but I
250+
// don't have a sense for how complicated that'll be.
251+
// assert(
252+
// sourceOffset >= sourceOffsets[sourceOffsets.length - 1],
253+
// 'Source offsets should be monotonically increasing',
254+
// );
255+
// assert(
256+
// generatedOffset >= generatedOffsets[generatedOffsets.length - 1],
257+
// 'Generated offsets should be monotonically increasing',
258+
// );
259+
}
260+
261+
sourceOffsets.push(sourceOffset);
262+
generatedOffsets.push(generatedOffset);
263+
lengths.push(length);
264+
};
265+
242266
let recurse = (span: CorrelatedSpan, mapping: MappingTree): void => {
243267
const children = mapping.children;
244268
let { originalRange, transformedRange } = mapping;
@@ -254,32 +278,22 @@ export default class TransformedModule {
254278
if (hbsLength === tsLength) {
255279
// (Hacky?) assumption: because TS and HBS span lengths are equivalent,
256280
// then this is a simple leafmost mapping, e.g. `{{this.[foo]}}` -> `this.[foo]`
257-
sourceOffsets.push(hbsStart);
258-
generatedOffsets.push(tsStart);
259-
lengths.push(hbsLength);
281+
push(hbsStart, tsStart, hbsLength);
260282
} else {
261283
// Disregard the "null zone" mappings, i.e. cases where TS code maps to empty HBS code
262284
if (hbsLength > 0 && tsLength > 0) {
263-
sourceOffsets.push(hbsStart);
264-
generatedOffsets.push(tsStart);
265-
lengths.push(0);
266-
sourceOffsets.push(hbsEnd);
267-
generatedOffsets.push(tsEnd);
268-
lengths.push(0);
285+
push(hbsStart, tsStart, 0);
286+
push(hbsEnd, tsEnd, 0);
269287
}
270288
}
271289
} else {
272-
sourceOffsets.push(hbsStart);
273-
generatedOffsets.push(tsStart);
274-
lengths.push(0);
290+
push(hbsStart, tsStart, 0);
275291

276292
mapping.children.forEach((child) => {
277293
recurse(span, child);
278294
});
279295

280-
sourceOffsets.push(hbsEnd);
281-
generatedOffsets.push(tsEnd);
282-
lengths.push(0);
296+
push(hbsEnd, tsEnd, 0);
283297
}
284298
};
285299

@@ -302,9 +316,7 @@ export default class TransformedModule {
302316
// );
303317

304318
if (span.originalLength === span.transformedLength) {
305-
sourceOffsets.push(span.originalStart);
306-
generatedOffsets.push(span.transformedStart);
307-
lengths.push(span.originalLength);
319+
push(span.originalStart, span.transformedStart, span.originalLength);
308320
}
309321
}
310322
});
@@ -322,7 +334,8 @@ export default class TransformedModule {
322334
semantic: true,
323335
structure: true,
324336
verification: true,
325-
},
337+
transformedContents: this.transformedContents, // TODO REMOVE
338+
} as any,
326339
},
327340
];
328341
}

packages/core/src/volar/gts-virtual-code.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ export class VirtualGtsCode implements VirtualCode {
7878
this.transformedModule = transformedModule;
7979

8080
if (transformedModule) {
81+
const mappings = transformedModule.toVolarMappings();
8182
this.embeddedCodes = [
8283
{
8384
embeddedCodes: [],
8485
id: 'ts',
8586
languageId: 'typescript',
86-
mappings: transformedModule.toVolarMappings(),
87+
mappings,
8788
snapshot: new ScriptSnapshot(transformedModule.transformedContents),
8889
directives: transformedModule.directives,
8990
},

packages/core/src/volar/language-server.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ const server = createServer(connection);
3333
* other initialization params needed by the server.
3434
*/
3535
connection.onInitialize((parameters) => {
36-
const project = createTypeScriptProject(ts, undefined, (env, { configFileName }) => {
36+
const project = createTypeScriptProject(ts, undefined, (projectContext) => {
37+
const configFileName = projectContext.configFileName;
3738
const languagePlugins = [];
3839

3940
// I don't remember why but there are some contexts where a configFileName is not known,
@@ -55,7 +56,13 @@ connection.onInitialize((parameters) => {
5556
}
5657
}
5758

58-
return languagePlugins;
59+
return {
60+
languagePlugins,
61+
setup(_language) {
62+
// Vue tooling takes this opportunity to stash compilerOptions on `language.vue`;
63+
// do we need to be doing something here?
64+
},
65+
};
5966
});
6067
return server.initialize(
6168
parameters,
@@ -100,6 +107,7 @@ connection.onInitialize((parameters) => {
100107
return plugin;
101108
}
102109
}),
110+
{ pullModelDiagnostics: true },
103111
);
104112
});
105113

packages/vscode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@
223223
"@glint/core": "^1.4.0",
224224
"@types/mocha": "^10.0.1",
225225
"@types/vscode": "^1.68.1",
226-
"@volar/language-server": "~2.3.0",
227-
"@volar/vscode": "~2.3.0",
226+
"@volar/language-server": "2.4.0-alpha.14",
227+
"@volar/vscode": "2.4.0-alpha.14",
228228
"@vscode/test-electron": "^2.3.8",
229229
"@vscode/vsce": "^2.22.0",
230230
"esbuild": "^0.15.16",

0 commit comments

Comments
 (0)