Skip to content

Commit

Permalink
reinstate watchFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
machty committed Jan 9, 2025
1 parent baa942a commit f36441a
Showing 1 changed file with 24 additions and 33 deletions.
57 changes: 24 additions & 33 deletions packages/core/src/volar/language-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import GlimmerASTMappingTree from '../transform/template/glimmer-ast-mapping-tre
import { Directive, TransformedModule } from '../transform/index.js';
import { Range } from '../transform/template/transformed-module.js';
import { offsetToPosition } from '../language-server/util/position.js';
import { Disposable } from '@volar/language-service';

const connection = createConnection();

Expand All @@ -33,10 +34,17 @@ const server = createServer(connection);
* other initialization params needed by the server.
*/
connection.onInitialize((parameters) => {
const project = createTypeScriptProject(ts, undefined, (projectContext) => {
// Not sure how tsLocalized is used.
const tsLocalized = undefined;
const watchingExtensions = new Set<string>();
let fileWatcher: Promise<Disposable> | undefined;

const project = createTypeScriptProject(ts, tsLocalized, (projectContext) => {
const configFileName = projectContext.configFileName;
const languagePlugins = [];

updateFileWatcher();

// I don't remember why but there are some contexts where a configFileName is not known,
// in which case we cannot fully activate all of the language plugins.
if (configFileName) {
Expand Down Expand Up @@ -102,6 +110,20 @@ connection.onInitialize((parameters) => {
}
}),
);

function updateFileWatcher() {

Check failure on line 114 in packages/core/src/volar/language-server.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing return type on function
const extensions = ['js', 'ts', 'gjs', 'gts', 'hbs'];
const newExtensions = extensions.filter((ext) => !watchingExtensions.has(ext));
if (newExtensions.length) {
for (const ext of newExtensions) {
watchingExtensions.add(ext);
}
fileWatcher?.then((dispose) => dispose.dispose());
fileWatcher = server.fileWatcher.watchFiles([
'**/*.{' + [...watchingExtensions].join(',') + '}',
]);
}
}
});

function filterAndAugmentDiagnostics(
Expand Down Expand Up @@ -271,42 +293,11 @@ function filterAndAugmentDiagnostics(
return allDiagnostics;
}

// connection.onRequest('mdx/toggleDelete', async (parameters) => {
// const commands = await getCommands(parameters.uri)
// return commands.toggleDelete(parameters)
// })

// connection.onRequest('mdx/toggleEmphasis', async (parameters) => {
// const commands = await getCommands(parameters.uri)
// return commands.toggleEmphasis(parameters)
// })

// connection.onRequest('mdx/toggleInlineCode', async (parameters) => {
// const commands = await getCommands(parameters.uri)
// return commands.toggleInlineCode(parameters)
// })

// connection.onRequest('mdx/toggleStrong', async (parameters) => {
// const commands = await getCommands(parameters.uri)
// return commands.toggleStrong(parameters)
// })

/**
* Invoked when client has sent `initialized` notification. Volar takes this
* opportunity to finish initializing, and we tell the client which extensions
* it should add file-watchers for (technically file-watchers could eagerly
* be set up on the client (e.g. when the extension activates), but since Volar
* capabilities use dynamic/deferredregistration, we have the server tell the
* client which files to watch via the deferred `registerCapability` message
* within `watchFiles()`).
* Invoked when client has sent `initialized` notification.
*/
connection.onInitialized(() => {
server.initialized();

const extensions = ['js', 'ts', 'gjs', 'gts', 'hbs'];

// TODO: figure out how to reinstate (and what this does exactly)
// server.watchFiles([`**.*.{${extensions.join(',')}}`]);
});

connection.listen();
Expand Down

0 comments on commit f36441a

Please sign in to comment.