11import * as vscode from "vscode" ;
22
33import { VersionManager , ActivationResult } from "./versionManager" ;
4+ import { pathToUri } from "../common" ;
5+ import { WorkspaceChannel } from "../workspaceChannel" ;
46
57// Manage your Ruby environment with rv
68//
79// Learn more: https://github.com/spinel-coop/rv
810export class Rv extends VersionManager {
11+ private static getPossiblePaths ( ) : vscode . Uri [ ] {
12+ return [
13+ pathToUri ( "/" , "home" , "linuxbrew" , ".linuxbrew" , "bin" , "rv" ) ,
14+ pathToUri ( "/" , "usr" , "local" , "bin" , "rv" ) ,
15+ pathToUri ( "/" , "opt" , "homebrew" , "bin" , "rv" ) ,
16+ pathToUri ( "/" , "usr" , "bin" , "rv" ) ,
17+ ] ;
18+ }
19+
20+ static async detect (
21+ _workspaceFolder : vscode . WorkspaceFolder ,
22+ _outputChannel : WorkspaceChannel ,
23+ ) : Promise < vscode . Uri | undefined > {
24+ return VersionManager . findFirst ( Rv . getPossiblePaths ( ) ) ;
25+ }
26+
927 async activate ( ) : Promise < ActivationResult > {
10- const rvExec = await this . findRv ( ) ;
11- const parsedResult = await this . runEnvActivationScript ( `${ rvExec } ruby run --` ) ;
28+ const rvExec = await this . findVersionManagerUri (
29+ "Rv" ,
30+ "rubyVersionManager.rvExecutablePath" ,
31+ Rv . getPossiblePaths ( ) ,
32+ ( ) => Rv . detect ( this . workspaceFolder , this . outputChannel ) ,
33+ ) ;
34+ const parsedResult = await this . runEnvActivationScript ( `${ rvExec . fsPath } ruby run --` ) ;
1235
1336 return {
1437 env : { ...process . env , ...parsedResult . env } ,
@@ -17,30 +40,4 @@ export class Rv extends VersionManager {
1740 gemPath : parsedResult . gemPath ,
1841 } ;
1942 }
20-
21- private async findRv ( ) : Promise < string > {
22- const config = vscode . workspace . getConfiguration ( "rubyLsp" ) ;
23- const configuredRvPath = config . get < string | undefined > ( "rubyVersionManager.rvExecutablePath" ) ;
24-
25- if ( configuredRvPath ) {
26- return this . ensureRvExistsAt ( configuredRvPath ) ;
27- } else {
28- const possiblePaths = [
29- vscode . Uri . joinPath ( vscode . Uri . file ( "/" ) , "home" , "linuxbrew" , ".linuxbrew" , "bin" ) ,
30- vscode . Uri . joinPath ( vscode . Uri . file ( "/" ) , "usr" , "local" , "bin" ) ,
31- vscode . Uri . joinPath ( vscode . Uri . file ( "/" ) , "opt" , "homebrew" , "bin" ) ,
32- vscode . Uri . joinPath ( vscode . Uri . file ( "/" ) , "usr" , "bin" ) ,
33- ] ;
34- return this . findExec ( possiblePaths , "rv" ) ;
35- }
36- }
37-
38- private async ensureRvExistsAt ( path : string ) : Promise < string > {
39- try {
40- await vscode . workspace . fs . stat ( vscode . Uri . file ( path ) ) ;
41- return path ;
42- } catch ( _error : any ) {
43- throw new Error ( `The Ruby LSP version manager is configured to be rv, but ${ path } does not exist` ) ;
44- }
45- }
4643}
0 commit comments