Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get rid of Error from the language Server (Server Not Initialized error)? #45

Open
wyuenho opened this issue Jun 23, 2018 · 8 comments

Comments

@wyuenho
Copy link
Contributor

wyuenho commented Jun 23, 2018

I keep getting this error for some reason:

Error from the Language Server: /path/to/src.c is being indexed. (Server Not Initialized) [11 times]

How do I wait for the server to be fully initialized before turning on lsp-ui-mode?

@wyuenho
Copy link
Contributor Author

wyuenho commented Jul 21, 2018

My config is fine. There's no reason enabling a lsp language server in a mode hook should result in an error.

@innerout
Copy link

@wyuenho Try this in your config

(add-hook 'lsp-after-open-hook 'lsp-ui-mode) 

@wyuenho
Copy link
Contributor Author

wyuenho commented Jul 22, 2018

That's what I used to have. Same problem.

@innerout
Copy link

innerout commented Jul 22, 2018

This error happened to me today for the first time but the plugin worked properly.
Could we ignore it?
Also i dont see this error when i defer lsp-ui for 5 seconds.

@wyuenho
Copy link
Contributor Author

wyuenho commented Jul 22, 2018

I can ignore it mentally but not practically. Anything printed into the echo area may cover up the previous one which you really care about.

This is an endemic problem across all kinds of language servers. This problem smells like a critical design flaw to me that I haven't had the time to dig into yet.

@FirstLoveLife
Copy link

I also decide to ignore it mentally.

@FirstLoveLife
Copy link

Wait, I found this warning only occur when the file was just edited. jacobdufault/cquery#206 . You can try reopen emacs/file, then the warning will disappear(at least for me).

@mneilly
Copy link

mneilly commented Nov 4, 2018

I see this when there are C++ standard headers that take time to index. It can be reproduced by creating compile_commands.json (and deleting any existing .cquery_cached_index directory) then calling emacs to edit the file.

The following doesn't exhibit the error message because there's very little to index:

struct Foo
{
  int x, y, z;
};

int main(int argc, char** argv)
{
  Foo mFoo;
}

But if I add standard headers (again deleting .cquery_cached_index before executing emacs) then I do see the message until indexing of the headers is complete:

#include <cstdio>
#include <iostream>
#include <fstream>

struct Foo
{
  int x, y, z;
};

int main(int argc, char** argv)
{
  Foo mFoo;
}

Note that the message itself actually comes from lsp-mode:

$ egrep -HIr 'Error from the Language Server' ~/.emacs.d/elpa
/home/mneilly/.emacs.d/elpa/lsp-mode-20181103.2101/lsp-io.el:    (format "Error from the Language Server: %s (%s)"

It looks like lsp sends initialize, server sends $cquery/progress, server sends initialize result, lsp sends initialized, lsp sends textDocument/didOpen, lsp sends textDocument/codeAction then the server responds with the 32002 error and a message stating that the file is being indexed.

lsp-mode appears to just display the message to the user. I'm not sure if 32002 is the appropriate error message or whether lsp should do any error handling for this. Since it is an indexing issue it would be nice to get an indicator that indexing is still ongoing rather than an error message.

lsp--stdio-wait: Content-Length: 1731^M
^M
{
  "jsonrpc": "2.0",
  "method": "initialize",
  "params": {
    "processId": 18042,
    "rootPath": "/home/mneilly/Projects/std-header/",
    "rootUri": "file:///home/mneilly/Projects/std-header/",
    "capabilities": {
      "workspace": {
        "applyEdit": true,
        "executeCommand": {
          "dynamicRegistration": true
        },
        "workspaceFolders": true
      },
      "textDocument": {
        "synchronization": {
          "willSave": true,
          "didSave": true,
          "willSaveWaitUntil": true
        },
        "documentSymbol": {
          "symbolKind": {
            "valueSet": [
              1,
              2,
              3,
              4,
              5,
              6,
              7,
              8,
              9,
              10,
              11,
              12,
              13,
              14,
              15,
              16,
              17,
              18,
              19,
              20,
              21,
              22,
              23,
              24,
              25
            ]
          },
          "hierarchicalDocumentSymbolSupport": true
        },
        "formatting": {
          "dynamicRegistration": true
        },
        "codeAction": {
          "dynamicRegistration": true
        },
        "completion": {
          "completionItem": {
            "snippetSupport": true
          }
        }
      }
    },
    "initializationOptions": {
      "index": {
        "comments": 2
      },
      "cacheFormat": "msgpack",
      "cacheDirectory": "/home/mneilly/Projects/std-header/.cquery_cached_index/",
      "highlight": {
        "enabled": false
      },
      "emitInactiveRegions": true
    }
  },
  "id": 1
}
Output from language server: {
  "jsonrpc": "2.0",
  "method": "$cquery/progress",
  "params": {
    "indexRequestCount": 0,
    "doIdMapCount": 0,
    "onIdMappedCount": 0,
    "onIndexedCount": 0,
    "activeThreads": 0
  }
}
Output from language server: {
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "capabilities": {
      "textDocumentSync": 2,
      "hoverProvider": true,
      "completionProvider": {
        "resolveProvider": false,
        "triggerCharacters": [
          ".",
          ":",
          ">",
          "#",
          "<",
          "\"",
          "/"
        ]
      },
      "signatureHelpProvider": {
        "triggerCharacters": [
          "(",
          ","
        ]
      },
      "definitionProvider": true,
      "typeDefinitionProvider": true,
      "implementationProvider": true,
      "referencesProvider": true,
      "documentHighlightProvider": true,
      "documentSymbolProvider": true,
      "workspaceSymbolProvider": true,
      "codeActionProvider": true,
      "codeLensProvider": {
        "resolveProvider": false
      },
      "documentFormattingProvider": true,
      "documentRangeFormattingProvider": false,
      "renameProvider": true,
      "documentLinkProvider": {
        "resolveProvider": true
      },
      "executeCommandProvider": {
        "commands": []
      }
    }
  }
}
lsp--send-no-wait: Content-Length: 68^M
^M
{
  "jsonrpc": "2.0",
  "method": "initialized",
  "params": {
  }
}
lsp--send-no-wait: Content-Length: 387^M
^M
{
  "jsonrpc": "2.0",
  "method": "textDocument/didOpen",
  "params": {
    "textDocument": {
      "uri": "file:///home/mneilly/Projects/std-header/test.cc",
      "languageId": "cpp",
      "version": 0,
      "text": "\n#include <cstdio>\n#include <iostream>\n#include <fstream>\n\nstruct Foo\n{\n  int x, y, z;\n};\n\nint main(int argc, char** argv)\n{\n  Foo mFoo;\n}\n"
    }
  }
}
lsp--send-no-wait: Content-Length: 386^M
^M
{
  "jsonrpc": "2.0",
  "method": "textDocument/codeAction",
  "params": {
    "textDocument": {
      "uri": "file:///home/mneilly/Projects/std-header/test.cc"
    },
    "range": {
      "start": {
        "line": 0,
        "character": 0
      },
      "end": {
        "line": 0,
        "character": 0
      }
    },
    "context": {
      "diagnostics": []
    }
  },
  "id": 2
}
Output from language server: {
  "jsonrpc": "2.0",
  "id": 2,
  "error": {
    "code": -32002,
    "message": "/home/mneilly/Projects/std-header/test.cc is being indexed."
  }
}
Error from the Language Server: /home/mneilly/Projects/std-header/test.cc is being indexed. (Server Not Initialized)

If you simply want to filter out the message you can tweak cquery.el as follows then set the custom variable cquery-ignore-regexps to '("is being indexed")

--- /home/mneilly/.emacs.d/elpa/cquery-20180811.2131/cquery.el  2018-11-03 23:00:29.152756370 -0700
+++ ./cquery.el 2018-11-03 22:58:16.462434933 -0700
@@ -49,6 +49,12 @@
 ;;   Customization
 ;; ---------------------------------------------------------------------

+(defcustom cquery-ignore-regexps
+  nil
+  "Keyword argument to pass to lsp-mode to filter messages."
+  :type '(regexp)
+  :group 'cquery)
+
 (defcustom cquery-executable
   "cquery"
   "Path of the cquery executable."
@@ -242,6 +248,7 @@
 (lsp-define-stdio-client
  lsp-cquery "cpp" #'cquery--get-root
  `(,cquery-executable ,@cquery-extra-args)
+ :ignore-regexps `(,@cquery-ignore-regexps)
  :initialize #'cquery--initialize-client
  :extra-init-params #'cquery--get-init-params)

$cquery/progress seems to always be zero or that might be a way to see that things are still being indexed. It seems it is intentionally always zero though per the following pull request?

jacobdufault/cquery#87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants