Skip to content

Commit e3248fe

Browse files
committed
Account for virtualedit=all in FixUsings
Fixes #731
1 parent ab6348c commit e3248fe

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

autoload/OmniSharp/buffer.vim

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function! OmniSharp#buffer#Update(responseBody) abort
8888
let changes = get(a:responseBody, 'Changes', [])
8989
if type(changes) == type(v:null) | let changes = [] | endif
9090

91+
let virtualedit = &virtualedit ==? 'all'
9192
if len(changes)
9293
for change in changes
9394
let text = join(split(change.NewText, '\r\?\n', 1), "\n")
@@ -98,7 +99,7 @@ function! OmniSharp#buffer#Update(responseBody) abort
9899
let start = [change.StartLine, startCol]
99100
let end = [change.EndLine, endCol]
100101
call cursor(start)
101-
if startCol > len(getline('.'))
102+
if startCol > len(getline('.')) && !virtualedit
102103
" We can't set a mark after the last character of the line, so add an
103104
" extra charaqcter which will be immediately deleted again
104105
noautocmd normal! a<

test/fixusings.vader

+62-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,65 @@ Expect cs(should add required using):
4646
}
4747

4848

49+
Given cs():
50+
using System;
51+
52+
public class Test
53+
{
54+
public Test()
55+
{
56+
Console.WriteLine(Encoding.UTF8.ToString());
57+
}
58+
}
59+
60+
Execute (run fix usings):
61+
call OmniSharpTestInitializeBuffer('FixUsings3')
62+
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
63+
call OmniSharpTestAwait('OmniSharp#actions#usings#Fix', [])
64+
65+
Expect cs(should add another required using):
66+
using System;
67+
using System.Text;
68+
69+
public class Test
70+
{
71+
public Test()
72+
{
73+
Console.WriteLine(Encoding.UTF8.ToString());
74+
}
75+
}
76+
77+
78+
Given cs():
79+
using System;
80+
81+
public class Test
82+
{
83+
public Test()
84+
{
85+
Console.WriteLine(Encoding.UTF8.ToString());
86+
}
87+
}
88+
89+
Execute (run fix usings with virtualedit=all):
90+
call OmniSharpTestInitializeBuffer('FixUsings4')
91+
set virtualedit=all
92+
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
93+
call OmniSharpTestAwait('OmniSharp#actions#usings#Fix', [])
94+
95+
Expect cs(should add another required using):
96+
using System;
97+
using System.Text;
98+
99+
public class Test
100+
{
101+
public Test()
102+
{
103+
Console.WriteLine(Encoding.UTF8.ToString());
104+
}
105+
}
106+
107+
49108
Given cs():
50109
public class test {
51110
class1 ns1 = new class1();
@@ -62,7 +121,7 @@ Given cs():
62121
}
63122

64123
Execute (run fix usings):
65-
call OmniSharpTestInitializeBuffer('FixUsings3')
124+
call OmniSharpTestInitializeBuffer('FixUsings5')
66125
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
67126
call OmniSharpTestAwait('OmniSharp#actions#usings#Fix', [])
68127

@@ -82,7 +141,7 @@ Expect cs(should not add ambiguous using):
82141
}
83142

84143
Execute (should return ambiguous usings to Callback):
85-
call OmniSharpTestInitializeBuffer('FixUsings4')
144+
call OmniSharpTestInitializeBuffer('FixUsings6')
86145
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
87146
let g:OmniSharp_test_locations = []
88147
function! s:CallbackFixUsings(locations)
@@ -103,7 +162,7 @@ Execute (should return ambiguous usings to Callback):
103162
AssertEqual g:OmniSharp_test_locations[0].lnum, 2
104163

105164
Execute (should add ambiguous usings to quickfix):
106-
call OmniSharpTestInitializeBuffer('FixUsings5')
165+
call OmniSharpTestInitializeBuffer('FixUsings7')
107166
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
108167
" Cannot use OmniSharpTestAwait, as the callback prevents the default quickfix
109168
" behaviour

0 commit comments

Comments
 (0)