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 a status bar item #650

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
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
27 changes: 26 additions & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {workspace, window, commands, ExtensionContext,
TextEditorRevealType,
Selection,
Uri,
extensions
StatusBarItem,
extensions,
StatusBarAlignment,
MarkdownString
} from 'vscode';

import {
Expand Down Expand Up @@ -37,6 +40,7 @@ import {
} from './utilities/utils';
import { DocumentStateViewProvider } from './panels/DocumentStateViewProvider';
import VsCoqToolchainManager, {ToolchainError, ToolChainErrorCode} from './utilities/toolchain';
import { stat } from 'fs';

let client: Client;

Expand Down Expand Up @@ -124,6 +128,10 @@ export function activate(context: ExtensionContext) {
const documentStateProvider = new DocumentStateViewProvider(client);
context.subscriptions.push(workspace.registerTextDocumentContentProvider("vscoq-document-state", documentStateProvider));

//status bar item for showing coq version and language server version
const statusBar: StatusBarItem = window.createStatusBarItem(StatusBarAlignment.Right, 1000);
context.subscriptions.push(statusBar);

const launchQuery = (editor: TextEditor, type: string)=> {
const selection = editor.selection;
const {end, start} = selection;
Expand Down Expand Up @@ -169,6 +177,23 @@ export function activate(context: ExtensionContext) {
.then(() => {

checkVersion(client, context);
const serverInfo = client.initializeResult!.serverInfo;
statusBar.text = `${serverInfo?.name} ${serverInfo?.version}, coq ${coqTM.getCoqVersion()}`;
statusBar.tooltip = new MarkdownString(

`**Coq Installation**

${coqTM.getversionFullOutput()}

Path: \`${coqTM.getCoqPath()}\`
---

**vscoqtop** ${serverInfo?.version}

Path: \`${coqTM.getVsCoqTopPath()}\`
`
);
statusBar.show();

initializeDecorations(context);

Expand Down
65 changes: 60 additions & 5 deletions client/src/utilities/toolchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { isFileInFolder } from './fileHelper';
import { ServerSessionOptions } from 'http2';
import { ServerOptions } from 'vscode-languageclient/node';
import Client from '../client';
import { version } from 'os';
import { match } from 'assert';

export enum ToolChainErrorCode {
notFound = 1,
launchError = 2,
coqVersionMissmatch = 3
launchError = 2
}

export interface ToolchainError {
Expand All @@ -20,7 +21,10 @@ export interface ToolchainError {

export default class VsCoqToolchainManager implements Disposable {

private _vscoqtopPath: string = "";
private _vscoqtopPath: string = "";
private _coqVersion: string = "";
private _versionFullOutput: string = "";
private _coqPath: string = "";

public dispose(): void {

Expand Down Expand Up @@ -64,6 +68,22 @@ export default class VsCoqToolchainManager implements Disposable {
return serverOptions;
};

public getVsCoqTopPath() : string {
return this._vscoqtopPath;
}

public getCoqPath() : string {
return this._coqPath;
}

public getCoqVersion() : string {
return this._coqVersion;
};

public getversionFullOutput() : string {
return this._versionFullOutput;
}

private getEnvPath() : string {
if(process.platform === 'win32') {
return process.env.Path ?? '';
Expand Down Expand Up @@ -111,14 +131,49 @@ export default class VsCoqToolchainManager implements Disposable {
reject({
status: ToolChainErrorCode.launchError,
message: `${this._vscoqtopPath} crashed with the following message: ${stderr}
This could be due to a bad Coq or installation or an incompatible Coq version.`
This could be due to a bad Coq installation or an incompatible Coq version.`
});
} else {
resolve();
this._coqPath = stdout;
this.coqVersion().then(
() => {
resolve();
},
(err) => {
reject({
status: ToolChainErrorCode.launchError,
message: `${this._vscoqtopPath} crashed with the following message: ${err}.
This could be due to a bad Coq installation or an incompatible Coq version`
});
}
);
}

});
});
};

private coqVersion() : Promise<void> {

const config = workspace.getConfiguration('vscoq').get('args') as string[];
const options = ["-v"].concat(config);
const cmd = [this._vscoqtopPath].concat(options).join(' ');

return new Promise((resolve, reject: (reason: string) => void) => {
exec(cmd, (error, stdout, stderr) => {
if(error) {
reject(stderr);
} else {
const versionRegexp = /\b\d\.\d+(\.\d|\+rc\d)\b/g;
this._versionFullOutput = stdout;
const matchArray = stdout.match(versionRegexp);
if(matchArray) {
this._coqVersion = matchArray[0];
}
resolve();
}
});
});
};

}
2 changes: 1 addition & 1 deletion client/src/utilities/versioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const checkVersion = (client: Client, context: ExtensionContext) => {
const extensionVersion = context.extension.packageJSON.version;
const initializeResult = client.initializeResult;
if(initializeResult !== undefined) {
const serverInfo =client.initializeResult?.serverInfo;
const serverInfo = client.initializeResult?.serverInfo;
if(serverInfo !== undefined) {
const {name, version} = serverInfo;
Client.writeToVscoq2Channel("[Versioning] Intialized server " + name + " [" + version + "]");
Expand Down