File tree 4 files changed +26
-9
lines changed
lib/ruby_lsp/ruby_lsp_rails
4 files changed +26
-9
lines changed Original file line number Diff line number Diff line change 5
5
# installed from the root of your application.
6
6
7
7
ENGINE_ROOT = File . expand_path ( ".." , __dir__ )
8
- ENGINE_PATH = File . expand_path ( "../lib/ruby_lsp_rails/engine" , __dir__ )
9
8
APP_PATH = File . expand_path ( "../test/dummy/config/application" , __dir__ )
10
9
11
10
# Set up gems listed in the Gemfile.
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ class NeedsRestartError < StandardError; end
22
22
sig { void }
23
23
def initialize
24
24
project_root = Pathname . new ( ENV [ "BUNDLE_GEMFILE" ] ) . dirname
25
+
26
+ if project_root . basename . to_s == ".ruby-lsp"
27
+ project_root = project_root . join ( "../" )
28
+ end
29
+
25
30
dummy_path = File . join ( project_root , "test" , "dummy" )
26
31
@root = T . let ( Dir . exist? ( dummy_path ) ? dummy_path : project_root . to_s , String )
27
32
app_uri_path = "#{ @root } /tmp/app_uri.txt"
Original file line number Diff line number Diff line change 1
- # typed: true
2
- # frozen_string_literal: true
3
-
4
1
# This file is auto-generated from the current state of the database. Instead
5
2
# of editing this file, please use the migrations feature of Active Record to
6
3
# incrementally modify your database, and then regenerate this schema definition.
15
12
16
13
ActiveRecord ::Schema [ 7.0 ] . define ( version : 2023_03_30_202955 ) do
17
14
create_table "users" , force : :cascade do |t |
18
- t . string ( "first_name" )
19
- t . string ( "last_name" )
20
- t . integer ( "age" )
21
- t . datetime ( "created_at" , null : false )
22
- t . datetime ( "updated_at" , null : false )
15
+ t . string "first_name"
16
+ t . string "last_name"
17
+ t . integer "age"
18
+ t . datetime "created_at" , null : false
19
+ t . datetime "updated_at" , null : false
23
20
end
21
+
24
22
end
Original file line number Diff line number Diff line change @@ -38,6 +38,21 @@ class RailsClientTest < ActiveSupport::TestCase
38
38
ensure
39
39
File . write ( T . must ( app_uri_path ) , "http://localhost:3000" )
40
40
end
41
+
42
+ test "instantiation finds the right directory when bundle gemfile points to .ruby-lsp" do
43
+ previous_bundle_gemfile = ENV [ "BUNDLE_GEMFILE" ]
44
+ project_root = Pathname . new ( previous_bundle_gemfile ) . dirname
45
+
46
+ # If the RailsClient singleton was initialized in a different test successfully, then there would be no chance
47
+ # for this assertion to pass. We need to reset the singleton instance in order to force `initialize` to be
48
+ # executed again
49
+ Singleton . send ( :__init__ , RailsClient )
50
+
51
+ ENV [ "BUNDLE_GEMFILE" ] = "#{ project_root } /.ruby-lsp/Gemfile"
52
+ assert_equal ( "#{ project_root } /test/dummy" , RailsClient . instance . root )
53
+ ensure
54
+ ENV [ "BUNDLE_GEMFILE" ] = previous_bundle_gemfile
55
+ end
41
56
end
42
57
end
43
58
end
You can’t perform that action at this time.
0 commit comments