]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Support using a particular offset encoding in LSP messages
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 18 Jun 2023 15:24:27 +0000 (08:24 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 18 Jun 2023 15:24:27 +0000 (08:24 -0700)
autoload/lsp/capabilities.vim
autoload/lsp/lsp.vim
autoload/lsp/lspserver.vim
doc/lsp.txt

index 9df58deded31714a3b23934964dcc673d86e8036..d2719e049e6d03198525bd9b61d2eb231db347f4 100644 (file)
@@ -14,6 +14,10 @@ export def ProcessServerCaps(lspserver: dict<any>, caps: dict<any>)
     serverEncoding = lspserver.caps['~additionalInitResult_offsetEncoding']
   endif
 
+  if lspserver.forceOffsetEncoding != ''
+    serverEncoding = lspserver.forceOffsetEncoding
+  endif
+
   # one of 'utf-8', 'utf-16' or 'utf-32'
   if serverEncoding == 'utf-8'
     lspserver.posEncoding = 8
index 730527a1bc906ed62ad4494ba6d57408143ea67f..56c1b4724e717dbc6e82a7824463b238557deedb 100644 (file)
@@ -614,6 +614,14 @@ export def AddServer(serverList: list<dict<any>>)
       server.initializationOptions = {}
     endif
 
+    if !server->has_key('forceOffsetEncoding')
+       || server.forceOffsetEncoding->type() != v:t_string
+       || (server.forceOffsetEncoding != 'utf-8'
+           && server.forceOffsetEncoding != 'utf-16'
+           && server.forceOffsetEncoding != 'utf-32')
+      server.forceOffsetEncoding = ''
+    endif
+
     if !server->has_key('customNotificationHandlers')
        || server.customNotificationHandlers->type() != v:t_dict
       server.customNotificationHandlers = {}
index 11c4afa753e16ef74fa67324b4025baf38fa04f2..d05ff37de8b38b8a174ea67749f5e44a0fcfd372 100644 (file)
@@ -1740,12 +1740,6 @@ export def NewLspServer(serverParams: dict<any>): dict<any>
     name: serverParams.name,
     path: serverParams.path,
     args: serverParams.args->deepcopy(),
-    syncInit: serverParams.syncInit,
-    initializationOptions: serverParams.initializationOptions->deepcopy(),
-    customNotificationHandlers: serverParams.customNotificationHandlers->deepcopy(),
-    customRequestHandlers: serverParams.customRequestHandlers->deepcopy(),
-    processDiagHandler: serverParams.processDiagHandler,
-    features: serverParams.features->deepcopy(),
     running: false,
     ready: false,
     job: v:none,
@@ -1753,24 +1747,31 @@ export def NewLspServer(serverParams: dict<any>): dict<any>
     nextID: 1,
     caps: {},
     requests: {},
+    callHierarchyType: '',
+    completionTriggerChars: [],
+    customNotificationHandlers: serverParams.customNotificationHandlers->deepcopy(),
+    customRequestHandlers: serverParams.customRequestHandlers->deepcopy(),
+    debug: serverParams.debug,
+    features: serverParams.features->deepcopy(),
+    forceOffsetEncoding: serverParams.forceOffsetEncoding,
+    initializationOptions: serverParams.initializationOptions->deepcopy(),
+    messages: [],
+    omniCompletePending: false,
+    peekSymbolFilePopup: -1,
+    peekSymbolPopup: -1,
+    processDiagHandler: serverParams.processDiagHandler,
     rootSearchFiles: serverParams.rootSearch->deepcopy(),
     runIfSearchFiles: serverParams.runIfSearch->deepcopy(),
     runUnlessSearchFiles: serverParams.runUnlessSearch->deepcopy(),
-    omniCompletePending: false,
-    completionTriggerChars: [],
+    selection: {},
     signaturePopup: -1,
-    typeHierPopup: -1,
+    syncInit: serverParams.syncInit,
+    traceLevel: serverParams.traceLevel,
     typeHierFilePopup: -1,
-    workspaceSymbolPopup: -1,
-    workspaceSymbolQuery: '',
-    peekSymbolPopup: -1,
-    peekSymbolFilePopup: -1,
-    callHierarchyType: '',
-    selection: {},
+    typeHierPopup: -1,
     workspaceConfig: serverParams.workspaceConfig->deepcopy(),
-    messages: [],
-    debug: serverParams.debug,
-    traceLevel: serverParams.traceLevel
+    workspaceSymbolPopup: -1,
+    workspaceSymbolQuery: ''
   }
   lspserver.logfile = $'lsp-{lspserver.name}.log'
   lspserver.errfile = $'lsp-{lspserver.name}.err'
index 4040ad459fd53fe475de7f1d0936206f407990fe..40a962201230b6817ddf8329737ea79c53cfcf91 100644 (file)
@@ -3,7 +3,7 @@
 
 Author: Yegappan Lakshmanan  (yegappan AT yahoo DOT com)
 For Vim version 9.0 and above
-Last change: June 7, 2023
+Last change: June 18, 2023
 
 ==============================================================================
 CONTENTS                                                     *lsp-contents*
@@ -321,17 +321,30 @@ Additionally the following configurations can be made:
                        request replies which you might want to silence or
                        handle.  The provided request handlers will be called
                        with a reference to the "lspserver" and the "request".
-                                               *lsp-cfg-features*
-       features
+
+       features                                *lsp-cfg-features*
                        (Optional) toggle which features should be enabled for
                        a given language server. See |lsp-multiple-servers|
                        and |lsp-features| for more information.
+
+       forceOffsetEncoding                     *lsp-cfg-forceOffsetEncoding*
+                       (Optional) a |String| value that forces the use of a
+                       specific offset encoding in LSP messages.  If this
+                       option is not specified, then the UTF offset encoding
+                       is negotiated with the server during initialization.
+                       Supported values are 'utf-8' or 'utf-16' or 'utf-32'.
+                       The Vim native offset encoding is 'utf-32'.  For the
+                       'utf-8' and 'utf-16' encodings, the offsets need to be
+                       encoded and decoded in every LSP message and will
+                       incur some overhead.
+
                                                *lsp-cfg-omnicompl*
        omnicompl       (Optional) a boolean value that enables (true)
                        or disables (false) omni-completion for these file
                        types. By default this is set to "v:true".  This value
                        is applicable only if auto completion is disabled
                        (|lsp-opt-autoComplete|).
+
                                                *lsp-cfg-processDiagHandler*
        processDiagHandler
                        (Optional) A |Funcref| or |lambda| that takes a list
@@ -378,12 +391,14 @@ Additionally the following configurations can be made:
                        call is used to initialize the language server,
                        otherwise the server is initialized asynchronously.
                        By default this is set to "false".
+
                                                *lsp-cfg-debug*
        debug           (Optional) log the messages printed by this language
                        server in stdout and stderr to a file.  Useful for
                        debugging a language server.  By default the
                        messages are not logged.  See |lsp-debug| for more
                        information.
+
                                                *lsp-cfg-traceLevel*
        traceLevel      (Optional) set the debug trace level for this language
                        server.  Supported values are: "off", "debug" and