Skip to content

Commit

Permalink
Support configuring specific version of language server binary
Browse files Browse the repository at this point in the history
+ Add a setting in the VS Code extension to specify a path to the binary.
+ Expand logging to report the version ID of the invoked language server.
  • Loading branch information
Viir committed Dec 20, 2024
1 parent ae57b53 commit 23d9082
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 30 deletions.
25 changes: 13 additions & 12 deletions implement/pine/Elm/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Pine.PineVM;
using Pine.Elm019;
using System.Collections.Immutable;
using System.Text;
using System.Threading.Tasks;

namespace Pine.Elm;

Expand Down Expand Up @@ -204,10 +201,6 @@ IEnumerable<string> composeDirectories()
}
}

IReadOnlyList<string> sourceDirectories = [.. composeDirectories().Distinct()];

Log("Starting to initialize files contents for " + sourceDirectories.Count + " directories");

languageServiceStateTask = System.Threading.Tasks.Task.Run(() =>
{
var vmCache = new PineVMCache();
Expand Down Expand Up @@ -238,6 +231,12 @@ IEnumerable<string> composeDirectories()
"Unexpected language service state result type: " + taskResult.GetType());
}

IReadOnlyList<string> sourceDirectories = [.. composeDirectories().Distinct()];

Log("Starting to initialize files contents for " + sourceDirectories.Count + " directories");

var aggregateClock = System.Diagnostics.Stopwatch.StartNew();

var filesContents = new Dictionary<string, string>();

foreach (var sourceDirectory in sourceDirectories)
Expand All @@ -253,7 +252,7 @@ IEnumerable<string> composeDirectories()
{
try
{
var clock = System.Diagnostics.Stopwatch.StartNew();
var fileClock = System.Diagnostics.Stopwatch.StartNew();

var fileContent = System.IO.File.ReadAllText(elmFile);

Expand All @@ -263,17 +262,17 @@ IEnumerable<string> composeDirectories()
"Read file " + elmFile + " with " +
CommandLineInterface.FormatIntegerForDisplay(fileContent.Length) +
" chars in " +
CommandLineInterface.FormatIntegerForDisplay((int)clock.Elapsed.TotalMilliseconds) + " ms");
CommandLineInterface.FormatIntegerForDisplay((int)fileClock.Elapsed.TotalMilliseconds) + " ms");

clock.Restart();
fileClock.Restart();

languageServiceState.AddFile(
PathItemsFromFlatPath(elmFile),
fileContent);

Log(
"Processed file " + elmFile + " in language service in " +
CommandLineInterface.FormatIntegerForDisplay((int)clock.Elapsed.TotalMilliseconds) + " ms");
CommandLineInterface.FormatIntegerForDisplay((int)fileClock.Elapsed.TotalMilliseconds) + " ms");
}
catch (System.Exception e)
{
Expand All @@ -287,7 +286,9 @@ IEnumerable<string> composeDirectories()
}
}

Log("Finished initializing contents for " + filesContents.Count + " files");
Log(
"Finished initializing contents for " + filesContents.Count + " Elm modules in " +
CommandLineInterface.FormatIntegerForDisplay((int)aggregateClock.Elapsed.TotalMilliseconds) + " ms");
}

public void Workspace_didChangeWorkspaceFolders(WorkspaceFoldersChangeEvent workspaceFoldersChangeEvent)
Expand Down
2 changes: 1 addition & 1 deletion implement/pine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ void log(string content)
log("Unobserved task exception: " + args.Exception);
};

log("Starting language server...");
log("Pine version " + AppVersionId + " starting language server...");

var languageServer = new LanguageServer(logDelegate: log);

Expand Down
52 changes: 37 additions & 15 deletions implement/vscode/extension/pine/client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import { workspace, ExtensionContext } from 'vscode';
import { workspace, ExtensionContext, window, OutputChannel } from 'vscode';

import {
CloseAction,
Expand All @@ -14,37 +14,59 @@ import {
let client: LanguageClient;


const langServerCommand: string =
const langServerExecutablePathDefault: string =
"pine";


const logDir: string =
"./ls-log/";

const pineOutputChannel: OutputChannel =
window.createOutputChannel("Pine Logs");

function buildServerOptions(context: ExtensionContext): ServerOptions {

/*
https://github.com/denoland/vscode_deno/blob/df2633e58a95554158065ac5e6fc9b87e6c02c7a/client/src/commands.ts#L167-L179
*/
const config =
workspace.getConfiguration('pineLanguageServer');

const customPath =
sanitizePathFromSettings(
config.get<string>('pathToPineBinary')?.trim() || '');

const langServerExecutablePath =
customPath !== ''
? customPath
: langServerExecutablePathDefault;

pineOutputChannel.appendLine("lang-server executable path: " + langServerExecutablePath);

return {
run: {
command: langServerCommand
// , args: ["lsp", "--log-dir=" + logDir]
, args: ["lsp"]
, transport: TransportKind.stdio
command: langServerExecutablePath,
args: ["lsp"],
transport: TransportKind.stdio
},
debug: {
command: langServerCommand
// , args: ["lsp", "--log-dir=" + logDir]
, args: ["lsp"]
, transport: TransportKind.stdio
},
command: langServerExecutablePath,
args: ["lsp"],
transport: TransportKind.stdio
}
};
}

function sanitizePathFromSettings(input: string): string {
/*
Remove leading and trailing quotes,
as could be present when using "Copy as path" in Windows Explorer
*/
const withoutQuotes = input.replace(/^"|"$/g, '');

return withoutQuotes;
}

export function activate(context: ExtensionContext) {

console.info("Begin activate...");
pineOutputChannel.appendLine("Pine extension activated.");

const serverOptions: ServerOptions = buildServerOptions(context);

Expand Down
10 changes: 8 additions & 2 deletions implement/vscode/extension/pine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Pine",
"description": "Elm developer tools",
"license": "MIT",
"version": "0.3.0",
"version": "0.3.1",
"author": "Michael Rätzel",
"repository": {
"type": "git",
Expand Down Expand Up @@ -54,7 +54,7 @@
},
"configuration": {
"type": "object",
"title": "Example configuration",
"title": "Pine",
"properties": {
"pineLanguageServer.maxNumberOfProblems": {
"scope": "resource",
Expand All @@ -72,6 +72,12 @@
],
"default": "off",
"description": "Traces the communication between VS Code and the language server."
},
"pineLanguageServer.pathToPineBinary": {
"scope": "window",
"type": "string",
"default": "",
"description": "Path to the Pine language server binary. Empty string falls back to 'pine'."
}
}
}
Expand Down

0 comments on commit 23d9082

Please sign in to comment.