neovim 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.md +6 -0
  6. data/Rakefile +14 -3
  7. data/lib/neovim.rb +10 -1
  8. data/lib/neovim/buffer.rb +2 -0
  9. data/lib/neovim/client.rb +2 -0
  10. data/lib/neovim/executable.rb +33 -0
  11. data/lib/neovim/ruby_provider.rb +32 -58
  12. data/lib/neovim/ruby_provider/vim.rb +15 -1
  13. data/lib/neovim/tabpage.rb +3 -0
  14. data/lib/neovim/version.rb +1 -1
  15. data/lib/neovim/window.rb +3 -0
  16. data/script/acceptance_tests +46 -0
  17. data/script/generate_docs +8 -1
  18. data/spec/acceptance/rplugin_spec.vim +19 -0
  19. data/spec/acceptance/ruby_spec.vim +94 -0
  20. data/spec/acceptance/rubydo_spec.vim +66 -0
  21. data/spec/acceptance/rubyfile/call_foo.rb +1 -0
  22. data/spec/acceptance/rubyfile/curbuf.rb +1 -0
  23. data/spec/acceptance/rubyfile/curbuf_ivar_get.rb +1 -0
  24. data/spec/acceptance/rubyfile/curbuf_ivar_set.rb +1 -0
  25. data/spec/acceptance/rubyfile/curwin.rb +1 -0
  26. data/spec/acceptance/rubyfile/define_foo.rb +3 -0
  27. data/spec/acceptance/rubyfile/raise_standard_error.rb +1 -0
  28. data/spec/acceptance/rubyfile/raise_syntax_error.rb +1 -0
  29. data/spec/acceptance/rubyfile/set_pwd_after.rb +1 -0
  30. data/spec/acceptance/rubyfile/set_pwd_before.rb +1 -0
  31. data/spec/acceptance/rubyfile/vim_constants.rb +2 -0
  32. data/spec/acceptance/rubyfile_spec.vim +111 -0
  33. data/spec/acceptance/runtime/init.vim +1 -0
  34. data/spec/acceptance/runtime/rplugin/ruby/plugin.rb +13 -0
  35. data/spec/documentation_spec.rb +24 -0
  36. data/spec/helper.rb +20 -45
  37. data/spec/neovim/executable_spec.rb +32 -0
  38. data/spec/neovim/host_spec.rb +2 -2
  39. data/spec/neovim/ruby_provider/vim_spec.rb +38 -0
  40. data/spec/neovim_spec.rb +6 -0
  41. data/spec/support.rb +45 -0
  42. metadata +46 -7
  43. data/spec/acceptance/neovim-ruby-host_spec.rb +0 -69
  44. data/spec/acceptance/ruby_provider_spec.rb +0 -256
@@ -0,0 +1,66 @@
1
+ Given:
2
+ a
3
+ b
4
+ c
5
+ d
6
+
7
+ Execute (Update one line using `$_`):
8
+ 2rubydo $_.upcase!
9
+
10
+ Expect:
11
+ a
12
+ B
13
+ c
14
+ d
15
+
16
+ Execute (Update a range of lines using `$_`):
17
+ 2,3rubydo $_.upcase!
18
+
19
+ Expect:
20
+ a
21
+ B
22
+ C
23
+ d
24
+
25
+ Execute (Update all lines using `$_`):
26
+ %rubydo $_.upcase!
27
+
28
+ Execute (Raise a Ruby standard error):
29
+ try
30
+ 1rubydo raise "BOOM"
31
+ catch /BOOM/
32
+ endtry
33
+
34
+ 1rubydo $_.replace("still works")
35
+
36
+ Expect:
37
+ still works
38
+ b
39
+ c
40
+ d
41
+
42
+ Execute (Raise a Ruby syntax error):
43
+ try
44
+ 1rubydo puts[
45
+ catch /SyntaxError/
46
+ endtry
47
+
48
+ 1rubydo $_.replace("still works")
49
+
50
+ Expect:
51
+ still works
52
+ b
53
+ c
54
+ d
55
+
56
+ Given:
57
+ x
58
+
59
+ Execute (Add a large number of lines):
60
+ 1yank
61
+ silent normal 6000p
62
+ %rubydo $_.succ!
63
+
64
+ AssertEqual "y", getline(1)
65
+ AssertEqual "y", getline(6001)
66
+ AssertEqual "", getline(6002)
@@ -0,0 +1 @@
1
+ $curbuf[1] = "first"
@@ -0,0 +1 @@
1
+ Vim.command("let g:foo = #{$curbuf.instance_variable_get(:@foo)}")
@@ -0,0 +1 @@
1
+ $curbuf.instance_variable_set(:@foo, 123)
@@ -0,0 +1 @@
1
+ $curwin.buffer[1] = "first"
@@ -0,0 +1,3 @@
1
+ def foo
2
+ Vim.command("let g:called = 1")
3
+ end
@@ -0,0 +1 @@
1
+ Vim.command("let g:pwd_after = '#{Dir.pwd}'")
@@ -0,0 +1 @@
1
+ Vim.command("let g:pwd_before = '#{Dir.pwd}'")
@@ -0,0 +1,2 @@
1
+ Vim.command('1normal! Sfirst')
2
+ VIM.command('2normal! Ssecond')
@@ -0,0 +1,111 @@
1
+ Execute (Set nvim_version):
2
+ if has('nvim')
3
+ let g:nvim_version = api_info()['version']
4
+ else
5
+ let g:nvim_version = {'major': 99, 'minor': 99, 'patch': 99}
6
+ endif
7
+
8
+ Given:
9
+ one
10
+ two
11
+
12
+ Execute (Access `Vim` and `VIM` constants):
13
+ rubyfile ./spec/acceptance/rubyfile/vim_constants.rb
14
+
15
+ Expect:
16
+ first
17
+ second
18
+
19
+ Execute (Access `$curbuf` global variable):
20
+ rubyfile ./spec/acceptance/rubyfile/curbuf.rb
21
+
22
+ Expect:
23
+ first
24
+ two
25
+
26
+ Execute (Access `$curwin` global variable):
27
+ rubyfile ./spec/acceptance/rubyfile/curwin.rb
28
+
29
+ Expect:
30
+ first
31
+ two
32
+
33
+ Execute (Define a Ruby method):
34
+ rubyfile ./spec/acceptance/rubyfile/define_foo.rb
35
+
36
+ Execute (Call a Ruby method):
37
+ rubyfile ./spec/acceptance/rubyfile/call_foo.rb
38
+
39
+ Then:
40
+ AssertEqual 1, g:called
41
+
42
+ Execute (Update instance state on $curbuf):
43
+ rubyfile ./spec/acceptance/rubyfile/curbuf_ivar_set.rb
44
+
45
+ Execute (Access instance state on $curbuf):
46
+ rubyfile ./spec/acceptance/rubyfile/curbuf_ivar_get.rb
47
+
48
+ Then:
49
+ AssertEqual 123, g:foo
50
+
51
+ Execute (Change the working directory explicitly):
52
+ let g:rubyfile = getcwd() . "/spec/acceptance/rubyfile/set_pwd_before.rb"
53
+ cd /
54
+ exec "rubyfile " . g:rubyfile
55
+ cd -
56
+
57
+ Then:
58
+ if g:nvim_version['major'] > 0 || g:nvim_version['minor'] >= 2
59
+ AssertEqual "/", g:pwd_before
60
+ endif
61
+
62
+ Execute (Change the working directory implicitly):
63
+ let g:before_file = getcwd() . "/spec/acceptance/rubyfile/set_pwd_before.rb"
64
+ let g:after_file = getcwd() . "/spec/acceptance/rubyfile/set_pwd_after.rb"
65
+
66
+ split | lcd /
67
+ exec "rubyfile " . g:before_file
68
+ wincmd p
69
+ exec "rubyfile " . g:after_file
70
+ wincmd p | lcd -
71
+
72
+ Then:
73
+ if g:nvim_version['major'] > 0 || g:nvim_version['minor'] >= 2
74
+ AssertNotEqual g:pwd_before, g:pwd_after
75
+ endif
76
+
77
+ Execute (Raise a Ruby load error):
78
+ try
79
+ rubyfile /foo/bar/baz
80
+ catch /LoadError/
81
+ endtry
82
+
83
+ ruby $curbuf[1] = "still works"
84
+
85
+ Expect:
86
+ still works
87
+ two
88
+
89
+ Execute (Raise a Ruby standard error):
90
+ try
91
+ rubyfile ./spec/acceptance/rubyfile/raise_standard_error.rb
92
+ catch /BOOM/
93
+ endtry
94
+
95
+ ruby $curbuf[1] = "still works"
96
+
97
+ Expect:
98
+ still works
99
+ two
100
+
101
+ Execute (Raise a Ruby syntax error):
102
+ try
103
+ rubyfile ./spec/acceptance/rubyfile/raise_syntax_error.rb
104
+ catch /SyntaxError/
105
+ endtry
106
+
107
+ ruby $curbuf[1] = "still works"
108
+
109
+ Expect:
110
+ still works
111
+ two
@@ -0,0 +1 @@
1
+ set rtp=vendor/vader.vim,spec/acceptance/runtime,$VIMRUNTIME
@@ -0,0 +1,13 @@
1
+ Neovim.plugin do |plug|
2
+ plug.command(:PlugSetFoo, :nargs => 1) do |nvim, str|
3
+ nvim.command("let g:PlugFoo = '#{str}'")
4
+ end
5
+
6
+ plug.function(:PlugAdd, :args => 2, :sync => true) do |nvim, x, y|
7
+ x + y
8
+ end
9
+
10
+ plug.autocmd(:BufEnter, :pattern => "*.rb") do |nvim|
11
+ nvim.command("let g:PlugInRuby = 1")
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "open-uri"
4
+
5
+ RSpec.describe "neovim-ruby documentation" do
6
+ it "has up-to-date generated method docs" do
7
+ begin
8
+ url = "https://api.github.com/repos/neovim/neovim/releases/latest"
9
+ response = open(url) { |json| JSON.load(json) }
10
+
11
+ client_file = File.read(
12
+ File.expand_path("../../lib/neovim/client.rb", __FILE__)
13
+ )
14
+ docs_version = client_file[
15
+ /The methods documented here were generated using (.+)$/,
16
+ 1
17
+ ]
18
+
19
+ expect(docs_version).to eq(response["name"])
20
+ rescue SocketError => e
21
+ skip "Skipping: #{e}"
22
+ end
23
+ end
24
+ end
@@ -8,52 +8,11 @@ end
8
8
  require "fileutils"
9
9
  require "neovim"
10
10
  require "pry"
11
- require "shellwords"
11
+ require "rubygems"
12
12
  require "stringio"
13
13
  require "timeout"
14
14
 
15
- module Support
16
- def self.workspace
17
- File.expand_path("../workspace", __FILE__)
18
- end
19
-
20
- def self.socket_path
21
- file_path("nvim.sock")
22
- end
23
-
24
- def self.tcp_port
25
- server = TCPServer.new("127.0.0.1", 0)
26
-
27
- begin
28
- server.addr[1]
29
- ensure
30
- server.close
31
- end
32
- end
33
-
34
- def self.file_path(name)
35
- File.join(workspace, name)
36
- end
37
-
38
- def self.setup_workspace
39
- FileUtils.mkdir_p(workspace)
40
- end
41
-
42
- def self.teardown_workspace
43
- FileUtils.rm_rf(workspace)
44
- end
45
-
46
- def self.child_argv
47
- nvim_exe = ENV.fetch("NVIM_EXECUTABLE", "nvim")
48
- [nvim_exe, "--headless", "-i", "NONE", "-u", "NONE", "-n"]
49
- end
50
- end
51
-
52
- unless system("#{Support.child_argv.shelljoin} --version | grep -q NVIM")
53
- warn("Failed to load nvim. See installation instructions:")
54
- warn("https://github.com/neovim/neovim/wiki/Installing-Neovim")
55
- exit(1)
56
- end
15
+ require File.expand_path("../support.rb", __FILE__)
57
16
 
58
17
  RSpec.configure do |config|
59
18
  config.expect_with :rspec do |exp|
@@ -74,21 +33,37 @@ RSpec.configure do |config|
74
33
  end
75
34
  end
76
35
 
77
- config.around(:example, :silence_logging) do |spec|
36
+ config.around(:example, :silence_warnings) do |spec|
78
37
  old_logger = Neovim.logger
79
38
  log_target = StringIO.new
80
39
  Neovim.logger = Logger.new(log_target)
40
+ Neovim.logger.level = Logger::WARN
81
41
 
82
42
  begin
83
43
  spec.run
84
44
 
85
45
  expect(log_target.string).not_to be_empty,
86
- ":silence_logging used but nothing logged"
46
+ ":silence_warnings used but nothing logged at WARN level"
87
47
  ensure
88
48
  Neovim.logger = old_logger
89
49
  end
90
50
  end
91
51
 
52
+ config.before(:example, :nvim_version) do |spec|
53
+ req = Gem::Requirement.new(spec.metadata[:nvim_version])
54
+
55
+ begin
56
+ nvim_vrs = Support.nvim_version
57
+ vrs = Gem::Version.new(nvim_vrs)
58
+ rescue ArgumentError
59
+ vrs = Gem::Version.new(nvim_vrs.gsub("-", "."))
60
+ end
61
+
62
+ unless req.satisfied_by?(vrs.release)
63
+ pending "Pending: Installed nvim (#{vrs}) doesn't satisfy '#{req}'."
64
+ end
65
+ end
66
+
92
67
  Kernel.srand config.seed
93
68
  end
94
69
 
@@ -0,0 +1,32 @@
1
+ require "helper"
2
+
3
+ module Neovim
4
+ RSpec.describe Executable do
5
+ describe ".from_env" do
6
+ it "respects NVIM_EXECUTABLE" do
7
+ executable = Executable.from_env("NVIM_EXECUTABLE" => "/foo/nvim")
8
+ expect(executable.path).to eq("/foo/nvim")
9
+ end
10
+
11
+ it "returns a default path" do
12
+ executable = Executable.from_env({})
13
+ expect(executable.path).to eq("nvim")
14
+ end
15
+ end
16
+
17
+ describe "#version" do
18
+ it "returns the current nvim version" do
19
+ executable = Executable.from_env
20
+ expect(executable.version).to match(/^\d+\.\d+\.\d+/)
21
+ end
22
+
23
+ it "raises with an invalid executable path" do
24
+ executable = Executable.new("/dev/null")
25
+
26
+ expect {
27
+ executable.version
28
+ }.to raise_error(Executable::Error, /\/dev\/null/)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -34,7 +34,7 @@ module Neovim
34
34
  host.run
35
35
  end
36
36
 
37
- it "rescues session exceptions", :silence_logging do
37
+ it "rescues session exceptions", :silence_warnings do
38
38
  expect(session).to receive(:run).and_raise("BOOM")
39
39
  expect { host.run }.not_to raise_error
40
40
  end
@@ -136,7 +136,7 @@ module Neovim
136
136
  host.handle(message)
137
137
  end
138
138
 
139
- it "rescues plugin sync handler exceptions", :silence_logging do
139
+ it "rescues plugin sync handler exceptions", :silence_warnings do
140
140
  plugin = Plugin.from_config_block("source") do |plug|
141
141
  plug.command(:Foo, :sync => true) { raise "BOOM" }
142
142
  end
@@ -2,6 +2,27 @@ require "helper"
2
2
  require "neovim/ruby_provider/vim"
3
3
 
4
4
  RSpec.describe Vim do
5
+ around do |spec|
6
+ client = Vim.instance_variable_get(:@__client)
7
+ buffer_cache = Vim.instance_variable_get(:@__buffer_cache)
8
+ curbuf = $curbuf
9
+ curwin = $curwin
10
+
11
+ begin
12
+ Vim.__client = nil
13
+ Vim.instance_variable_set(:@__buffer_cache, {})
14
+ $curbuf = nil
15
+ $curwin = nil
16
+
17
+ spec.run
18
+ ensure
19
+ Vim.__client = client
20
+ Vim.instance_variable_set(:@__buffer_cache, buffer_cache)
21
+ $curbuf = curbuf
22
+ $curwin = curwin
23
+ end
24
+ end
25
+
5
26
  describe Vim::Buffer do
6
27
  it "refers to Neovim::Buffer" do
7
28
  expect(Vim::Buffer).to be(Neovim::Buffer)
@@ -23,10 +44,27 @@ RSpec.describe Vim do
23
44
  describe "#method_missing" do
24
45
  it "delegates method calls to @__client" do
25
46
  client = double(:client)
47
+ expect(Vim).to receive(:__refresh_globals).with(client)
26
48
  expect(client).to receive(:foo).with(1, 2)
27
49
 
28
50
  Vim.__client = client
29
51
  Vim.foo(1, 2)
30
52
  end
53
+
54
+ it "refreshes global variables" do
55
+ client = Neovim.attach_child(Support.child_argv)
56
+ client.command("vs foo")
57
+
58
+ Vim.__client = client
59
+ Vim.__refresh_globals(client)
60
+
61
+ expect {
62
+ Vim.command("wincmd n")
63
+ }.to change { $curwin.index }.by(1)
64
+
65
+ expect {
66
+ Vim.command("vs bar")
67
+ }.to change { $curbuf.index }.by(1)
68
+ end
31
69
  end
32
70
  end