Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fannheyward committed Dec 12, 2023
1 parent 3aea72a commit beaa9df
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 75 deletions.
10 changes: 5 additions & 5 deletions src/cmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function switchSourceHeader(ctx: Ctx) {
};
const dest = await ctx.client.sendRequest<string>(SwitchSourceHeaderRequest.type.method, params);
if (!dest) {
window.showMessage(`Didn't find a corresponding file.`);
window.showInformationMessage(`Didn't find a corresponding file.`);
return;
}

Expand Down Expand Up @@ -64,7 +64,7 @@ export function symbolInfo(ctx: Ctx) {

// TODO
const detail = details[0];
window.showMessage(`name: ${detail.name}, containerName: ${detail.containerName}, usr: ${detail.usr}`);
window.showInformationMessage(`name: ${detail.name}, containerName: ${detail.containerName}, usr: ${detail.usr}`);
};
}

Expand Down Expand Up @@ -98,7 +98,7 @@ export function userConfig() {
if (file) {
openConfigFile(file);
} else {
window.showMessage("Couldn't get global configuration directory", 'warning');
window.showWarningMessage("Couldn't get global configuration directory");
}
}

Expand All @@ -107,6 +107,6 @@ export function projectConfig() {
const folder = workspace.workspaceFolders[0];
openConfigFile(path.join(Uri.parse(folder.uri).fsPath, '.clangd'));
} else {
window.showMessage('No project is open', 'warning');
window.showWarningMessage('No project is open');
}
}
}
8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Ctx, ClangdExtensionFeature } from './ctx';
import { FileStatus, Status } from './file-status';
import { InlayHintsFeature } from './inlay-hints';
import * as install from './install';
import { ReloadFeature } from './reload';
import { MemoryUsageFeature } from './memory-usage';
import { ASTFeature } from './ast';

Expand All @@ -16,7 +15,7 @@ export async function activate(context: ExtensionContext): Promise<void> {

const service = services.getService('clangd');
if (service) {
window.showMessage(`Looks like you've configured clangd in coc-settings.json, you should remove it to use coc-clangd`, 'warning');
window.showWarningMessage("Looks like you've configured clangd in coc-settings.json, you should remove it to use coc-clangd");
return;
}

Expand All @@ -28,10 +27,9 @@ export async function activate(context: ExtensionContext): Promise<void> {
try {
const astFeature = new ASTFeature(ctx);
const extFeature = new ClangdExtensionFeature();
const reloadFeature = new ReloadFeature(ctx, () => activate(context));
const memoryUsageFeature = new MemoryUsageFeature(ctx);
const inlayFeature = new InlayHintsFeature(ctx);
await ctx.startServer(clangdPath, ...[astFeature, extFeature, reloadFeature, memoryUsageFeature, inlayFeature]);
await ctx.startServer(clangdPath, ...[astFeature, extFeature, memoryUsageFeature, inlayFeature]);
} catch (e) {
return;
}
Expand Down Expand Up @@ -63,4 +61,4 @@ export async function activate(context: ExtensionContext): Promise<void> {
ctx.client?.onNotification('textDocument/clangd.fileStatus', (status: Status) => {
fileStatus.onFileUpdated(status);
});
}
}
8 changes: 3 additions & 5 deletions src/inlay-hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
StaticFeature,
TextDocumentIdentifier,
} from 'coc.nvim';
import { ServerCapabilities } from 'vscode-languageserver-protocol';

import { Ctx, documentSelector } from './ctx';

Expand Down Expand Up @@ -40,11 +39,10 @@ export class InlayHintsFeature implements StaticFeature {
fillClientCapabilities() {}
fillInitializeParams() {}

initialize(capabilities: ServerCapabilities) {
const serverCapabilities: ServerCapabilities & { clangdInlayHintsProvider?: boolean; inlayHintProvider?: any } = capabilities;
initialize(capabilities: any) {
// If the clangd server supports LSP 3.17 inlay hints, these are handled by
// the vscode-languageclient library - don't send custom requests too!
if (!serverCapabilities.clangdInlayHintsProvider || languages.registerInlayHintsProvider === undefined || serverCapabilities.inlayHintProvider) {
if (!capabilities.clangdInlayHintsProvider || languages.registerInlayHintsProvider === undefined || capabilities.inlayHintProvider) {
return;
}
this.context.subscriptions.push(languages.registerInlayHintsProvider(documentSelector, new Provider(this.context)));
Expand Down Expand Up @@ -83,4 +81,4 @@ class Provider implements InlayHintsProvider {
const result = await this.context.client!.sendRequest(protocol.InlayHintsRequest.type, request, token);
return result.map(this.decode, this);
}
}
}
16 changes: 8 additions & 8 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class UI {
return this.context.storagePath;
}
slow<T>(title: string, result: Promise<T>) {
coc.window.showMessage(title + '...');
coc.window.showInformationMessage(`${title}...}`);
return result;
}
error(s: string) {
coc.window.showMessage(s, 'error');
coc.window.showErrorMessage(s);
}
info(s: string) {
coc.window.showMessage(s);
coc.window.showInformationMessage(s);
}
progress<T>(title: string, _cancel: any, body: (progress: (fraction: number) => void) => Promise<T>) {
return this.slow(
Expand All @@ -27,23 +27,23 @@ class UI {
}

async shouldReuse(release: string) {
coc.window.showMessage(`Reusing existing ${release} installation in ${this.storagePath}`);
coc.window.showInformationMessage(`Reusing existing ${release} installation in ${this.storagePath}`);
return true;
}
async promptReload() {
await coc.commands.executeCommand('editor.action.restart');
}
showHelp(message: string, url: string) {
message += ` See ${url}.`;
coc.window.showMessage(message);
coc.window.showInformationMessage(message);
}
async promptUpdate(oldVersion: string, newVersion: string) {
const message = `clangd ${newVersion} is available (you have ${oldVersion}). :CocCommand clangd.install, or :CocSettings to disable clangd.checkUpdates.`;
coc.window.showMessage(message);
coc.window.showInformationMessage(message);
}
async promptInstall(version: string) {
const message = `clangd was not found on your PATH. :CocCommand clangd.install will install ${version}.`;
coc.window.showMessage(message);
coc.window.showInformationMessage(message);
}

get clangdPath(): string {
Expand Down Expand Up @@ -75,4 +75,4 @@ export async function activate(context: coc.ExtensionContext): Promise<string |
context.subscriptions.push(coc.commands.registerCommand('clangd.update', async () => common.checkUpdates(true, ui)));
const status = await common.prepare(ui, cfg.get<boolean>('checkUpdates', false));
return status.clangdPath;
}
}
5 changes: 2 additions & 3 deletions src/memory-usage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Implements the "memory usage" feature.

import { commands, RequestType0, StaticFeature, window } from 'coc.nvim';
import { ServerCapabilities } from 'vscode-languageserver-protocol';
import { Ctx } from './ctx';

// LSP wire format for this clangd feature.
Expand Down Expand Up @@ -57,7 +56,7 @@ export class MemoryUsageFeature implements StaticFeature {
fillClientCapabilities() {}
fillInitializeParams() {}

initialize(capabilities: ServerCapabilities) {
initialize(capabilities: any) {
if ('memoryUsageProvider' in capabilities) {
this.ctx.subscriptions.push(
commands.registerCommand('clangd.memoryUsage', async () => {
Expand All @@ -70,4 +69,4 @@ export class MemoryUsageFeature implements StaticFeature {
}
}
dispose() {}
}
}
49 changes: 0 additions & 49 deletions src/reload.ts

This file was deleted.

0 comments on commit beaa9df

Please sign in to comment.