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

sublime text support? #44

Open
pancelor opened this issue Jun 25, 2023 · 4 comments
Open

sublime text support? #44

pancelor opened this issue Jun 25, 2023 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@pancelor
Copy link

Hi! I'm looking for a pico8 LSP for Sublime Text and I see this the README:

This extension uses the Language Server Protocol, so while it's mainly made for VSCode, it could also be used for other editors such as NeoVim, Atom, etc.

How difficult would it be to get this LSP running in Sublime, either on my own, or as an official feature of this repo? I don't know much about how LSPs work under the hood so I have no idea how big of a feature request this is. Any tips on how I would go about doing this?

@pancelor
Copy link
Author

Progress: I found #34 and ran these commands to install this language server:

git clone https://github.com/japhib/pico8-ls
cd pico8-ls
npm install
cd server
npm run compile
echo -e '#!/usr/bin/env bash\n'"node $PWD/out/server.js" '"$@"' > ~/bin/pico8-ls # or any other folder in your $PATH
chmod +x ~/bin/pico8-ls

I already have sublime's LSP installed, and it works for me with LSP-lua.

I edited my LSP settings: (via "Preferences: LSP Settings" in the sublime command palette)

{
    "clients":
    {
        "pico8-lua": {
            "enabled": true,
            "command": ["pico8-ls","--stdio"],
            "selector": "source.p8",
        },
    },
}

(the --stdio bit seemed necessary; without it, this lsp server crashed on startup. but maybe there's a better way to connect?)


This is where I'm stuck now; I can't figure out how to use the pico8 language server. The right-click context menu only lets me do LSP: Expand Selection, but when I try it, the status bar briefly says "No selectionRangeProvider found, reverting to built-in Expand Selection"

The LSP log panel shows this, so the server appears to be running, I just can't figure out how to use it:

:: [02:52:06.650] --> pico8-lua initialize (1): {'rootUri': 'file:///home/pancelor/w/pico8/mice-heist', 'rootPath': '/home/pancelor/w/pico8/mice-heist', 'capabilities': {'window': {'showMessage': {'messageActionItem': {'additionalPropertiesSupport': True}}, 'showDocument': {'support': True}, 'workDoneProgress': True}, 'textDocument': {'publishDiagnostics': {'dataSupport': True, 'codeDescriptionSupport': True, 'tagSupport': {'valueSet': [2, 1]}, 'relatedInformation': True, 'versionSupport': True}, 'inlayHint': {'resolveSupport': {'properties': ['textEdits', 'label.command']}, 'dynamicRegistration': True}, 'documentSymbol': {'symbolKind': {'valueSet': [7, 6, 25, 8, 9, 3, 12, 5, 23, 20, 4, 13, 21, 18, 17, 10, 1, 11, 19, 16, 2, 26, 22, 15, 14, 24]}, 'hierarchicalDocumentSymbolSupport': True, 'dynamicRegistration': True, 'tagSupport': {'valueSet': [1]}}, 'synchronization': {'didSave': True, 'willSaveWaitUntil': True, 'willSave': True, 'dynamicRegistration': True}, 'references': {'dynamicRegistration': True}, 'declaration': {'dynamicRegistration': True, 'linkSupport': True}, 'typeDefinition': {'dynamicRegistration': True, 'linkSupport': True}, 'codeLens': {'dynamicRegistration': True}, 'diagnostic': {'relatedDocumentSupport': True, 'dynamicRegistration': True}, 'rename': {'prepareSupportDefaultBehavior': 1, 'prepareSupport': True, 'dynamicRegistration': True}, 'hover': {'contentFormat': ['markdown', 'plaintext'], 'dynamicRegistration': True}, 'typeHierarchy': {'dynamicRegistration': True}, 'callHierarchy': {'dynamicRegistration': True}, 'colorProvider': {'dynamicRegistration': True}, 'documentHighlight': {'dynamicRegistration': True}, 'formatting': {'dynamicRegistration': True}, 'rangeFormatting': {'dynamicRegistration': True}, 'implementation': {'dynamicRegistration': True, 'linkSupport': True}, 'semanticTokens': {'requests': {'full': {'delta': True}, 'range': True}, 'tokenModifiers': ['async', 'modification', 'readonly', 'static', 'declaration', 'defaultLibrary', 'deprecated', 'documentation', 'abstract', 'definition'], 'augmentsSyntaxTokens': True, 'dynamicRegistration': True, 'overlappingTokenSupport': False, 'tokenTypes': ['property', 'method', 'parameter', 'operator', 'function', 'modifier', 'macro', 'namespace', 'typeParameter', 'struct', 'keyword', 'regexp', 'variable', 'class', 'decorator', 'type', 'interface', 'enum', 'number', 'comment', 'enumMember', 'string', 'event'], 'formats': ['relative'], 'multilineTokenSupport': True}, 'codeAction': {'isPreferredSupport': True, 'resolveSupport': {'properties': ['edit']}, 'codeActionLiteralSupport': {'codeActionKind': {'valueSet': ['quickfix', 'refactor', 'refactor.extract', 'refactor.inline', 'refactor.rewrite', 'source.fixAll', 'source.organizeImports']}}, 'dynamicRegistration': True, 'dataSupport': True}, 'definition': {'dynamicRegistration': True, 'linkSupport': True}, 'completion': {'completionItem': {'documentationFormat': ['markdown', 'plaintext'], 'labelDetailsSupport': True, 'insertTextModeSupport': {'valueSet': [2]}, 'resolveSupport': {'properties': ['detail', 'documentation', 'additionalTextEdits']}, 'insertReplaceSupport': True, 'deprecatedSupport': True, 'tagSupport': {'valueSet': [1]}, 'snippetSupport': True}, 'insertTextMode': 2, 'completionItemKind': {'valueSet': [10, 19, 2, 24, 5, 15, 4, 3, 12, 22, 14, 8, 7, 11, 17, 1, 16, 13, 6, 9, 25, 20, 18, 21, 23]}, 'dynamicRegistration': True, 'completionList': {'itemDefaults': ['editRange', 'insertTextFormat', 'data']}}, 'documentLink': {'tooltipSupport': True, 'dynamicRegistration': True}, 'signatureHelp': {'signatureInformation': {'documentationFormat': ['markdown', 'plaintext'], 'parameterInformation': {'labelOffsetSupport': True}, 'activeParameterSupport': True}, 'contextSupport': True, 'dynamicRegistration': True}, 'selectionRange': {'dynamicRegistration': True}}, 'general': {'markdown': {'parser': 'Python-Markdown', 'version': '3.2.2'}, 'regularExpressions': {'engine': 'ECMAScript'}}, 'workspace': {'applyEdit': True, 'didChangeConfiguration': {'dynamicRegistration': True}, 'configuration': True, 'executeCommand': {}, 'semanticTokens': {'refreshSupport': True}, 'inlayHint': {'refreshSupport': True}, 'workspaceEdit': {'failureHandling': 'abort', 'documentChanges': True}, 'diagnostics': {'refreshSupport': True}, 'symbol': {'symbolKind': {'valueSet': [7, 6, 25, 8, 9, 3, 12, 5, 23, 20, 4, 13, 21, 18, 17, 10, 1, 11, 19, 16, 2, 26, 22, 15, 14, 24]}, 'tagSupport': {'valueSet': [1]}, 'dynamicRegistration': True}, 'codeLens': {'refreshSupport': True}, 'workspaceFolders': True}}, 'processId': 20218, 'clientInfo': {'version': '1.24.0', 'name': 'Sublime Text LSP'}, 'initializationOptions': {}, 'workspaceFolders': [{'uri': 'file:///home/pancelor/w/pico8/mice-heist', 'name': 'mice-heist'}]}

In LSP-lua, I can right click on a variable and choose LSP > Rename. How can I get this working with this pico8 language server?

@japhib
Copy link
Owner

japhib commented Jun 26, 2023

--stdio seems good, although I think there are some extra console.log statements in the language server that may cause the stdio thing to fail. (i.e. just extra stuff like error logs that might get printed to stdio and mess things up.)

The right-click context menu only lets me do LSP: Expand Selection

You probably need to edit the Sublime Text portion of your config to match up with the features actually provided by the language server. Here's where the capabilities are defined on the server side: https://github.com/japhib/pico8-ls/blob/master/server/src/server.ts#L51-L67

In English, the features provided are:

  • Document symbols
  • Navigate to definition of symbol
  • View usages of symbol
  • Auto-completion
  • Hover (only for built-in functions)
  • Signature help
  • Formatter

Notably, Expand Selection is not provided ... I'm actually not sure what that feature would do. Maybe you could clarify?

Rename is also not supported by this language server. PRs are welcome though!

I never use Sublime Text myself and have zero experience setting up a plugin for it, so I'm sorry I can't be more help! However, if you're able to get this working, I'd be happy to add setup instructions to the repo. Or if you want to make a Sublime plugin repo, I could split out the current pico8-ls repo into separate server and VSCode client repos, so that you could have a Sublime plugin that includes the server, but none of the VSCode-specific stuff.

@japhib japhib added enhancement New feature or request help wanted Extra attention is needed labels Jun 26, 2023
@pancelor
Copy link
Author

Oh, "View usages of symbol" is supported but "Rename" isn't? How strange, I would expect one would imply the other automatically. (But again, I know very little about LSPs and I'm sure it's complicated)

Ah sorry, I don't particularly care about "Expand Selection". What I meant to communicate was that pico8-ls seemed to be initialized and running, but my editor didn't seem to be able to use any of its features. This video shows LSP-lua hover working, but pico8-ls hover not working:

pico8-ls.mp4

You probably need to edit the Sublime Text portion of your config to match up with the features actually provided by the language server

pico8-ls sends that info to Sublime-LSP, right? why would I need to tell sublime that info as well? It seems redundant. (probably I don't understand something fundamental about LSP configuration..?)


wait, I'm seeing some errors in the sublime console:

reloading settings Packages/User/LSP.sublime-settings
Error handling notification
Traceback (most recent call last):
  File "/home/pancelor/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/sessions.py", line 2215, in on_payload
    handler(result)
  File "/home/pancelor/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/sessions.py", line 2001, in m___progress
    if token.startswith(_PARTIAL_RESULT_PROGRESS_PREFIX):
AttributeError: 'int' object has no attribute 'startswith'

The error repeats itself 5 times. Maybe this has to do with the extra logging you were talking about? Or maybe not, maybe the "$/progress notification" pico8-ls sends is faulty somehow -- here's line 2001 and line 2215 is here (note, the line numbers don't actually match up with my local copy of LSP. I haven't changed anything, I must just be not up-to-date)

I tried editing my LSP settings to get rid of --stdio, based on sublime-LSP documentation:

        "pico8-lua": {
            "enabled": true,
            "command": ["pico8-ls","--socket=1289"],
            "tcp_port": 1289,
            "selector": "source.p8",
            "settings": {
                "Lua.hover.enable": true,
            },
        },

but the errors remain.

(the Lua.hover.enable is cargo-culted from LSP-lua, idk what I'm doing)

@valba8
Copy link

valba8 commented Feb 29, 2024

Hi, I was looking at this and the problem is in some prints that are made from the server to the standard output, that make the sublime LSP plugin fail. If those console.log are removed the server works with Sublime.

I have made a pull request (#55), if anyone is interested. The modification is to use pico8-ls with .lua files, not with the .p8 format.

pico8ls_st

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

No branches or pull requests

3 participants