zed icon indicating copy to clipboard operation
zed copied to clipboard

editor: auto-import style

Open avetisk opened this issue 1 year ago • 13 comments

Check for existing issues

  • [X] Completed

Describe the feature

There's an option in VS Code called "import module specifier" which allows to choose how the auto-imports are written.

image

This would be great in order to not waste time rewriting all auto-imports to match the desired import style.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

avetisk avatar Feb 09 '24 16:02 avetisk

Seconding this - this is the main blocker for me to switch fully to Zed

joaquim-verges avatar Feb 13 '24 20:02 joaquim-verges

Adding this in settings is working for me:

{
  ...
  "lsp": {
    "typescript-language-server": {
      "initialization_options": {
        "preferences": {
          "importModuleSpecifierPreference": "non-relative"
        }
      }
    }
  }
}

binary-koan avatar Mar 14 '24 17:03 binary-koan

This solution is no longer working with vtsls typescript LSP

Adding this in settings is working for me:

{
  ...
  "lsp": {
    "typescript-language-server": {
      "initialization_options": {
        "preferences": {
          "importModuleSpecifierPreference": "non-relative"
        }
      }
    }
  }
}

antoyne7 avatar Jul 01 '24 15:07 antoyne7

FWIW, this works for me after running into the same issue as @antoyne7:

{
  ...
  "language_servers": ["...", "!vtsls", "typescript-language-server"],
  "lsp": {
    "typescript-language-server": {
      "initialization_options": {
        "preferences": {
          "importModuleSpecifierPreference": "non-relative"
        }
      }
    }
  }
}

pcalves avatar Jul 02 '24 09:07 pcalves

I tried all kinds of different ways to configure the vtsls language server but I can't seem to get it working :sob:

  "lsp": {
    "vtsls": {
      "initialization_options": {
        "typescript": {
          "preferences": {
            "importModuleSpecifier": "non-relative",
            "importModuleSpecifierEnding": "js"
          }
        }
      }
    }
  }

Or like so

  "lsp": {
    "vtsls": {
      "initialization_options": {
        "preferences": {
          "typescript.preferences.importModuleSpecifier": "non-relative",
          "typescript.preferences.importModuleSpecifierEnding": "js"
        }
      }
    }
  }

I have looked at the docs of this vtsls language server but I can't seem to get it working. The answer of @pcalves by switching to the typescript-language-server is working but I would like to keep using the standard language server for typescript that Zed offers instead of working around it, if possible

patrickswijgman avatar Jul 12 '24 16:07 patrickswijgman

After trying a good amount of permutations, this ended up doing the work for me with vtsls:

  "lsp": {
    "vtsls": {
      "initialization_options": {
        "typescript": {
          "preferences": {
            "importModuleSpecifier": "relative"
          }
        }
      }
    }
  }

kristiyanraykov avatar Jul 31 '24 08:07 kristiyanraykov

^ this did it. P.S. Don't forget to change it to "non-relative".

kantuni avatar Sep 05 '24 06:09 kantuni

In zed version 0.154.2 it's not work

tp6gw94 avatar Sep 26 '24 06:09 tp6gw94

@tp6gw94 Replace initialization_options with settings.

giannisp avatar Sep 26 '24 06:09 giannisp

@tp6gw94 Replace initialization_options with settings.

@giannisp It's work! Thank you.

    "vtsls": {
      "settings": {
        "typescript": {
          "preferences": {
            "importModuleSpecifier": "non-relative"
          }
        }
      }
    },

tp6gw94 avatar Sep 27 '24 05:09 tp6gw94

Hi all! Is there a documentation for all this magic words?

thatc0py avatar Feb 13 '25 10:02 thatc0py

@procopym You can look into the configuration options of the language server for further tinkering

ps173 avatar Feb 20 '25 08:02 ps173

Does anyone has an idea how to enable the relative option for .vue files? With this config:

{
  "lsp": {
    "vtsls": {
      "settings": { 
        "typescript": {
          "preferences": {
            "importModuleSpecifier": "relative"
          }
        },
      }
    }
  }
}

It works for .ts files but in .vue it behaves like when the value is "non-relative"

thomasaull avatar May 13 '25 08:05 thomasaull