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

DocumentSelector is of wrong type #1056

Closed
qua3k opened this issue Mar 28, 2023 · 5 comments · Fixed by #1068
Closed

DocumentSelector is of wrong type #1056

qua3k opened this issue Mar 28, 2023 · 5 comments · Fixed by #1068
Milestone

Comments

@qua3k
Copy link

qua3k commented Mar 28, 2023

Hi all, I’m using ocamllsp version 1.15.1-5.0 on macOS with Sublime Text, and I’m getting errors on the client/registerCapability response to initialize. I think it’s because documentSelector should be a DocumentFilter list instead of a DocumentFilter list list, but the ocamllsp code appears to be correct. I’m not entirely sure where in the code is wrong, and would appreciate some help.

See example response here:

:: [09:54:29.821] --> OCaml initialize (1): {'rootUri': 'file:///Users/duck/olox', 'initializationOptions': {}, 'workspaceFolders': [{'uri': 'file:///Users/duck/olox', 'name': 'olox'}], 'processId': 40578, 'capabilities': {'textDocument': {'formatting': {'dynamicRegistration': True}, 'signatureHelp': {'contextSupport': True, 'dynamicRegistration': True, 'signatureInformation': {'documentationFormat': ['markdown', 'plaintext'], 'parameterInformation': {'labelOffsetSupport': True}, 'activeParameterSupport': True}}, 'typeHierarchy': {'dynamicRegistration': True}, 'rename': {'prepareSupport': True, 'dynamicRegistration': True, 'prepareSupportDefaultBehavior': 1}, 'documentLink': {'dynamicRegistration': True, 'tooltipSupport': True}, 'references': {'dynamicRegistration': True}, 'hover': {'dynamicRegistration': True, 'contentFormat': ['markdown', 'plaintext']}, 'typeDefinition': {'linkSupport': True, 'dynamicRegistration': True}, 'publishDiagnostics': {'versionSupport': True, 'codeDescriptionSupport': True, 'relatedInformation': True, 'dataSupport': True, 'tagSupport': {'valueSet': [2, 1]}}, 'callHierarchy': {'dynamicRegistration': True}, 'semanticTokens': {'multilineTokenSupport': True, 'dynamicRegistration': True, 'tokenModifiers': ['declaration', 'static', 'deprecated', 'abstract', 'readonly', 'modification', 'definition', 'defaultLibrary', 'documentation', 'async'], 'augmentsSyntaxTokens': True, 'overlappingTokenSupport': False, 'formats': ['relative'], 'requests': {'full': {'delta': True}, 'range': True}, 'tokenTypes': ['enum', 'method', 'event', 'string', 'keyword', 'type', 'typeParameter', 'macro', 'operator', 'interface', 'property', 'comment', 'number', 'modifier', 'decorator', 'variable', 'struct', 'class', 'regexp', 'enumMember', 'namespace', 'parameter', 'function']}, 'declaration': {'linkSupport': True, 'dynamicRegistration': True}, 'synchronization': {'didSave': True, 'dynamicRegistration': True, 'willSave': True, 'willSaveWaitUntil': True}, 'colorProvider': {'dynamicRegistration': True}, 'completion': {'completionItemKind': {'valueSet': [13, 1, 16, 4, 23, 7, 15, 18, 14, 25, 24, 8, 10, 6, 2, 19, 5, 12, 20, 9, 17, 21, 22, 11, 3]}, 'completionList': {'itemDefaults': ['editRange', 'insertTextFormat', 'data']}, 'dynamicRegistration': True, 'insertTextMode': 2, 'completionItem': {'resolveSupport': {'properties': ['detail', 'documentation', 'additionalTextEdits']}, 'documentationFormat': ['markdown', 'plaintext'], 'insertReplaceSupport': True, 'insertTextModeSupport': {'valueSet': [2]}, 'snippetSupport': True, 'deprecatedSupport': True, 'labelDetailsSupport': True, 'tagSupport': {'valueSet': [1]}}}, 'codeAction': {'isPreferredSupport': True, 'resolveSupport': {'properties': ['edit']}, 'dynamicRegistration': True, 'codeActionLiteralSupport': {'codeActionKind': {'valueSet': ['quickfix', 'refactor', 'refactor.extract', 'refactor.inline', 'refactor.rewrite', 'source.fixAll', 'source.organizeImports']}}, 'dataSupport': True}, 'rangeFormatting': {'dynamicRegistration': True}, 'inlayHint': {'resolveSupport': {'properties': ['textEdits', 'label.command']}, 'dynamicRegistration': True}, 'definition': {'linkSupport': True, 'dynamicRegistration': True}, 'documentHighlight': {'dynamicRegistration': True}, 'documentSymbol': {'hierarchicalDocumentSymbolSupport': True, 'symbolKind': {'valueSet': [10, 6, 18, 9, 24, 19, 4, 21, 26, 25, 17, 11, 20, 15, 13, 23, 5, 7, 22, 2, 8, 16, 1, 3, 14, 12]}, 'dynamicRegistration': True, 'tagSupport': {'valueSet': [1]}}, 'selectionRange': {'dynamicRegistration': True}, 'implementation': {'linkSupport': True, 'dynamicRegistration': True}, 'codeLens': {'dynamicRegistration': True}}, 'general': {'markdown': {'parser': 'Python-Markdown', 'version': '3.2.2'}, 'regularExpressions': {'engine': 'ECMAScript'}}, 'window': {'workDoneProgress': True, 'showDocument': {'support': True}, 'showMessage': {'messageActionItem': {'additionalPropertiesSupport': True}}}, 'workspace': {'executeCommand': {}, 'applyEdit': True, 'configuration': True, 'didChangeConfiguration': {'dynamicRegistration': True}, 'codeLens': {'refreshSupport': True}, 'workspaceEdit': {'failureHandling': 'abort', 'documentChanges': True}, 'workspaceFolders': True, 'semanticTokens': {'refreshSupport': True}, 'inlayHint': {'refreshSupport': True}, 'symbol': {'symbolKind': {'valueSet': [10, 6, 18, 9, 24, 19, 4, 21, 26, 25, 17, 11, 20, 15, 13, 23, 5, 7, 22, 2, 8, 16, 1, 3, 14, 12]}, 'dynamicRegistration': True, 'tagSupport': {'valueSet': [1]}}}}, 'clientInfo': {'name': 'Sublime Text LSP', 'version': '1.23.0'}, 'rootPath': '/Users/duck/olox'}
OCaml: failed to poll dune registry. Unix.Unix_error(Unix.ENOENT, "stat", "/Users/duck/.local/share/dune/rpc")
:: [09:54:29.839] <-  OCaml window/logMessage: {'type': 2, 'message': 'failed to poll dune registry. Unix.Unix_error(Unix.ENOENT, "stat", "/Users/duck/.local/share/dune/rpc")'}
:: [09:54:29.839] <<< OCaml (1) (duration: 18ms): {'serverInfo': {'name': 'ocamllsp', 'version': '1.15.1-5.0'}, 'capabilities': {'declarationProvider': True, 'workspaceSymbolProvider': True, 'selectionRangeProvider': True, 'codeActionProvider': {'codeActionKinds': ['quickfix', 'refactor.inline', 'construct', 'destruct', 'inferred_intf', 'put module name in identifiers', 'remove module name from identifiers', 'type-annotate']}, 'textDocumentSync': {'didOpen': {}, 'save': {'includeText': False}, 'didClose': {}, 'change': {'syncKind': 2}}, 'hoverProvider': True, 'executeCommandProvider': {'commands': ['ocamllsp/view-metrics', 'ocamllsp/open-related-source', 'ocamllsp/show-document-text', 'ocamllsp/show-merlin-config', 'dune/promote']}, 'experimental': {'ocamllsp': {'interfaceSpecificLangId': True, 'handleTypedHoles': True, 'handleSwitchImplIntf': True, 'handleHoverExtended': True, 'handleInferIntf': True, 'diagnostic_promotions': True, 'handleWrappingAstNode': True}}, 'completionProvider': {'resolveProvider': True, 'triggerCharacters': ['.', '#']}, 'signatureHelpProvider': {'triggerCharacters': [' ', '~', '?', ':', '(']}, 'referencesProvider': True, 'typeDefinitionProvider': True, 'documentSymbolProvider': True, 'renameProvider': {'prepareProvider': True}, 'foldingRangeProvider': True, 'definitionProvider': True, 'semanticTokensProvider': {'full': {'delta': True}, 'legend': {'tokenTypes': ['namespace', 'type', 'class', 'enum', 'interface', 'struct', 'typeParameter', 'parameter', 'variable', 'property', 'enumMember', 'event', 'function', 'method', 'macro', 'keyword', 'modifier', 'comment', 'string', 'number', 'regexp', 'operator', 'decorator'], 'tokenModifiers': ['declaration', 'definition', 'readonly', 'static', 'deprecated', 'abstract', 'async', 'modification', 'documentation', 'defaultLibrary']}}, 'codeLensProvider': {'resolveProvider': False}, 'documentFormattingProvider': True, 'workspace': {'workspaceFolders': {'changeNotifications': True, 'supported': True}}, 'documentHighlightProvider': True}}
:: [09:54:29.840] <-- OCaml client/registerCapability (1): {'registrations': [{'registerOptions': {'documentSelector': [['DocumentFilter', {'pattern': None, 'language': 'cram', 'scheme': None}], ['DocumentFilter', {'pattern': None, 'language': 'dune', 'scheme': None}], ['DocumentFilter', {'pattern': None, 'language': 'dune-project', 'scheme': None}], ['DocumentFilter', {'pattern': None, 'language': 'dune-workspace', 'scheme': None}]]}, 'method': 'textDocument/didOpen', 'id': 'ocamllsp-cram-dune-files/textDocument/didOpen'}, {'registerOptions': {'documentSelector': [['DocumentFilter', {'pattern': None, 'language': 'cram', 'scheme': None}], ['DocumentFilter', {'pattern': None, 'language': 'dune', 'scheme': None}], ['DocumentFilter', {'pattern': None, 'language': 'dune-project', 'scheme': None}], ['DocumentFilter', {'pattern': None, 'language': 'dune-workspace', 'scheme': None}]]}, 'method': 'textDocument/didClose', 'id': 'ocamllsp-cram-dune-files/textDocument/didClose'}]}
:: [09:54:29.840] ~~> OCaml (1) (duration: 0ms): {'code': -32603, 'message': 'type object argument after ** must be a mapping, not list'}
Error handling request
Traceback (most recent call last):
  File "/Users/duck/Library/Application Support/Sublime Text/Installed Packages/LSP.sublime-package/plugin/core/sessions.py", line 2081, in on_payload
    handler(result, req_id)
  File "/Users/duck/Library/Application Support/Sublime Text/Installed Packages/LSP.sublime-package/plugin/core/sessions.py", line 1777, in m_client_registerCapability
    data = _RegistrationData(registration_id, capability_path, registration_path, options)
  File "/Users/duck/Library/Application Support/Sublime Text/Installed Packages/LSP.sublime-package/plugin/core/sessions.py", line 1135, in __init__
    self.selector = DocumentSelector(document_selector)
  File "/Users/duck/Library/Application Support/Sublime Text/Installed Packages/LSP.sublime-package/plugin/core/types.py", line 405, in __init__
    self.filters = [DocumentFilter(**document_filter) for document_filter in document_selector]
  File "/Users/duck/Library/Application Support/Sublime Text/Installed Packages/LSP.sublime-package/plugin/core/types.py", line 405, in <listcomp>
    self.filters = [DocumentFilter(**document_filter) for document_filter in document_selector]
TypeError: type object argument after ** must be a mapping, not list

Exception AttributeError: 'session_buffers' in <bound method _RegistrationData.__del__ of <LSP.plugin.core.sessions._RegistrationData object at 0x1045692b0>> ignored
@rchl
Copy link

rchl commented Mar 28, 2023

Yeah, looks like wrong structure (extra nested arrays):

{
  "registrations": [
    {
      "registerOptions": {
        "documentSelector": [
          [
            "DocumentFilter",
            {
              "pattern": null,
              "language": "cram",
              "scheme": null
            }
          ],
          [
            "DocumentFilter",
            {
              "pattern": null,
              "language": "dune",
              "scheme": null
            }
          ],
          [
            "DocumentFilter",
            {
              "pattern": null,
              "language": "dune-project",
              "scheme": null
            }
          ],
          [
            "DocumentFilter",
            {
              "pattern": null,
              "language": "dune-workspace",
              "scheme": null
            }
          ]
        ]
      },
      "method": "textDocument/didOpen",
      "id": "ocamllsp-cram-dune-files/textDocument/didOpen"
    },
    {
      "registerOptions": {
        "documentSelector": [
          [
            "DocumentFilter",
            {
              "pattern": null,
              "language": "cram",
              "scheme": null
            }
          ],
          [
            "DocumentFilter",
            {
              "pattern": null,
              "language": "dune",
              "scheme": null
            }
          ],
          [
            "DocumentFilter",
            {
              "pattern": null,
              "language": "dune-project",
              "scheme": null
            }
          ],
          [
            "DocumentFilter",
            {
              "pattern": null,
              "language": "dune-workspace",
              "scheme": null
            }
          ]
        ]
      },
      "method": "textDocument/didClose",
      "id": "ocamllsp-cram-dune-files/textDocument/didClose"
    }
  ]
}

@qua3k
Copy link
Author

qua3k commented Mar 28, 2023

You can see this weird DocumentSelector written into the OCaml VSCode extension as well, so that may need to be fixed.

@rchl
Copy link

rchl commented Mar 28, 2023

Yeah, looks like a entirely custom handling that matches on the extension and server side.
Should be reported in their repo.

@qua3k
Copy link
Author

qua3k commented Mar 28, 2023

I seem to have figured out what’s going on—the metamodel.json is outdated/wrong, and this issue was fixed in microsoft/vscode-languageserver-node@6568838. I think what is best is that there be some sort of CI to automatically pull the latest from upstream. I will see about making a PR updating the model.

@qua3k
Copy link
Author

qua3k commented Apr 24, 2023

Hi, I would like to say that this is still an issue. My attempts to generate the metamodel didn’t work, even when I attempted to use the first commit where the metamodel was checked into the repo. There’s nothing I can do.

@rgrinberg rgrinberg linked a pull request Apr 25, 2023 that will close this issue
@rgrinberg rgrinberg added this to the 1.16.0 milestone Apr 25, 2023
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

Successfully merging a pull request may close this issue.

3 participants