Skip to content

Imports in components use relative paths rather than $lib #2866

@codevogel

Description

@codevogel

Describe the bug

Whenever I try to import a component into another component, the language server seems to suggest a relative path, rather than a $lib path.

Reproduction

  1. Install lspconfig
  2. Install svelte-language-server using Mason
  3. Create a new svelte app using npx sv create app
  4. cd app; nvim .
  5. touch src/lib/components/component-a.svelte and touch src/lib/components/component-b.svelte
  6. Type <ComponentA/> into +page.svelte
  7. Code actions (and autocompletions) will suggest an import from $lib:
Image
  1. Type <ComponentA/> into component-a.svelte`
  2. Code actions (and autocompletions) will suggest an import from ./component-a.svelte:
Image

The same is true for typescript files.

e.g.

  1. echo 'export const test = 'test';' > src/lib/testFile.ts
  2. In component-a.svelte, attempting to import test will suggest a relative path.
Image

Expected behaviour

Both imports should be imported through $lib. Alternatively, suggest a relative import path, but make $lib the default.

System Info

  • OS: [e.g. Windows]
❯ inxi -Sxxx
System:
  Host: codevogel-GLU Kernel: 6.8.0-79-generic arch: x86_64 bits: 64
    compiler: gcc v: 13.3.0 clocksource: tsc
  Desktop: awesome v: 4.3 vt: 7 dm: LightDM v: 1.30.0
    Distro: Linux Mint 22.1 Xia base: Ubuntu 24.04 noble

Which package is the issue about?

svelte-language-server

Additional Information, eg. Screenshots

My LSPconfig

I have tried extending the svelte server capabilities with non-relative as a preference, like so:

svelte = {
   capabilities = {
      workspace = {
         didChangeWatchedFiles = false,
      },
   },
   settings = {
      lint = {
         unknownAtRules = 'ignore',
      },
      typescript = {
         preferences = {
            importModuleSpecifierPreference = 'non-relative',
         },
      },
   },
   preferences = {
      importModuleSpecifierPreference = 'non-relative',
   },
},

:LspInfo:

==============================================================================
vim.lsp:                                     require("vim.lsp.health").check()

- LSP log level : WARN
- Log path: /home/codevogel/.local/state/nvim/lsp.log
- Log size: 49080 KB

vim.lsp: Active Clients ~
- GitHub Copilot (id: 1)
  - Version: 1.378.0
  - Root directory: nil
  - Command: { "node", "/home/codevogel/.local/share/nvim/lazy/copilot.vim/copilot-language-server/dist/language-server.js", "--stdio" }
  - Settings: {
      ["github-enterprise"] = {
        uri = vim.NIL
      },
      http = {
        proxy = vim.NIL,
        proxyStrictSSL = vim.NIL
      }
    }
  - Attached buffers: 30, 28, 110, 23, 159, 19, 138, 174, 173
- eslint (id: 2)
  - Version: ? (no serverInfo.version response)
  - Root directory: ~/work/test/app
  - Command: { "vscode-eslint-language-server", "--stdio" }
  - Settings: {
      codeAction = {
        disableRuleComment = {
          enable = true,
          location = "separateLine"
        },
        showDocumentation = {
          enable = true
        }
      },
      codeActionOnSave = {
        enable = false,
        mode = "all"
      },
      experimental = {
        useFlatConfig = true
      },
      format = true,
      nodePath = "",
      onIgnoredFiles = "off",
      problems = {
        shortenToSingleLine = false
      },
      quiet = false,
      rulesCustomizations = {},
      run = "onType",
      useESLintClass = false,
      validate = "on",
      workingDirectory = {
        mode = "auto"
      },
      workspaceFolder = {
        name = "app",
        uri = "/home/codevogel/work/test/app"
      }
    }
  - Attached buffers: 174, 159, 19, 138, 110, 173
- svelte (id: 3)
  - Version: ? (no serverInfo.version response)
  - Root directory: ~/work/test/app
  - Command: { "svelteserver", "--stdio" }
  - Settings: {}
  - Attached buffers: 138, 159, 19
- lua_ls (id: 4)
  - Version: 3.15.0
  - Root directory: ~/.dotfiles/neovim/.config/nvim
  - Command: { "lua-language-server" }
  - Settings: {}
  - Attached buffers: 23, 28
- stylua (id: 5)
  - Version: 2.3.0
  - Root directory: ~/.dotfiles/neovim/.config/nvim
  - Command: { "stylua", "--lsp" }
  - Settings: {}
  - Attached buffers: 23, 28
- ts_ls (id: 6)
  - Version: ? (no serverInfo.version response)
  - Root directory: ~/work/test/app
  - Command: { "typescript-language-server", "--stdio" }
  - Settings: {}
  - Attached buffers: 110, 174, 173

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions