-
-
Notifications
You must be signed in to change notification settings - Fork 6
Notify running LS about build complete. #33
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import deepmerge from 'deepmerge'; | |
import { Mutex } from 'async-mutex'; | ||
import vscode, { ExtensionContext } from 'vscode'; | ||
import { LanguageClient, CloseAction, ErrorAction, InitializeError, Message, RevealOutputChannelOn } from 'vscode-languageclient'; | ||
import { DidCompleteBuildNotification, DidCompleteBuildParams } from './protocol'; | ||
|
||
interface LanguageServerConfig { | ||
readonly lsPath: string; | ||
|
@@ -72,10 +73,10 @@ export function activate(context: ExtensionContext) { | |
const started = await startLanguageServer(context, config); | ||
languageServerIsRunning = started; | ||
return languageServerIsRunning ? config.board.fqbn : undefined; | ||
} catch (e) { | ||
console.log(e); | ||
} catch (err) { | ||
console.error('Failed to start the language server.', err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you prefer the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question; the original code does not show the error if the LS failed to start. I did not want to change this behavior, but I could do it. Note, if we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only effective change here is that I use |
||
languageServerIsRunning = false; | ||
throw e; | ||
throw err; | ||
} finally { | ||
unlock(); | ||
} | ||
|
@@ -94,7 +95,14 @@ export function activate(context: ExtensionContext) { | |
return vscode.commands.executeCommand('arduino.languageserver.start', latestConfig); | ||
} | ||
}), | ||
vscode.commands.registerCommand('arduino.debug.start', (config: DebugConfig) => startDebug(context, config)) | ||
vscode.commands.registerCommand('arduino.debug.start', (config: DebugConfig) => startDebug(context, config)), | ||
vscode.commands.registerCommand('arduino.languageserver.notifyBuildDidComplete', (params: DidCompleteBuildParams) => { | ||
if (languageClient) { | ||
languageClient.sendNotification(DidCompleteBuildNotification.TYPE, params); | ||
} else { | ||
vscode.window.showWarningMessage('Language server is not running.'); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
|
@@ -108,8 +116,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo | |
rawStdout = stdout.trim(); | ||
rawStdErr = stderr.trim(); | ||
} catch (err) { | ||
const message = err instanceof Error ? err.stack || err.message : 'Unknown error'; | ||
vscode.window.showErrorMessage(message); | ||
showError(err); | ||
return false; | ||
} | ||
if (!rawStdout) { | ||
|
@@ -125,7 +132,8 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo | |
try { | ||
info = JSON.parse(rawStdout); | ||
} catch (err) { | ||
vscode.window.showErrorMessage(err); | ||
console.error(`Could not parse JSON: <${rawStdout}>`); | ||
showError(err); | ||
} | ||
if (!info) { | ||
return false; | ||
|
@@ -190,7 +198,7 @@ async function startLanguageServer(context: ExtensionContext, config: LanguageSe | |
|
||
async function buildLanguageClient(config: LanguageServerConfig): Promise<LanguageClient> { | ||
const { lsPath: command, clangdPath, cliDaemonAddr, cliDaemonInstance, board, flags, env, log } = config; | ||
const args = ['-clangd', clangdPath, '-cli-daemon-addr', cliDaemonAddr, '-cli-daemon-instance', cliDaemonInstance, '-fqbn', board.fqbn]; | ||
const args = ['-clangd', clangdPath, '-cli-daemon-addr', cliDaemonAddr, '-cli-daemon-instance', cliDaemonInstance, '-fqbn', board.fqbn, '-skip-libraries-discovery-on-rebuild']; | ||
if (board.name) { | ||
args.push('-board-name', board.name); | ||
} | ||
|
@@ -252,6 +260,12 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua | |
); | ||
} | ||
|
||
function showError(err: unknown): void { | ||
console.error(err); | ||
const message = err instanceof Error ? err.message : typeof err === 'string' ? err : String(err); | ||
vscode.window.showErrorMessage(message); | ||
} | ||
|
||
/** | ||
* Instead of writing the `launch.json` to the workspace, the file is written to the temporary binary output location. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { NotificationType, DocumentUri } from 'vscode-languageclient'; | ||
|
||
export interface DidCompleteBuildParams { | ||
readonly buildOutputUri: DocumentUri; | ||
} | ||
export namespace DidCompleteBuildNotification { | ||
export const TYPE = new NotificationType<DidCompleteBuildParams, void>('ino/didCompleteBuild'); | ||
} |