diff --git a/implement/pine/Elm/LanguageServer.cs b/implement/pine/Elm/LanguageServer.cs index 3edb7b2c..26bfe22c 100644 --- a/implement/pine/Elm/LanguageServer.cs +++ b/implement/pine/Elm/LanguageServer.cs @@ -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; @@ -204,10 +201,6 @@ IEnumerable composeDirectories() } } - IReadOnlyList sourceDirectories = [.. composeDirectories().Distinct()]; - - Log("Starting to initialize files contents for " + sourceDirectories.Count + " directories"); - languageServiceStateTask = System.Threading.Tasks.Task.Run(() => { var vmCache = new PineVMCache(); @@ -238,6 +231,12 @@ IEnumerable composeDirectories() "Unexpected language service state result type: " + taskResult.GetType()); } + IReadOnlyList sourceDirectories = [.. composeDirectories().Distinct()]; + + Log("Starting to initialize files contents for " + sourceDirectories.Count + " directories"); + + var aggregateClock = System.Diagnostics.Stopwatch.StartNew(); + var filesContents = new Dictionary(); foreach (var sourceDirectory in sourceDirectories) @@ -253,7 +252,7 @@ IEnumerable composeDirectories() { try { - var clock = System.Diagnostics.Stopwatch.StartNew(); + var fileClock = System.Diagnostics.Stopwatch.StartNew(); var fileContent = System.IO.File.ReadAllText(elmFile); @@ -263,9 +262,9 @@ IEnumerable 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), @@ -273,7 +272,7 @@ IEnumerable composeDirectories() 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) { @@ -287,7 +286,9 @@ IEnumerable 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) diff --git a/implement/pine/Program.cs b/implement/pine/Program.cs index 4557c89d..a085d574 100644 --- a/implement/pine/Program.cs +++ b/implement/pine/Program.cs @@ -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); diff --git a/implement/vscode/extension/pine/client/src/extension.ts b/implement/vscode/extension/pine/client/src/extension.ts index 04fea492..cddea1d4 100644 --- a/implement/vscode/extension/pine/client/src/extension.ts +++ b/implement/vscode/extension/pine/client/src/extension.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { workspace, ExtensionContext } from 'vscode'; +import { workspace, ExtensionContext, window, OutputChannel } from 'vscode'; import { CloseAction, @@ -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('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); diff --git a/implement/vscode/extension/pine/package.json b/implement/vscode/extension/pine/package.json index 9da5ea0d..e6b56024 100644 --- a/implement/vscode/extension/pine/package.json +++ b/implement/vscode/extension/pine/package.json @@ -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", @@ -54,7 +54,7 @@ }, "configuration": { "type": "object", - "title": "Example configuration", + "title": "Pine", "properties": { "pineLanguageServer.maxNumberOfProblems": { "scope": "resource", @@ -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'." } } }