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 "--lsp" flag to bsc to start an LSP server #668

Merged
merged 3 commits into from
Aug 18, 2022
Merged
Changes from all commits
Commits
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
28 changes: 17 additions & 11 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';
import { ProgramBuilder } from './ProgramBuilder';
import { DiagnosticSeverity } from 'vscode-languageserver';
import util from './util';
import { LanguageServer } from './LanguageServer';

let options = yargs
.usage('$0', 'BrighterScript, a superset of Roku\'s BrightScript language')
Expand Down Expand Up @@ -31,6 +32,7 @@ let options = yargs
.option('source-root', { type: 'string', description: 'Override the root directory path where debugger should locate the source files. The location will be embedded in the source map to help debuggers locate the original source files. This only applies to files found within rootDir. This is useful when you want to preprocess files before passing them to BrighterScript, and want a debugger to open the original files.' })
.option('watch', { type: 'boolean', defaultDescription: 'false', description: 'Watch input files.' })
.option('require', { type: 'array', description: 'A list of modules to require() on startup. Useful for doing things like ts-node registration.' })
.option('lsp', { type: 'boolean', defaultDescription: 'false', description: 'Run brighterscript as a language server.' })
.check(argv => {
const diagnosticLevel = argv.diagnosticLevel as string;
//if we have the diagnostic level and it's not a known value, then fail
Expand All @@ -46,15 +48,19 @@ let options = yargs
})
.argv;

let builder = new ProgramBuilder();
builder.run(<any>options).then(() => {
//if this is a single run (i.e. not watch mode) and there are error diagnostics, return an error code
const hasError = !!builder.getDiagnostics().find(x => x.severity === DiagnosticSeverity.Error);
if (builder.options.watch === false && hasError) {
if (options.lsp) {
const server = new LanguageServer();
server.run();
} else {
let builder = new ProgramBuilder();
builder.run(<any>options).then(() => {
//if this is a single run (i.e. not watch mode) and there are error diagnostics, return an error code
const hasError = !!builder.getDiagnostics().find(x => x.severity === DiagnosticSeverity.Error);
if (builder.options.watch === false && hasError) {
process.exit(1);
}
}).catch((error) => {
console.error(error);
process.exit(1);
}
}).catch((error) => {
console.error(error);
process.exit(1);
});

});
}