Skip to content

Commit

Permalink
feat: lsp_ext statusNotification
Browse files Browse the repository at this point in the history
  • Loading branch information
fannheyward committed Jul 3, 2020
1 parent 15bd717 commit 3a055d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ExperimentalFeatures implements StaticFeature {
const caps: any = capabilities.experimental ?? {};
caps.snippetTextEdit = true;
caps.resolveCodeAction = true;
caps.statusNotification = true;
capabilities.experimental = caps;
}
initialize(): void {}
Expand Down
15 changes: 13 additions & 2 deletions src/ctx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { commands, ExtensionContext, LanguageClient, services, workspace } from 'coc.nvim';
import { commands, ExtensionContext, LanguageClient, services, StatusBarItem, workspace } from 'coc.nvim';
import executable from 'executable';
import { existsSync } from 'fs';
import { homedir } from 'os';
Expand All @@ -8,6 +8,7 @@ import which from 'which';
import { createClient } from './client';
import { Config } from './config';
import { downloadServer, getLatestRelease } from './downloader';
import * as ra from './lsp_ext';

export type RustDocument = TextDocument & { languageId: 'rust' };
export function isRustDocument(document: TextDocument): document is RustDocument {
Expand All @@ -18,8 +19,13 @@ export type Cmd = (...args: any[]) => unknown;

export class Ctx {
client!: LanguageClient;
private statusBar: StatusBarItem;

constructor(private readonly extCtx: ExtensionContext, readonly config: Config) {}
constructor(private readonly extCtx: ExtensionContext, readonly config: Config) {
this.statusBar = workspace.createStatusBarItem(10);
this.statusBar.text = 'rust-analyzer';
this.extCtx.subscriptions.push(this.statusBar);
}

registerCommand(name: string, factory: (ctx: Ctx) => Cmd) {
const fullName = `rust-analyzer.${name}`;
Expand All @@ -38,6 +44,11 @@ export class Ctx {
this.extCtx.subscriptions.push(services.registLanguageClient(client));
await client.onReady();

client.onNotification(ra.status, (status) => {
this.statusBar.text = `rust-analyzer ${status}`;
this.statusBar.show();
});

this.client = client;
}

Expand Down
3 changes: 3 additions & 0 deletions src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import * as lc from 'vscode-languageserver-protocol';

export const analyzerStatus = new lc.RequestType<null, string, void>('rust-analyzer/analyzerStatus');

export type Status = 'loading' | 'ready' | 'invalid' | 'needsReload';
export const status = new lc.NotificationType<Status>('rust-analyzer/status');

export const reloadWorkspace = new lc.RequestType<null, null, void>('rust-analyzer/reloadWorkspace');

export interface SyntaxTreeParams {
Expand Down

0 comments on commit 3a055d6

Please sign in to comment.