Package dk.gtz.graphedit.spi
Class GrpcLanguageServer
java.lang.Object
dk.gtz.graphedit.spi.GrpcLanguageServer
- All Implemented Interfaces:
ILanguageServer
Language server base class for wiring a gRPC based language server with graphedit.
Extend this clas and override the appropriate subprocess invocation parts to seamlessly integrate your MLSP implementation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected IBufferContainer
Reference to the current editor buffercontainerprotected int
Time (in milliseconds) to wait between failed connection attemptsprotected final dk.gtz.graphedit.proto.Empty
Utility instance of the gRPC Empty value.protected final String
Host string, pointing to the connected language serverprotected int
Maximum amount of attempts to connect to the language serverprotected final int
Host port, pointing to the connected language serverprotected final Thread
The thread in which the language server process is runningprotected final dk.yalibs.yalazy.Lazy<dk.gtz.graphedit.proto.ServerInfo>
Lazy loaded server info struct.protected final dk.yalibs.yalazy.Lazy<dk.gtz.graphedit.proto.LanguageServerGrpc.LanguageServerStub>
Lazy loaded gRPC language server stub interface instance. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
GrpcLanguageServer
(String host, int port, String command, List<String> arguments) Constructs a new GrpcLanguageServer instanceprotected
GrpcLanguageServer
(String command, List<String> arguments) Constructs a new GrpcLanguageServer instance -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDiagnosticsCallback
(dk.yalibs.yafunc.IRunnable1<Collection<ModelLint>> callback) Add a callback function to call when diagnostics are updated.void
addNotificationCallback
(dk.yalibs.yafunc.IRunnable1<ModelNotification> callback) Add a callback function to call when a notification is presented.void
addProgressCallback
(dk.yalibs.yafunc.IRunnable1<ModelLanguageServerProgress> callback) Add a callback function to call when language server progress notification happens.protected dk.gtz.graphedit.proto.LanguageServerGrpc.LanguageServerStub
connect()
Connect to the language server.Get all the diagnostics that are currently known to the server.Get the name of the language that the server supports.protected dk.gtz.graphedit.proto.ServerInfo
Get the information about the language server.Get the name of the language server (not to be confused withILanguageServer.getLanguageName()
)Get the version string of the language server.protected void
handleDiff
(dk.gtz.graphedit.proto.Diff diff) Tell the connected language server to handle the provided diffvoid
initialize
(File projectFile, IBufferContainer bufferContainer) Function to initialize (not start) the language server This will be called right before any callback functions are addedprotected boolean
isServerCapable
(dk.gtz.graphedit.proto.Capability capability) Check if the language server reports that it is capable of some feature.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dk.gtz.graphedit.spi.ILanguageServer
start
-
Field Details
-
stub
protected final dk.yalibs.yalazy.Lazy<dk.gtz.graphedit.proto.LanguageServerGrpc.LanguageServerStub> stubLazy loaded gRPC language server stub interface instance. Use this to interact with the connected language server. -
serverInfo
protected final dk.yalibs.yalazy.Lazy<dk.gtz.graphedit.proto.ServerInfo> serverInfoLazy loaded server info struct. -
empty
protected final dk.gtz.graphedit.proto.Empty emptyUtility instance of the gRPC Empty value. -
bufferContainer
Reference to the current editor buffercontainer -
host
Host string, pointing to the connected language server -
port
protected final int portHost port, pointing to the connected language server -
programThread
The thread in which the language server process is running -
maxConnectionAttempts
protected int maxConnectionAttemptsMaximum amount of attempts to connect to the language server -
connectionAttemptWaitMilliseconds
protected int connectionAttemptWaitMillisecondsTime (in milliseconds) to wait between failed connection attempts
-
-
Constructor Details
-
GrpcLanguageServer
Constructs a new GrpcLanguageServer instance- Parameters:
command
- The subprocess command to execute at startuparguments
- The arguments to provide to the subprocess command
-
GrpcLanguageServer
Constructs a new GrpcLanguageServer instance- Parameters:
host
- The gRPC host to connect toport
- The gRPC port to connect tocommand
- The subprocess command to execute at startuparguments
- The arguments to provide to the subprocess command
-
-
Method Details
-
connect
protected dk.gtz.graphedit.proto.LanguageServerGrpc.LanguageServerStub connect()Connect to the language server.- Returns:
- A new language server stub instance
-
getServerInfo
protected dk.gtz.graphedit.proto.ServerInfo getServerInfo()Get the information about the language server.- Returns:
- A class of language server information
-
isServerCapable
protected boolean isServerCapable(dk.gtz.graphedit.proto.Capability capability) Check if the language server reports that it is capable of some feature.- Parameters:
capability
- The feature capability- Returns:
true
if the server reports that it is capable of the provided feature, otherwisefalse
-
getLanguageName
Description copied from interface:ILanguageServer
Get the name of the language that the server supports. Expected to match whatISyntaxFactory.getSyntaxName()
provides- Specified by:
getLanguageName
in interfaceILanguageServer
- Returns:
- A string with the name of the supported language.
-
getServerName
Description copied from interface:ILanguageServer
Get the name of the language server (not to be confused withILanguageServer.getLanguageName()
)- Specified by:
getServerName
in interfaceILanguageServer
- Returns:
- A string representing the name of the language server
-
getServerVersion
Description copied from interface:ILanguageServer
Get the version string of the language server. i.e. "v1.0.0"- Specified by:
getServerVersion
in interfaceILanguageServer
- Returns:
- A string representing the version of the language server
-
handleDiff
protected void handleDiff(dk.gtz.graphedit.proto.Diff diff) Tell the connected language server to handle the provided diff- Parameters:
diff
- The diff for the connected server to handle
-
initialize
Description copied from interface:ILanguageServer
Function to initialize (not start) the language server This will be called right before any callback functions are added- Specified by:
initialize
in interfaceILanguageServer
- Parameters:
projectFile
- The Graphedit project file. Note that this can also just be a temporary directorybufferContainer
- The collection of buffers, likely (but not guaranteed) to be empty at initialization
-
getDiagnostics
Description copied from interface:ILanguageServer
Get all the diagnostics that are currently known to the server.- Specified by:
getDiagnostics
in interfaceILanguageServer
- Returns:
- A collection of lints.
-
addDiagnosticsCallback
Description copied from interface:ILanguageServer
Add a callback function to call when diagnostics are updated. Note that the callback expects a complete collection of lints.- Specified by:
addDiagnosticsCallback
in interfaceILanguageServer
- Parameters:
callback
- The function to call when the diagnostics collections change.
-
addNotificationCallback
Description copied from interface:ILanguageServer
Add a callback function to call when a notification is presented.- Specified by:
addNotificationCallback
in interfaceILanguageServer
- Parameters:
callback
- The function to call when a notification should be shown.
-
addProgressCallback
Description copied from interface:ILanguageServer
Add a callback function to call when language server progress notification happens.- Specified by:
addProgressCallback
in interfaceILanguageServer
- Parameters:
callback
- The function to call when a progress notification should be shown.
-