Skip to content

generated code to offer nix-develop as version manager #3691

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions jekyll/version-managers.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@
"rvm",
"shadowenv",
"mise",
"nix-develop",
"custom"
],
"default": "auto"
Expand Down
7 changes: 7 additions & 0 deletions vscode/src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -44,6 +45,7 @@ export enum ManagerIdentifier {
Shadowenv = "shadowenv",
Mise = "mise",
RubyInstaller = "rubyInstaller",
NixDevelop = "nix-develop",
None = "none",
Custom = "custom",
}
Expand Down Expand Up @@ -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)),
Expand Down
26 changes: 26 additions & 0 deletions vscode/src/ruby/nixDevelop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as vscode from "vscode";

import { VersionManager, ActivationResult } from "./versionManager";

export class NixDevelop extends VersionManager {
async activate(): Promise<ActivationResult> {
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 || "";
}
}
Loading