diff --git a/jekyll/version-managers.markdown b/jekyll/version-managers.markdown index ecaefc6c2..a2ab43c19 100644 --- a/jekyll/version-managers.markdown +++ b/jekyll/version-managers.markdown @@ -31,6 +31,32 @@ Ensure Mise is up-to-date: https://mise.jdx.dev/faq.html#mise-is-failing-or-not- Ensure RVM is up-to-date: https://rvm.io/rvm/upgrading +## Nix Flakes + +To use the Ruby LSP with Nix flakes, set the version manager to `nix-develop`. + +```jsonc +{ + "rubyLsp.rubyVersionManager": { + "identifier": "nix-develop" + } +} +``` + +By default, this will use `nix develop --command ruby` to activate the environment. If you need to specify a path to a +flake, you can do so with the `rubyLsp.customRubyCommand` setting. + +```jsonc +{ + "rubyLsp.rubyVersionManager": { + "identifier": "nix-develop" + }, + "rubyLsp.customRubyCommand": "/path/to/dir/containing/flake" +} +``` + +This will result in the activation command `nix develop /path/to/dir/containing/flake --command ruby`. + ## Custom activation If you're using a different version manager that's not supported by this extension or if you're manually inserting the Ruby diff --git a/vscode/package.json b/vscode/package.json index 9a35ce1fe..395f9c388 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -390,6 +390,7 @@ "rvm", "shadowenv", "mise", + "nix-develop", "custom" ], "default": "auto" diff --git a/vscode/src/ruby.ts b/vscode/src/ruby.ts index abf45d180..1c854308f 100644 --- a/vscode/src/ruby.ts +++ b/vscode/src/ruby.ts @@ -11,6 +11,7 @@ import { VersionManager } from "./ruby/versionManager"; import { Mise } from "./ruby/mise"; import { RubyInstaller } from "./ruby/rubyInstaller"; import { Rbenv } from "./ruby/rbenv"; +import { NixDevelop } from "./ruby/nixDevelop"; import { Rvm } from "./ruby/rvm"; import { None } from "./ruby/none"; import { Custom } from "./ruby/custom"; @@ -44,6 +45,7 @@ export enum ManagerIdentifier { Shadowenv = "shadowenv", Mise = "mise", RubyInstaller = "rubyInstaller", + NixDevelop = "nix-develop", None = "none", Custom = "custom", } @@ -318,6 +320,11 @@ export class Ruby implements RubyInterface { new RubyInstaller(this.workspaceFolder, this.outputChannel, this.context, this.manuallySelectRuby.bind(this)), ); break; + case ManagerIdentifier.NixDevelop: + await this.runActivation( + new NixDevelop(this.workspaceFolder, this.outputChannel, this.context, this.manuallySelectRuby.bind(this)), + ); + break; case ManagerIdentifier.Custom: await this.runActivation( new Custom(this.workspaceFolder, this.outputChannel, this.context, this.manuallySelectRuby.bind(this)), diff --git a/vscode/src/ruby/nixDevelop.ts b/vscode/src/ruby/nixDevelop.ts new file mode 100644 index 000000000..386a51d8a --- /dev/null +++ b/vscode/src/ruby/nixDevelop.ts @@ -0,0 +1,26 @@ +import * as vscode from "vscode"; + +import { VersionManager, ActivationResult } from "./versionManager"; + +export class NixDevelop extends VersionManager { + async activate(): Promise { + const customCommand = this.customCommand(); + const command = `nix develop ${customCommand} --command ruby`; + const parsedResult = await this.runEnvActivationScript(command); + + return { + env: { ...process.env, ...parsedResult.env }, + yjit: parsedResult.yjit, + version: parsedResult.version, + gemPath: parsedResult.gemPath, + }; + } + + private customCommand() { + const configuration = vscode.workspace.getConfiguration("rubyLsp"); + const customCommand: string | undefined = + configuration.get("customRubyCommand"); + + return customCommand || ""; + } +}