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 IBufferContainerReference to the current editor buffercontainerprotected intTime (in milliseconds) to wait between failed connection attemptsprotected final dk.gtz.graphedit.proto.EmptyUtility instance of the gRPC Empty value.protected final StringHost string, pointing to the connected language serverprotected intMaximum amount of attempts to connect to the language serverprotected final intHost port, pointing to the connected language serverprotected final ThreadThe 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
ConstructorsModifierConstructorDescriptionprotectedGrpcLanguageServer(String host, int port, String command, List<String> arguments) Constructs a new GrpcLanguageServer instanceprotectedGrpcLanguageServer(String command, List<String> arguments) Constructs a new GrpcLanguageServer instance -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDiagnosticsCallback(dk.yalibs.yafunc.IRunnable1<Collection<ModelLint>> callback) Add a callback function to call when diagnostics are updated.voidaddNotificationCallback(dk.yalibs.yafunc.IRunnable1<ModelNotification> callback) Add a callback function to call when a notification is presented.voidaddProgressCallback(dk.yalibs.yafunc.IRunnable1<ModelLanguageServerProgress> callback) Add a callback function to call when language server progress notification happens.protected dk.gtz.graphedit.proto.LanguageServerGrpc.LanguageServerStubconnect()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.ServerInfoGet 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 voidhandleDiff(dk.gtz.graphedit.proto.Diff diff) Tell the connected language server to handle the provided diffvoidinitialize(File projectFile, IBufferContainer bufferContainer) Function to initialize (not start) the language server This will be called right before any callback functions are addedprotected booleanisServerCapable(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, waitMethods 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:
trueif the server reports that it is capable of the provided feature, otherwisefalse
-
getLanguageName
Description copied from interface:ILanguageServerGet the name of the language that the server supports. Expected to match whatISyntaxFactory.getSyntaxName()provides- Specified by:
getLanguageNamein interfaceILanguageServer- Returns:
- A string with the name of the supported language.
-
getServerName
Description copied from interface:ILanguageServerGet the name of the language server (not to be confused withILanguageServer.getLanguageName())- Specified by:
getServerNamein interfaceILanguageServer- Returns:
- A string representing the name of the language server
-
getServerVersion
Description copied from interface:ILanguageServerGet the version string of the language server. i.e. "v1.0.0"- Specified by:
getServerVersionin 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:ILanguageServerFunction to initialize (not start) the language server This will be called right before any callback functions are added- Specified by:
initializein 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:ILanguageServerGet all the diagnostics that are currently known to the server.- Specified by:
getDiagnosticsin interfaceILanguageServer- Returns:
- A collection of lints.
-
addDiagnosticsCallback
Description copied from interface:ILanguageServerAdd a callback function to call when diagnostics are updated. Note that the callback expects a complete collection of lints.- Specified by:
addDiagnosticsCallbackin interfaceILanguageServer- Parameters:
callback- The function to call when the diagnostics collections change.
-
addNotificationCallback
Description copied from interface:ILanguageServerAdd a callback function to call when a notification is presented.- Specified by:
addNotificationCallbackin interfaceILanguageServer- Parameters:
callback- The function to call when a notification should be shown.
-
addProgressCallback
Description copied from interface:ILanguageServerAdd a callback function to call when language server progress notification happens.- Specified by:
addProgressCallbackin interfaceILanguageServer- Parameters:
callback- The function to call when a progress notification should be shown.
-