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

Initialize Language Server Error in VScode large workspace #312

Closed
jokervTv opened this issue Jul 25, 2023 · 7 comments · Fixed by #373
Closed

Initialize Language Server Error in VScode large workspace #312

jokervTv opened this issue Jul 25, 2023 · 7 comments · Fixed by #373
Labels
enhancement New feature or request

Comments

@jokervTv
Copy link

Describe the bug
Initialising Language Server Error in VScode.

To Reproduce
Open a large fortran workspace.

Start with posting:

fortls --debug_filepath mpas_atm_time_integration.F --debug_rootpath . --debug_log

Testing "initialize" request:
  Root = "."
REQUEST None None
fortls - Fortran Language Server 2.13.0 Initialized
  Successful with errors:
    fortls debugging enabled

  Source directories:
    C:\Users\****\src\core_atmosphere\dynamics
fortls --debug_filepath mpas_atm_time_integration.F --debug_rootpath . --debug_log --enable_code_actions --autocomplete_no_prefix --lowercase_intrinsics --nthreads=4 --incremental_sync

Testing "initialize" request:
  Root = "."
REQUEST None None

long time no output

Alternatively, you can try and describe the steps that you followed to encounter the bug:

  1. Open a large fortran file
  2. error on vscode output

Setup information (please complete the following information):

  • OS: windows
  • Python 3.11
  • fortls 2.13.0
  • Code editor used VS Code
  • Modern Fortran v3.2.0

Configuration information (please complete the following information):
Using default.

VScode Log

["INFO" - 14:29:50] Initialising Language Server for workspace: c:\Users\**\src\core_atmosphere\dynamics\mpas_atm_time_integration.F with command-line options: --enable_code_actions, --autocomplete_no_prefix, --lowercase_intrinsics, --nthreads=4, --incremental_sync
[Error - 14:30:11] Server initialization failed.
  Message: Error sending result: '<fortls.parse_fortran.FortranFile object at 0x000001ACEBEE63D0>'. Reason: 'RecursionError('maximum recursion depth exceeded while calling a Python object')'
  Code: -32603 
@jokervTv jokervTv added the bug Something isn't working label Jul 25, 2023
@gnikit gnikit added the investigate Issue requires research to see if it can be implemented label Jul 25, 2023
@gnikit
Copy link
Member

gnikit commented Jul 25, 2023

@jokervTv it appears you've reached a limitation of Python with regards to recursion.

Reason: 'RecursionError('maximum recursion depth exceeded while calling a Python object')'

Changing the recursion limit has adverse effects to general fortls behaviour, hence we won't be changing that.

To be sure however you will have to provide code for me to investigate. You can upload a zip file with the sources to the issue, limit 25MB.

@gnikit gnikit removed bug Something isn't working investigate Issue requires research to see if it can be implemented labels Jul 26, 2023
@jokervTv
Copy link
Author

Thank you so much for reading and for your prompt feedback.

The code file has been uploaded via the link:MPAS-Model.tar.gz

When I open the mpas_atm_time_integration.F file, located in MPAS-Model/src/core_atmosphere/dynamics/, I will receive the error message(RecursionError), and I also get the following error log through neovim LSP:

[START][2023-07-27 00:53:12] LSP logging initiated
[ERROR][2023-07-27 00:53:12] .../vim/lsp/rpc.lua:734    "rpc"   "/home/yp/.local/share/nvim/mason/bin/fortls"   "stderr"        "[WARN - 00:53:12] error handling request {'id': 1, 'method': 'initialize', 'params': {'rootUri': 'file:///home/yp/MPAS-Model', 'rootPath': '/home/yp/MPAS-Model', 'clientInfo': {'version': '0.9.1', 'name': 'Neovim'}, 'trace': 'off', 'capabilities': {'workspace': {'configuration': True, 'applyEdit': True, 'didChangeWatchedFiles': {'dynamicRegistration': False, 'relativePatternSupport': True}, 'workspaceEdit': {'resourceOperations': ['rename', 'create', 'delete']}, 'semanticTokens': {'refreshSupport': True}, 'symbol': {'dynamicRegistration': False, '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, 26]}, 'hierarchicalWorkspaceSymbolSupport': True}, 'workspaceFolders': True}, 'textDocument': {'references': {'dynamicRegistration': False}, 'semanticTokens': {'augmentsSyntaxTokens': True, 'serverCancelSupport': False, 'formats': ['relative'], 'tokenModifiers': ['declaration', 'definition', 'readonly', 'static', 'deprecated', 'abstract', 'async', 'modification', 'documentation', 'defaultLibrary'], 'overlappingTokenSupport': True, 'requests': {'range': False, 'full': {'delta': True}}, 'tokenTypes': ['namespace', 'type', 'class', 'enum', 'interface', 'struct', 'typeParameter', 'parameter', 'variable', 'property', 'enumMember', 'event', 'function', 'method', 'macro', 'keyword', 'modifier', 'comment', 'string', 'number', 'regexp', 'operator', 'decorator'], 'multilineTokenSupport': False, 'dynamicRegistration': False}, 'documentSymbol': {'dynamicRegistration': False, '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, 26]}, 'hierarchicalDocumentSymbolSupport': True}, 'documentHighlight': {'dynamicRegistration': False}, 'rename': {'dynamicRegistration': False, 'prepareSupport': True}, 'signatureHelp': {'dynamicRegistration': False, 'signatureInformation': {'documentationFormat': ['markdown', 'plaintext'], 'activeParameterSupport': True, 'parameterInformation': {'labelOffsetSupport': True}}}, 'completion': {'dynamicRegistration': False, 'contextSupport': False, 'completionItemKind': {'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]}, 'completionItem': {'documentationFormat': ['markdown', 'plaintext'], 'deprecatedSupport': True, 'preselectSupport': True, 'commitCharactersSupport': True, 'snippetSupport': True, 'resolveSupport': {'properties': ['documentation', 'detail', 'additionalTextEdits']}, 'labelDetailsSupport': True, 'tagSupport': {'valueSet': [1]}, 'insertReplaceSupport': True}}, 'codeAction': {'resolveSupport': {'properties': ['edit']}, 'codeActionLiteralSupport': {'codeActionKind': {'valueSet': ['', 'quickfix', 'refactor', 'refactor.extract', 'refactor.inline', 'refactor.rewrite', 'source', 'source.organizeImports']}}, 'dynamicRegistration': False, 'dataSupport': True, 'isPreferredSupport': True}, 'declaration': {'linkSupport': True}, 'typeDefinition': {'linkSupport': True}, 'implementation': {'linkSupport': True}, 'definition': {'linkSupport': True}, 'callHierarchy': {'dynamicRegistration': False}, 'publishDiagnostics': {'tagSupport': {'valueSet': [1, 2]}, 'relatedInformation': True}, 'hover': {'dynamicRegistration': False, 'contentFormat': ['markdown', 'plaintext']}, 'synchronization': {'dynamicRegistration': False, 'willSave': True, 'didSave': True, 'willSaveWaitUntil': True}}, 'window': {'showDocument': {'support': True}, 'workDoneProgress': True, 'showMessage': {'messageActionItem': {'additionalPropertiesSupport': False}}}}, 'processId': 11947, 'initializationOptions': {}, 'workspaceFolders': [{'uri': 'file:///home/yp/MPAS-Model', 'name': '/home/yp/MPAS-Model'}]}, 'jsonrpc': '2.0'}\nTraceback (most recent call last):\n  File \"/home/yp/.local/share/nvim/mason/packages/fortls/venv/lib/python3.11/site-packages/fortls/langserver.py\", line 167, in handle\n    resp = handler(request)\n           ^^^^^^^^^^^^^^^^\n  File \"/home/yp/.local/share/nvim/mason/packages/fortls/venv/lib/python3.11/site-packages/fortls/langserver.py\", line 206, in serve_initialize\n    self.workspace_init()\n  File \"/home/yp/.local/share/nvim/mason/packages/fortls/venv/lib/python3.11/site-packages/fortls/langserver.py\", line 1449, in workspace_init\n    result_obj = result.get()\n                 ^^^^^^^^^^^^\n  File \"/usr/lib/python3.11/multiprocessing/pool.py\", line 774, in get\n    raise self._value\nmultiprocessing.pool.MaybeEncodingError: Error sending result: '<fortls.parse_fortran.FortranFile object at 0x7f04000f7110>'. Reason: 'RecursionError('maximum recursion depth exceeded while pickling an object')'\n"

As you said, modifying the default recursive limit is not a good choice, and I wholeheartedly agree with that. So, do you have any opinions on this matter?

@jokervTv
Copy link
Author

When I check the directories and exclude some it works fine.

Thanks for your reading.

@alexeedm
Copy link

Just hit this issue with another large fortran workspace. Maybe we should consider fixing it on the fortls side, like removing recursion? Legacy fortran-language-server was working fine with the same project...

@gnikit
Copy link
Member

gnikit commented Apr 12, 2024

@alexeedm can you please post some steps to reproduce? We don't control the recursion limit and neither did fortran-language-server, so something that is reproducible would help shed some light in this behaviour.

@alexeedm
Copy link

Steps are the same as for @jokervTv: just open a large project in the VScode and init_workspace would crash with the recursion limit message. I unfortunately cannot share the code itself, but I believe MPAS tarball should be enough to repro.

I also dug a bit deeper, and it seems that the error happens when file_init returns a large AST that has to be pickled/unpickled due to multiprocessing. Indeed there's not much that can be done about it, as the limitation is in python itself. The issues is known, but it has not been resolved in almost 20 years...

I guess I'd just suggest to increase the recursion limit for fortls module, possibly optionally with a command-line argument.

@gnikit gnikit reopened this Apr 13, 2024
@gnikit
Copy link
Member

gnikit commented Apr 13, 2024

I guess I'd just suggest to increase the recursion limit for fortls module, possibly optionally with a command-line argument.

Yeap, I think this is the only sensible option. I remember a couple years ago when I tried to do this, increasing the recursion depth had no effect, maybe my test case was not very good. I will have a look.

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

Successfully merging a pull request may close this issue.

3 participants