PMunch / nimlsp

Language Server Protocol implementation for Nim
MIT License
419 stars 51 forks source link

nimlsp crashes with latest nim devel #153

Closed AmjadHD closed 1 year ago

AmjadHD commented 1 year ago

nim-lang/Nim@7031ea6 causes nimlsp to crash with recursion limit hit.

:: --> nimlsp initialize(1): {'clientInfo': {'version': '1.21.0', 'name': 'Sublime Text LSP'}, 'rootPath': 'D:\\User\\Space-Shooter', 'capabilities': {'textDocument': {'codeAction': {'isPreferredSupport': True, 'dynamicRegistration': True, 'dataSupport': True, 'codeActionLiteralSupport': {'codeActionKind': {'valueSet': ['quickfix', 'refactor', 'refactor.extract', 'refactor.inline', 'refactor.rewrite', 'source.fixAll', 'source.organizeImports']}}, 'resolveSupport': {'properties': ['edit']}}, 'definition': {'dynamicRegistration': True, 'linkSupport': True}, 'documentSymbol': {'dynamicRegistration': True, 'symbolKind': {'valueSet': [10, 12, 24, 17, 13, 3, 16, 22, 1, 20, 9, 21, 14, 8, 6, 4, 5, 2, 7, 11, 15, 26, 23, 25, 19, 18]}, 'tagSupport': {'valueSet': [1]}, 'hierarchicalDocumentSymbolSupport': True}, 'codeLens': {'dynamicRegistration': True}, 'colorProvider': {'dynamicRegistration': True}, 'rename': {'dynamicRegistration': True, 'prepareSupport': True, 'prepareSupportDefaultBehavior': 1}, 'documentHighlight': {'dynamicRegistration': True}, 'publishDiagnostics': {'relatedInformation': True, 'versionSupport': True, 'dataSupport': True, 'tagSupport': {'valueSet': [1, 2]}, 'codeDescriptionSupport': True}, 'formatting': {'dynamicRegistration': True}, 'synchronization': {'willSaveWaitUntil': True, 'dynamicRegistration': True, 'willSave': True, 'didSave': True}, 'implementation': {'dynamicRegistration': True, 'linkSupport': True}, 'rangeFormatting': {'dynamicRegistration': True}, 'typeDefinition': {'dynamicRegistration': True, 'linkSupport': True}, 'references': {'dynamicRegistration': True}, 'hover': {'dynamicRegistration': True, 'contentFormat': ['markdown', 'plaintext']}, 'semanticTokens': {'augmentsSyntaxTokens': True, 'dynamicRegistration': True, 'tokenTypes': ['decorator', 'enum', 'function', 'event', 'keyword', 'namespace', 'number', 'enumMember', 'typeParameter', 'variable', 'modifier', 'struct', 'parameter', 'regexp', 'method', 'class', 'macro', 'interface', 'string', 'comment', 'property', 'operator', 'type'], 'requests': {'full': {'delta': True}, 'range': True}, 'tokenModifiers': ['definition', 'deprecated', 'readonly', 'static', 'documentation', 'async', 'abstract', 'defaultLibrary', 'modification', 'declaration'], 'overlappingTokenSupport': False, 'formats': ['relative'], 'multilineTokenSupport': True}, 'signatureHelp': {'dynamicRegistration': True, 'signatureInformation': {'activeParameterSupport': True, 'parameterInformation': {'labelOffsetSupport': True}, 'documentationFormat': ['markdown', 'plaintext']}, 'contextSupport': True}, 'documentLink': {'dynamicRegistration': True, 'tooltipSupport': True}, 'declaration': {'dynamicRegistration': True, 'linkSupport': True}, 'completion': {'completionItemKind': {'valueSet': [15, 13, 1, 3, 23, 6, 2, 20, 17, 19, 14, 16, 4, 11, 21, 5, 8, 7, 9, 18, 10, 12, 25, 22, 24]}, 'dynamicRegistration': True, 'insertTextMode': 2, 'completionItem': {'deprecatedSupport': True, 'documentationFormat': ['markdown', 'plaintext'], 'insertTextModeSupport': {'valueSet': [2]}, 'labelDetailsSupport': True, 'tagSupport': {'valueSet': [1]}, 'insertReplaceSupport': True, 'snippetSupport': True, 'resolveSupport': {'properties': ['detail', 'documentation', 'additionalTextEdits']}}}, 'selectionRange': {'dynamicRegistration': True}, 'inlayHint': {'dynamicRegistration': True, 'resolveSupport': {'properties': ['textEdits', 'label.command']}}}, 'workspace': {'applyEdit': True, 'executeCommand': {}, 'didChangeWatchedFiles': {'dynamicRegistration': True}, 'symbol': {'dynamicRegistration': True, 'symbolKind': {'valueSet': [10, 12, 24, 17, 13, 3, 16, 22, 1, 20, 9, 21, 14, 8, 6, 4, 5, 2, 7, 11, 15, 26, 23, 25, 19, 18]}, 'tagSupport': {'valueSet': [1]}}, 'configuration': True, 'codeLens': {'refreshSupport': True}, 'didChangeConfiguration': {'dynamicRegistration': True}, 'workspaceEdit': {'documentChanges': True, 'failureHandling': 'abort'}, 'workspaceFolders': True, 'inlayHint': {'refreshSupport': True}, 'semanticTokens': {'refreshSupport': True}}, 'window': {'workDoneProgress': True, 'showMessage': {'messageActionItem': {'additionalPropertiesSupport': True}}, 'showDocument': {'support': True}}, 'general': {'regularExpressions': {'engine': 'ECMAScript'}, 'markdown': {'parser': 'Python-Markdown', 'version': '3.2.2'}}}, 'initializationOptions': {}, 'rootUri': 'file:///D:/User/Space-Shooter', 'processId': 2904, 'workspaceFolders': [{'uri': 'file:///D:/User/Space-Shooter', 'name': 'Space-Shooter'}]}
:: <<< nimlsp 1: {'capabilities': {'completionProvider': {'triggerCharacters': ['.'], 'resolveProvider': False}, 'textDocumentSync': {'change': {'syncKind': 1}, 'save': {'includeText': True}, 'didOpen': {}, 'didClose': {}}, 'definitionProvider': True, 'referencesProvider': True, 'hoverProvider': True, 'signatureHelpProvider': {'triggerCharacters': ['(', ',']}, 'documentSymbolProvider': True, 'renameProvider': True}}
::  -> nimlsp initialized: {}
::  -> nimlsp textDocument/didOpen: {'textDocument': {'uri': 'file:///D:/User/Space-Shooter/main.nim', 'languageId': 'nim', 'version': 0, 'text': 'import std/random\nimport std/strutils\nimport pkg/sdl2\n\n\nconst\n  WIDTH = 512\n  HEIGHT = 640\n\ntype\n  Game = object\n    highScore: int\n    isPlaying: bool\n    waitTime: uint32\n    wait: bool\n    blinkTime: uint32\n    blink: bool\n    currentTrack: int\n    randPos: int\n    player: Player\n\n    allSprites: seq[Sprite]\n\nrandomize()\n\nproc initGame(): Game = \n  let scoreStr = open("highscore.txt").readLine()\n  let now = getTicks()\n\n  result = Game(\n    highScore: if scoreStr.len != 0: parseInt(scoreStr) else: 0,\n    isPlaying: true,\n    waitTime: now,\n    wait: true,\n    blinkTime: now,\n    blink: true,\n    currentTrack: 0,\n    randPos: rand(40, HEIGHT div 3),\n    player: Player()\n  )\n\nproc play(game: var Game) =\n  game.waitTime = getTicks()\n  game.wait = true\n\n  while game.isPlaying:\n    discard\n'}}
:: --> nimlsp textDocument/hover(2): {'textDocument': {'uri': 'file:///D:/User/Space-Shooter/main.nim'}, 'position': {'line': 26, 'character': 7}}
:: --> nimlsp textDocument/hover(3): {'textDocument': {'uri': 'file:///D:/User/Space-Shooter/main.nim'}, 'position': {'line': 26, 'character': 10}}
nimlsp: Traceback (most recent call last)
nimlsp: D:\User\nimlsp\src\nimlsp.nim(666) nimlsp
nimlsp: D:\User\nimlsp\src\nimlsp.nim(330) main
nimlsp: D:\User\nimlsp\src\nimlsppkg\suggestlib.nim(80) def
nimlsp: C:\Users\User\.choosenim\toolchains\nim-#devel\nimsuggest\nimsuggest.nim(1162) runCmd
nimlsp: C:\Users\User\.choosenim\toolchains\nim-#devel\nimsuggest\nimsuggest.nim(237) executeNoHooks
...
nimlsp: C:\Users\User\.choosenim\toolchains\nim-#devel\nimsuggest\nimsuggest.nim(237) executeNoHooks
nimlsp: C:\Users\User\.choosenim\toolchains\nim-#devel\nimsuggest\nimsuggest.nim executeNoHooks
nimlsp: Error: call depth limit reached in a debug build (2000 function calls). You can change it with -d:nimCallDepthLimit=<int> but really try to avoid deep recursions instead.

https://github.com/nim-lang/Nim/commit/7031ea65cd220360b8e9f566fd28f01bc0bf53c4#diff-a7c8d25cefdf0d3b4d7713ada23b1ec76416139cdaaa9999c0e8ef8fda94cb2aR236-R237. nimsuggest works fine.

AmjadHD commented 1 year ago

@PMunch.

PMunch commented 1 year ago

Yeah I'm currently debugging a couple issues like this. Seems to be partially caused by the langserver implementation fiddling with the nimsuggest API without ensuring that using it as a library still works..

marcusramberg commented 1 year ago

I'm seeing this on latest stable (1.6.12) as well.


Error: call depth limit reached in a debug build (2000 function calls). You can change it with -d:nimCallDepthLimit=<int> but really try to avoid deep recursions instead.\n"```
AmjadHD commented 1 year ago

This was fixed in https://github.com/nim-lang/Nim/pull/21555. Closing.