teal-language / teal-language-server

A language server for Teal, a typed dialect of Lua
MIT License
81 stars 9 forks source link

Make tlconfig.lua optional? #19

Open pdesaulniers opened 2 months ago

pdesaulniers commented 2 months ago

I tried using the language server with tl.tl from https://github.com/teal-language/tl, but it seems like the server fails to initialize because that project does not contain a tlconfig.lua file. I suppose tlconfig.lua should be optional?

{
    "module": "lsp_events_manager",
    "fields": {
        "1": "....luarocks/share/lua/5.4/teal_language_server/asserts.lua:7: Assert hit!\nstack traceback:\n\t[C]: in function 'error'\n\t....luarocks/share/lua/5.4/teal_language_server/asserts.lua:7: in upvalue '_raise'\n\t....luarocks/share/lua/5.4/teal_language_server/asserts.lua:23: in function 'teal_language_server.asserts.that'\n\t...ocks/share/lua/5.4/teal_language_server/server_state.lua:203: in function 'teal_language_server.server_state._load_config'\n\t...ocks/share/lua/5.4/teal_language_server/server_state.lua:233: in function 'teal_language_server.server_state.initialize'\n\t...cks/share/lua/5.4/teal_language_server/misc_handlers.lua:70: in function 'teal_language_server.misc_handlers._on_initialize'\n\t...cks/share/lua/5.4/teal_language_server/misc_handlers.lua:317: in field '?'\n\t...hare/lua/5.4/teal_language_server/lsp_events_manager.lua:41: in function <...hare/lua/5.4/teal_language_server/lsp_events_manager.lua:41>\n\t[C]: in function 'xpcall'\n\t...hare/lua/5.4/teal_language_server/lsp_events_manager.lua:40: in function 'teal_language_server.lsp_events_manager._trigger'\n\t...hare/lua/5.4/teal_language_server/lsp_events_manager.lua:64: in function 'teal_language_server.lsp_events_manager._receive_initialize_request'\n\t...hare/lua/5.4/teal_language_server/lsp_events_manager.lua:71: in function <...hare/lua/5.4/teal_language_server/lsp_events_manager.lua:69>",
        "0": "initialize"
    },
    "timestamp": 1726787974,
    "time": 0.0071817530042608,
    "message": "Error in handler for request with method {0}: {1}",
    "level": "ERROR"
}
FourierTransformer commented 2 weeks ago

So, I went ahead and put in a PR to make tlconfig.lua optional, but opening up tl.tl still has other issues. It shows a syntax error within patch_visitors coming from tl.parse_program.

   local function patch_visitors(my_visit_node: Visitor<TypeChecker, NodeKind, Node, Type>,
                                 after_node: VisitorAfterPatcher<TypeChecker, Node, Type>,
                                 my_visit_type?: Visitor<TypeChecker, TypeName, Type, Type>,
                                 after_type?: VisitorAfterPatcher<TypeChecker, Type, Type>):
                                 Visitor<TypeChecker, NodeKind, Node, Type>,
                                 Visitor<TypeChecker, TypeName, Type, Type>

It can be fixed by modifying it to:

   local function patch_visitors(my_visit_node: Visitor<TypeChecker, NodeKind, Node, Type>,
                                 after_node: VisitorAfterPatcher<TypeChecker, Node, Type>,
                                 my_visit_type?: Visitor<TypeChecker, TypeName, Type, Type>,
                                 after_type?: VisitorAfterPatcher<TypeChecker, Type, Type>): Visitor<TypeChecker, NodeKind, Node, Type>, Visitor<TypeChecker, TypeName, Type, Type>

and then it will happily do the language server things!

FourierTransformer commented 2 weeks ago

I tried running tl.parse_program outside of the teal-language-server, and it didn't throw any syntax errors. I guess something to look into.