Skip to content

Commit

Permalink
Merge pull request #234 from mame/monitor-rbs
Browse files Browse the repository at this point in the history
Monitor the changes of RBS files
  • Loading branch information
mame authored Dec 20, 2024
2 parents 9534796 + 8a54ef1 commit d1574ed
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import * as vscode from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node';
import { LanguageClient, LanguageClientOptions, ServerOptions, TextDocumentFilter } from 'vscode-languageclient/node';
import * as net from 'net';
import * as child_process from 'child_process';

Check warning on line 6 in src/extension.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 3.3.6)

Import name `child_process` must match one of the following formats: camelCase, PascalCase

Check warning on line 6 in src/extension.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest, 3.3.6)

Import name `child_process` must match one of the following formats: camelCase, PascalCase
import { existsSync } from 'fs';
Expand Down Expand Up @@ -212,7 +212,7 @@ function getTypeProfStream(
});
}

function invokeTypeProf(folder: vscode.WorkspaceFolder): LanguageClient {
function invokeTypeProf(version: string, folder: vscode.WorkspaceFolder): LanguageClient {
const reportError = (msg: string) => client?.info(msg);

const serverOptions: ServerOptions = async () => {
Expand All @@ -226,11 +226,19 @@ function invokeTypeProf(folder: vscode.WorkspaceFolder): LanguageClient {
};
};

const documentSelector: TextDocumentFilter[] = [
{ scheme: 'file', language: 'ruby' },
{ scheme: 'file', language: 'rbs' },
];

if (compareVersions(version, '0.30.1') < 0) {
// I don't know why, but this prevents the notification of changes of RBS files.
// This is needed because the old version of TypeProf does not support RBS changes.
documentSelector[0].pattern = '**/*.rb';
}

const clientOptions: LanguageClientOptions = {
documentSelector: [
{ scheme: 'file', language: 'ruby', pattern: '**/*.rb' },
{ scheme: 'file', language: 'rbs' },
],
documentSelector,
outputChannel,
synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher('{**/*.rb,**/*.rbs}'),
Expand Down Expand Up @@ -268,7 +276,7 @@ function startTypeProf(context: vscode.ExtensionContext, folder: vscode.Workspac
return;
}
showStatus(`Starting Ruby TypeProf (${version})...`);
client = invokeTypeProf(folder);
client = invokeTypeProf(version, folder);
await client.start();
showStatus('Ruby TypeProf is running');
if (compareVersions(version, '0.21.8') >= 0) {
Expand Down

0 comments on commit d1574ed

Please sign in to comment.