Class GrpcLanguageServer

java.lang.Object
dk.gtz.graphedit.spi.GrpcLanguageServer
All Implemented Interfaces:
ILanguageServer

public abstract class GrpcLanguageServer extends Object implements 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 Details

    • stub

      protected final dk.yalibs.yalazy.Lazy<dk.gtz.graphedit.proto.LanguageServerGrpc.LanguageServerStub> stub
      Lazy 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> serverInfo
      Lazy loaded server info struct.
    • empty

      protected final dk.gtz.graphedit.proto.Empty empty
      Utility instance of the gRPC Empty value.
    • bufferContainer

      protected IBufferContainer bufferContainer
      Reference to the current editor buffercontainer
    • host

      protected final String host
      Host string, pointing to the connected language server
    • port

      protected final int port
      Host port, pointing to the connected language server
    • programThread

      protected final Thread programThread
      The thread in which the language server process is running
    • maxConnectionAttempts

      protected int maxConnectionAttempts
      Maximum amount of attempts to connect to the language server
    • connectionAttemptWaitMilliseconds

      protected int connectionAttemptWaitMilliseconds
      Time (in milliseconds) to wait between failed connection attempts
  • Constructor Details

    • GrpcLanguageServer

      protected GrpcLanguageServer(String command, List<String> arguments)
      Constructs a new GrpcLanguageServer instance
      Parameters:
      command - The subprocess command to execute at startup
      arguments - The arguments to provide to the subprocess command
    • GrpcLanguageServer

      protected GrpcLanguageServer(String host, int port, String command, List<String> arguments)
      Constructs a new GrpcLanguageServer instance
      Parameters:
      host - The gRPC host to connect to
      port - The gRPC port to connect to
      command - The subprocess command to execute at startup
      arguments - 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, otherwise false
    • getLanguageName

      public String getLanguageName()
      Description copied from interface: ILanguageServer
      Get the name of the language that the server supports. Expected to match what ISyntaxFactory.getSyntaxName() provides
      Specified by:
      getLanguageName in interface ILanguageServer
      Returns:
      A string with the name of the supported language.
    • getServerName

      public String getServerName()
      Description copied from interface: ILanguageServer
      Get the name of the language server (not to be confused with ILanguageServer.getLanguageName())
      Specified by:
      getServerName in interface ILanguageServer
      Returns:
      A string representing the name of the language server
    • getServerVersion

      public String getServerVersion()
      Description copied from interface: ILanguageServer
      Get the version string of the language server. i.e. "v1.0.0"
      Specified by:
      getServerVersion in interface ILanguageServer
      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

      public void initialize(File projectFile, IBufferContainer bufferContainer)
      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 interface ILanguageServer
      Parameters:
      projectFile - The Graphedit project file. Note that this can also just be a temporary directory
      bufferContainer - The collection of buffers, likely (but not guaranteed) to be empty at initialization
    • getDiagnostics

      public Collection<ModelLint> getDiagnostics()
      Description copied from interface: ILanguageServer
      Get all the diagnostics that are currently known to the server.
      Specified by:
      getDiagnostics in interface ILanguageServer
      Returns:
      A collection of lints.
    • addDiagnosticsCallback

      public void addDiagnosticsCallback(dk.yalibs.yafunc.IRunnable1<Collection<ModelLint>> callback)
      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 interface ILanguageServer
      Parameters:
      callback - The function to call when the diagnostics collections change.
    • addNotificationCallback

      public void addNotificationCallback(dk.yalibs.yafunc.IRunnable1<ModelNotification> callback)
      Description copied from interface: ILanguageServer
      Add a callback function to call when a notification is presented.
      Specified by:
      addNotificationCallback in interface ILanguageServer
      Parameters:
      callback - The function to call when a notification should be shown.
    • addProgressCallback

      public void addProgressCallback(dk.yalibs.yafunc.IRunnable1<ModelLanguageServerProgress> callback)
      Description copied from interface: ILanguageServer
      Add a callback function to call when language server progress notification happens.
      Specified by:
      addProgressCallback in interface ILanguageServer
      Parameters:
      callback - The function to call when a progress notification should be shown.