Skip to content

Commit

Permalink
Upgrade language client and debugger protocol package (#315)
Browse files Browse the repository at this point in the history
* update languageclient to 9.0.1

* remove duplicate of inlayhints after languageclient migration

* fix crash when unicode chararcter are use in function names

* fix language client migration

* fix upgrade debugger version
  • Loading branch information
pgourlain authored Oct 28, 2024
1 parent d8bcf55 commit 0e640e9
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 270 deletions.
19 changes: 13 additions & 6 deletions apps/erlangbridge/src/lsp_handlers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
textDocument_didOpen/2, textDocument_didClose/2, textDocument_didSave/2, textDocument_didChange/2,
textDocument_definition/2, textDocument_references/2, textDocument_hover/2, textDocument_completion/2,
textDocument_formatting/2, textDocument_codeLens/2, textDocument_documentSymbol/2,
textDocument_inlayHints/2, textDocument_signatureHelp/2, textDocument_prepareRename/2, textDocument_rename/2]).
-export([textDocument_inlineValues/2]).
textDocument_signatureHelp/2, textDocument_prepareRename/2, textDocument_rename/2]).
-export([textDocument_inlineValues/2, textDocument_inlineValue/2]).
-export([textDocument_inlayHints/2, textDocument_inlayHint/2]).

-include("lsp_log.hrl").

Expand Down Expand Up @@ -239,6 +240,10 @@ textDocument_codeLens(_Socket, Params) ->
end, [], lsp_navigation:codelens_info(lsp_utils:file_uri_to_file(Uri)))
end.


textDocument_inlayHint(_Socket, Params) ->
textDocument_inlayHints(_Socket, Params).

textDocument_inlayHints(_Socket, Params) ->
%gen_lsp_server:lsp_log("textDocument_inlayHints ~p", [Params]),
Uri = mapmapget(textDocument, uri, Params),
Expand Down Expand Up @@ -273,13 +278,15 @@ textDocument_documentSymbol(_Socket, Params) ->
}
end, lsp_navigation:symbol_info(lsp_utils:file_uri_to_file(Uri))).


textDocument_inlineValue(_Socket, Params) ->
textDocument_inlineValues(_Socket, Params).

% provide inlive values while debugging (values are shown directly in editor)
textDocument_inlineValues(_Socket, Params) ->
Uri = mapmapget(textDocument, uri, Params),
%#{line:=LS, character:=CS} = mapmapget(range, start, Params),
% no inlivevalues after 'stoppedLocation'
%#{line:=LE, character:=CE} = mapmapget(range, 'end', Params),
#{line:=LE, character:=CE} = mapmapget(stoppedLocation, 'end', Params),
ContextMap = maps:get(context, Params),
#{line:=LE, character:=CE} = mapmapget(stoppedLocation, 'end', ContextMap),
lists:map(fun ({Kind, Position, Label}) ->
#{
position => lsp_utils:client_position(Position),
Expand Down
3 changes: 2 additions & 1 deletion apps/erlangbridge/src/lsp_inlayhints.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ internal_inlayhint_analyze(SyntaxTree, _CurrentFile, #{defs := Defs, calls := Ca
%{call,{32,5},{remote,{32,15},{atom,{32,5},sample_lib}, {atom,{32,16},fn_utils1}},[{var,{32,26},'X'}]}
{call, _LocationCall, {remote, _, {atom, _,ModuleName}, {atom, _, FName}}, Args} ->
%to avoid collision with local function name, add module as prefix
FuncName = lists:flatten(io_lib:format("~s.~s", [ModuleName, FName])),
% ~p to avoid crash on function name with unicode characters
FuncName = lists:flatten(io_lib:format("~s.~p", [ModuleName, FName])),
case get_remote_function_content(ModuleName, FName) of
{true, RemoteFuns} ->
F = #{
Expand Down
5 changes: 4 additions & 1 deletion lib/ErlangShellDebugger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChildProcess, spawn } from 'child_process';
import { EventEmitter } from 'events';
import { GenericShell, ILogOutput } from './GenericShell';
import { DebugProtocol } from 'vscode-debugprotocol';
import { DebugProtocol } from '@vscode/debugprotocol';
import * as path from 'path';
import * as os from 'os';
import * as fs from 'fs';
Expand Down Expand Up @@ -33,6 +33,9 @@ export class FunctionBreakpoint implements DebugProtocol.Breakpoint {
this.functionName = fn;
this.arity = a;
}
public setId(id: number): void{
this.id = id;
}
}

// export interface IErlangShellOutputForDebugging {
Expand Down
2 changes: 1 addition & 1 deletion lib/erlangDebugConnection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ErlangConnection} from './erlangConnection';
import { DebugProtocol } from 'vscode-debugprotocol';
import { DebugProtocol } from '@vscode/debugprotocol';
import { FunctionBreakpoint } from './ErlangShellDebugger';


Expand Down
4 changes: 2 additions & 2 deletions lib/erlangDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
DebugSession, InitializedEvent, TerminatedEvent, StoppedEvent,
OutputEvent, Thread, ThreadEvent, StackFrame, Scope, Source, Handles
, Breakpoint, ModuleEvent, Module, ContinuedEvent, Variable, BreakpointEvent
} from 'vscode-debugadapter';
import { DebugProtocol } from 'vscode-debugprotocol';
} from '@vscode/debugadapter';
import { DebugProtocol } from '@vscode/debugprotocol';
import { ErlangShellForDebugging, LaunchRequestArguments, FunctionBreakpoint } from './ErlangShellDebugger';
import { ILogOutput } from './GenericShell';
import * as path from 'path';
Expand Down
12 changes: 6 additions & 6 deletions lib/lsp/lsp-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export class ErlangLanguageClient extends LanguageClient {
// prompt up the failure to users.
outChannel?: vscode.OutputChannel;

handleFailedRequest<T>(type: MessageSignature, error: any,
defaultValue: T): T {
handleFailedRequest<T>(type: MessageSignature, token: vscode.CancellationToken | undefined, error: any, defaultValue: T, showNotification?: boolean): T {

if (error instanceof ResponseError && type.method === 'workspace/executeCommand') {
//show an error popup at lower right in vscode
vscode.window.showErrorMessage(error.message);
}
return super.handleFailedRequest(type, error, defaultValue);
return super.handleFailedRequest(type, token, error, defaultValue);
}

constructor(name: string, serverOptions: ServerOptions,
Expand All @@ -41,10 +41,10 @@ export class ErlangLanguageClient extends LanguageClient {
this.outChannel = lspOutputChannel;
}


onReady(): Promise<void> {
public onReady(): void {
this.outChannel?.appendLine("LanguageClient is ready");
clientIsReady = true;
return super.onReady();
//not more needed
//return super.onReady();
}
}
107 changes: 0 additions & 107 deletions lib/lsp/lsp-inlayhints.ts

This file was deleted.

12 changes: 4 additions & 8 deletions lib/lsp/lspclientextension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import * as Net from 'net';

import * as lspcodelens from './lspcodelens';

import * as lspInlay from './lsp-inlayhints';
import * as lspValue from './lsp-inlinevalues';
import * as lspRename from './lsp-rename';

Expand Down Expand Up @@ -95,12 +94,10 @@ namespace Configuration {
export function initialize() {
//force to read configuration
lspcodelens.configurationChanged();
lspInlay.configurationChanged();
// VS Code currently doesn't sent fine grained configuration changes. So we
// listen to any change. However this will change in the near future.
configurationListener = Workspace.onDidChangeConfiguration(() => {
lspcodelens.configurationChanged();
lspInlay.configurationChanged();
client.sendNotification(DidChangeConfigurationNotification.type, { settings: null });
});
fileSystemWatcher = workspace.createFileSystemWatcher('**/*.erl');
Expand Down Expand Up @@ -208,7 +205,6 @@ export function activate(context: ExtensionContext) {
if (erlangCfg.verbose)
lspOutputChannel = Window.createOutputChannel('Erlang Language Server');

lspInlay.activate(context, lspOutputChannel);
lspValue.activate(context, lspOutputChannel);
lspRename.activate(context, lspOutputChannel);

Expand All @@ -222,10 +218,10 @@ export function activate(context: ExtensionContext) {
resolveCodeLens: (codeLens) => {
return Promise.resolve(lspcodelens.onResolveCodeLenses(codeLens)).then(x => x);
},
didSave: (data: TextDocument, next: (data: TextDocument) => void) => {
next(data);//call LSP
didSave: async (data, next) => {
await next(data);//call LSP
lspcodelens.onDocumentDidSave();
},
}
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
Expand Down Expand Up @@ -258,7 +254,7 @@ export function activate(context: ExtensionContext) {
},
undefined);
//
client.onReady();
(<ErlangLanguageClient>client).onReady();
});
});
}, clientOptions, lspOutputChannel, true);
Expand Down
Loading

0 comments on commit 0e640e9

Please sign in to comment.