Skip to content

Commit

Permalink
Fix bug with dublication of the output channel
Browse files Browse the repository at this point in the history
Built-in output channel in vscode was used for logging events of the
CoqLSP used inside. Output channels were created for each CoqLSP
instance. Now it's fixed.
  • Loading branch information
K-dizzled committed Sep 30, 2024
1 parent 363e210 commit 66d2d36
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/coqLsp/coqLspClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Mutex } from "async-mutex";
import { readFileSync } from "fs";
import { OutputChannel } from "vscode";
import {
BaseLanguageClient,
Diagnostic,
Expand Down Expand Up @@ -76,9 +77,14 @@ export class CoqLspClient implements CoqLspClientInterface {

static async create(
serverConfig: CoqLspServerConfig,
clientConfig: CoqLspClientConfig
clientConfig: CoqLspClientConfig,
logOutputChannel: OutputChannel
): Promise<CoqLspClient> {
const connector = new CoqLspConnector(serverConfig, clientConfig);
const connector = new CoqLspConnector(
serverConfig,
clientConfig,
logOutputChannel
);
await connector.start().catch((error) => {
throw new CoqLspStartupError(
`failed to start coq-lsp with Error: ${error.message}`,
Expand Down
6 changes: 4 additions & 2 deletions src/coqLsp/coqLspConnector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Uri } from "vscode";
import { OutputChannel, Uri } from "vscode";
import {
LanguageClientOptions,
RevealOutputChannelOn,
Expand All @@ -14,14 +14,16 @@ export class CoqLspConnector extends LanguageClient {
constructor(
serverConfig: CoqLspServerConfig,
clientConfig: CoqLspClientConfig,
public logOutputChannel: OutputChannel,
private eventLogger?: EventLogger
) {
let clientOptions: LanguageClientOptions = {
documentSelector: [
{ scheme: "file", language: "coq" },
{ scheme: "file", language: "markdown", pattern: "**/*.mv" },
],
outputChannelName: "CoqPilot: coq-lsp events",
outputChannel: logOutputChannel,
// outputChannelName: "CoqPilot: coq-lsp events",
revealOutputChannelOn: RevealOutputChannelOn.Info,
initializationOptions: serverConfig,
markdown: { isTrusted: true, supportHtml: true },
Expand Down
3 changes: 2 additions & 1 deletion src/extension/coqPilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ export class CoqPilot {
CoqLspConfig.createClientConfig(coqLspServerPath);
const client = await CoqLspClient.create(
coqLspServerConfig,
coqLspClientConfig
coqLspClientConfig,
this.globalExtensionState.logOutputChannel
);
const contextTheoremsRanker = buildTheoremsRankerFromConfig();

Expand Down
6 changes: 5 additions & 1 deletion src/extension/globalExtensionState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "fs";
import * as path from "path";
import * as tmp from "tmp";
import { WorkspaceConfiguration, workspace } from "vscode";
import { WorkspaceConfiguration, window, workspace } from "vscode";

import { LLMServices, disposeServices } from "../llm/llmServices";
import { GrazieService } from "../llm/llmServices/grazie/grazieService";
Expand All @@ -20,6 +20,9 @@ export class GlobalExtensionState {
this.eventLogger,
this.parseLoggingVerbosity(workspace.getConfiguration(pluginId))
);
public readonly logOutputChannel = window.createOutputChannel(
"CoqPilot: coq-lsp events"
);

public readonly llmServicesLogsDir = path.join(
tmp.dirSync().name,
Expand Down Expand Up @@ -65,5 +68,6 @@ export class GlobalExtensionState {
disposeServices(this.llmServices);
this.logWriter.dispose();
fs.rmSync(this.llmServicesLogsDir, { recursive: true, force: true });
this.logOutputChannel.dispose();
}
}
11 changes: 10 additions & 1 deletion src/test/benchmark/benchmarkingFramework.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as assert from "assert";
import * as fs from "fs";
import { window } from "vscode";

import { LLMServices } from "../../llm/llmServices";
import { GrazieService } from "../../llm/llmServices/grazie/grazieService";
Expand Down Expand Up @@ -425,7 +426,15 @@ async function createCoqLspClient(
process.env.COQ_LSP_PATH || "coq-lsp",
workspaceRootPath
);
return await CoqLspClient.create(coqLspServerConfig, coqLspClientConfig);
const logOutputChannel = window.createOutputChannel(
"CoqPilot: coq-lsp events"
);

return await CoqLspClient.create(
coqLspServerConfig,
coqLspClientConfig,
logOutputChannel
);
}

async function extractCompletionTargets(
Expand Down
11 changes: 10 additions & 1 deletion src/test/commonTestFunctions/coqLspBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { window } from "vscode";

import { CoqLspClient } from "../../coqLsp/coqLspClient";
import { CoqLspConfig } from "../../coqLsp/coqLspConfig";

Expand All @@ -9,6 +11,13 @@ export async function createCoqLspClient(
process.env.COQ_LSP_PATH || "coq-lsp",
workspaceRootPath
);
const logOutputChannel = window.createOutputChannel(
"CoqPilot: coq-lsp events"
);

return await CoqLspClient.create(coqLspServerConfig, coqLspClientConfig);
return await CoqLspClient.create(
coqLspServerConfig,
coqLspClientConfig,
logOutputChannel
);
}

0 comments on commit 66d2d36

Please sign in to comment.