Index: clangd/clients/clangd-vscode/src/extension.ts =================================================================== --- clangd/clients/clangd-vscode/src/extension.ts +++ clangd/clients/clangd-vscode/src/extension.ts @@ -18,6 +18,37 @@ void, void>('textDocument/switchSourceHeader'); } +class FileStatus { + private statuses = new Map(); + private readonly statusBarItem = + vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 10); + + onFileUpdated(fileStatus: any) { + const filePath = vscode.Uri.parse(fileStatus.uri); + this.statuses.set(filePath.fsPath, fileStatus); + this.updateStatus(); + } + + updateStatus() { + const path = vscode.window.activeTextEditor.document.fileName; + const status = this.statuses.get(path); + if (!status) { + this.statusBarItem.hide(); + return; + } + this.statusBarItem.text = `clangd: ` + status.state; + // FIXME: find a way to show the details in a nicer way. + if (status.details.length > 0) + this.statusBarItem.tooltip = status.details.map( + (detail: any) => detail.message).join('; '); + this.statusBarItem.show() + } + + dispose() { + this.statusBarItem.dispose(); + } +} + /** * this method is called when your extension is activate * your extension is activated the very first time the command is executed @@ -80,4 +111,13 @@ vscode.Uri.parse(sourceUri)); vscode.window.showTextDocument(doc); })); + const status = new FileStatus(); + context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(() => { + status.updateStatus(); + })) + clangdClient.onReady().then(() => { + clangdClient.onNotification('textDocument/fileStatus', (fileStatus) => { + status.onFileUpdated(fileStatus) + }); + }) }