Skip to content

Update ts_ls.lua to include instructions for ember support #3851

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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

NullVoxPopuli
Copy link
Contributor

idk if we just want instructions here? because we can do a lot better with the on_new_config hook.

Here is what I do in my own configs:

    if (serverName == 'ts_ls') then
      local filetypes = {
        'typescript',
        'javascript',
        'typescript.glimmer',
        'javascript.glimmer',
        'typescript.tsx',
        'javascript.jsx',
        'html.handlebars',
        'handlebars',
      }
      server.setup({
        -- filetypes MUST include our custom filetypes for all variants of TS that we might want to use
        -- else the server won't boot and on_new_config won't get called, so we can't conditionally
        -- configure the init_options based on our project
        filetypes = filetypes,
        root_dir = utils.is_ts_project,
        capabilities = capabilities,
        -- This allows us to switch types of TSServers based on the open file.
        -- We don't always need the @glint/tsserver-plugin -- for example, in backend projects.
        on_new_config = function(new_config, new_root_dir)
          local info = utils.read_nearest_ts_config(new_root_dir)
          local glintPlugin = new_root_dir .. "node_modules/@glint/tsserver-plugin"

          if new_config.init_options then
            new_config.init_options.tsdk = get_typescript_server_path(new_root_dir)
            new_config.init_options.requestForwardingCommand = "forwardingTsRequest"


            if (info.isGlintPlugin) then
              new_config.init_options.plugins = {
                {
                  name = "@glint/tsserver-plugin",
                  location = glintPlugin,
                  languages = filetypes,
                  enableForWorkspaceTypeScriptVersions = true,
                  configNamespace = "typescript"
                }
              }
              print(glintPlugin)
            end
          end
        end,
        init_options = {
          tsserver = { logVerbosity = 'verbose', trace = "verbose" },
          preferences = {
            disableAutomaticTypingAcquisition = true,
            importModuleSpecifierPreference = "relative",
            importModuleSpecifierEnding = "minimal",
          },
          plugins = {}
        },
        settings = mySettings[serverName],
        on_attach = function(client, bufnr)
          keymap(bufnr)
          conditional_features(client, bufnr)
        end
      })

this allows automatic swapping of the tsplugins based on package.json, tsconfig.json, and/or node_modules contents

@justinmk
Copy link
Member

from the lint ci :

lint.sh: Configs in lua/lspconfig/configs/* are deprecated. Add or update configs in lsp/* instead.

@justinmk
Copy link
Member

stylua lint issue

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 this pull request may close these issues.

2 participants