跳转到内容

JavaScript and TypeScript

此内容尚不支持你的语言。

Open a folder with a package.json and Ferris IDEA offers a run configuration per script, runs Vitest and Jest into the result tree, formats with the project’s Prettier, fixes with its ESLint, and debugs Node.js with js-debug. JavaScript and TypeScript support is Works; Extract Interface, Extract Superclass and Pull Members Up are Experimental.

  • Node.js. Ferris IDEA finds node on the PATH and the versions of nvm (NVM_DIR) and fnm (FNM_DIR), and reads .nvmrc, .node-version and engines.node to choose and check one.

  • A language server. The first one found is used:

    Server Install
    typescript-language-server npm install -g typescript-language-server typescript@5
    vtsls npm install -g @vtsls/language-server
    tsc --lsp (TypeScript 7) npm install -g typescript@7
    Terminal window
    npm install -g typescript-language-server typescript@5

    The install command Ferris IDEA names in language_servers, version 1.6.0.

    The TypeScript installed beside the server is used when the project has none of its own, so a project does not need node_modules/typescript for code insight. In a project you have not trusted, the project’s own TypeScript is never loaded.

  • Framework servers, when you use them:

    Framework Server Install
    Vue vue-language-server npm install -g @vue/language-server@2 typescript
    Svelte svelteserver npm install -g svelte-language-server
    Angular templates ngserver, only when angular.json exists npm install -g @angular/language-server
  • js-debug for debugging: unpack the js-debug-dap release of the vscode-js-debug project so that ~/.local/opt/js-debug-<version>/js-debug/src/dapDebugServer.js exists (the newest such folder is used), or name that file in FERRIS_IDEA_JS_DEBUG.

  • Prettier and ESLint as dev dependencies of the project. Ferris IDEA uses them only from the project’s node_modules/.bin, never global ones.

Ferris IDEA takes the package manager from the packageManager field, else from the lockfile (package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lock, bun.lockb), else npm. View › Tool Windows › npm lists the scripts of every package.json; the ▶ next to a script in package.json runs it with that package manager.

  1. Open the project. The run list shows npm run name for every script under “Detected from build files”, plus vitest or jest when the project depends on them.
  2. Run › Run Current File (⌃⇧R) on a .js, .mjs, .cjs, .ts, .mts or .cts file runs node <file>. TypeScript files run through Node’s own type stripping, which needs Node 22.18 or later; .tsx and .d.ts files are not run, and TypeScript that needs a transform (enums, namespaces) fails in Node.
  1. In a test file the gutter shows ▶ on every describe, suite, it and test call. Run one and only that test runs, filtered by its full name.
  2. The vitest and jest configurations run the whole suite with a JSON report that fills the result tree. See Run tests.

Mocha and Node’s own test runner are not read into the tree.

  1. Set a breakpoint (⌘F8) in a .js or .ts file.
  2. Run › Debug Current File (⌃⇧D), or debug a script configuration: npm, pnpm, Yarn and Bun scripts, npm start and npm test run under js-debug, which follows the child processes they start. A Jest ▶ offers Debug too; Jest is then run with --runInBand.
  3. Step and evaluate as in Debug a program. To debug a Node process started with --inspect, use Attach to Process.
  • Reformat Code (⌥⌘L) uses the project’s Prettier for the whole file in a trusted project, otherwise the language server. Without Prettier, the server keeps one-line blocks as they are.
  • Code › Reformat with Prettier (⌥⇧⌘P) also covers CSS, SCSS, Less, JSON, Markdown, YAML, HTML and GraphQL.
  • Code › Fix ESLint Problems applies ESLint’s fixes. ESLint runs only when the project has a configuration (eslint.config.*, .eslintrc* or eslintConfig in package.json).
  • Code › Optimize Imports (⌃⌥O) uses the server’s own “remove unused” and “sort imports”, never ESLint or Prettier.

Rename, Introduce Field and the server’s extract actions come from the language server. Ferris IDEA adds Extract Interface, Extract Superclass and Pull Members Up for TypeScript classes, worked out from the syntax tree, and its own Extract Variable where the server offers none (TypeScript 7).

  • “Cannot debug JavaScript: node or js-debug is missing …”: unpack the js-debug release into ~/.local/opt or set FERRIS_IDEA_JS_DEBUG.
  • Reformat ignores your Prettier settings: Prettier is not in the project’s node_modules, or the project is not trusted; run the package manager’s install and trust the project.
  • A TypeScript file does not run: the Node version is older than 22.18, or the file needs a transform. Use a script with your loader instead.
  • Vue files have no insight: install the server with the command above (@vue/language-server@2).
Keyboard of
ActionShortcut
Code › Optimize Imports⌃⌥OCtrlAltO
Code › Reformat Code⌥⌘LCtrlAltL
Code › Reformat with Prettier⌥⇧⌘PCtrlAltShiftP
Run › Debug Current File⌃⇧Dno shortcut
Run › Run Current File⌃⇧RCtrlShiftF10

  • debug_startchangesdry run by defaultdebugtrusted-projectStart a debug session: native programs with lldb-dap, Go with Delve (go_test for tests), Python with debugpy, Node.js/TypeScript scripts or an npm_script with js-debug, or a Kotlin main_class.
  • eslint_filechangesdry run by defaultwritetrusted-projectCheck a JavaScript/TypeScript file with the project's own ESLint (node_modules/.bin/eslint with an eslint.config.*/.eslintrc*/eslintConfig in or above its package, inside the workspace; nothing is downloaded): findings with 1-based line, severity, rule, message and whether --fix can fix them.
  • extract_interfacechangesdry run by defaultwriteExtract Interface for the class at (or around) a position of a TypeScript file: creates the interface before the type with the signatures of members and adds it to implements (or extends of an interface).
  • extract_superclasschangesdry run by defaultwriteExtract Superclass for the class at (or around) a position of a JavaScript or TypeScript file: creates class name before it with the chosen members, moves them there and makes the class extend it.
  • node_environmentreadsNode.js setup of the workspace without starting node: runtimes from nvm, fnm and PATH with versions; which one is selected and why (incl.
  • package_scriptsreadsThe scripts of a package.json (what the ▶ markers next to them offer, SPEC-0168): name, 1-based line, command and the run configuration that runs it with the package's manager (packageManager, else the lockfile's, else npm) in the package's folder.
  • prettier_filechangesdry run by defaultwritetrusted-projectFormat a file with the project's own Prettier (node_modules/.bin/prettier in or above its package, inside the workspace, with the project's configuration; nothing is downloaded).
  • pull_members_upchangesdry run by defaultwritePull Members Up for the class at (or around) a position of a JavaScript or TypeScript file: moves members to the end of the direct supertype named target (may be left out when there is only one), or adds their signature when it is an interface or abstract is true (an abstract class).