Skip to content

Commit 682325f

Browse files
authored
Merge pull request #778 from nickspoons/bugfix/add-import-with-empty-line
Use virtualedit to simplify inserting buffer edits
2 parents 4a73854 + a086fc8 commit 682325f

File tree

2 files changed

+73
-10
lines changed

2 files changed

+73
-10
lines changed

autoload/OmniSharp/buffer.vim

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ function! OmniSharp#buffer#Update(responseBody) abort
100100
let changes = get(a:responseBody, 'Changes', [])
101101
if type(changes) == type(v:null) | let changes = [] | endif
102102

103-
let virtualedit = &virtualedit ==? 'all'
103+
let virtualedit_bak = &virtualedit
104+
let &l:virtualedit = 'all'
104105
if len(changes)
105106
for change in changes
106107
let text = join(split(change.NewText, '\r\?\n', 1), "\n")
@@ -111,15 +112,6 @@ function! OmniSharp#buffer#Update(responseBody) abort
111112
let start = [change.StartLine, startCol]
112113
let end = [change.EndLine, endCol]
113114
call cursor(start)
114-
if startCol > len(getline('.')) && !virtualedit
115-
" We can't set a mark after the last character of the line, so add an
116-
" extra charaqcter which will be immediately deleted again
117-
noautocmd normal! a<
118-
if start == end
119-
let endCol += 1
120-
let end[0] = endCol
121-
endif
122-
endif
123115
call cursor(change.EndLine, max([1, endCol - 1]))
124116
let lineLen = len(getline('.'))
125117
if change.StartLine < change.EndLine && (endCol == 1 || lineLen == 0)
@@ -156,6 +148,7 @@ function! OmniSharp#buffer#Update(responseBody) abort
156148
let pos[1] = min([pos[1], line('$')])
157149
call setpos('.', pos)
158150
endif
151+
let &l:virtualedit = virtualedit_bak
159152
endfunction
160153

161154
function! OmniSharp#buffer#Valid(...) abort

test/fixusings.vader

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,76 @@ Expect cs(should add another required using):
105105
}
106106

107107

108+
Given cs():
109+
using System;
110+
111+
using System.Text;
112+
113+
public class Test
114+
{
115+
public Test()
116+
{
117+
Console.WriteLine(Encoding.UTF8.ToString());
118+
Console.WriteLine(DateTime.Parse("1999-01-01T00:01:01Z", CultureInfo.InvariantCulture));
119+
}
120+
}
121+
122+
Execute (run fix usings with empty line and virtualedit=):
123+
call OmniSharpTestInitializeBuffer('FixUsings4')
124+
set virtualedit=
125+
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
126+
call OmniSharpTestAwait('OmniSharp#actions#usings#Fix', [])
127+
128+
Expect cs(should add another required using between the others):
129+
using System;
130+
using System.Globalization;
131+
using System.Text;
132+
133+
public class Test
134+
{
135+
public Test()
136+
{
137+
Console.WriteLine(Encoding.UTF8.ToString());
138+
Console.WriteLine(DateTime.Parse("1999-01-01T00:01:01Z", CultureInfo.InvariantCulture));
139+
}
140+
}
141+
142+
143+
Given cs():
144+
using System;
145+
146+
using System.Text;
147+
148+
public class Test
149+
{
150+
public Test()
151+
{
152+
Console.WriteLine(Encoding.UTF8.ToString());
153+
Console.WriteLine(DateTime.Parse("1999-01-01T00:01:01Z", CultureInfo.InvariantCulture));
154+
}
155+
}
156+
157+
Execute (run fix usings with empty line and virtualedit=all):
158+
call OmniSharpTestInitializeBuffer('FixUsings4')
159+
set virtualedit=all
160+
call OmniSharpWarmup('OmniSharp#actions#usings#Fix', [])
161+
call OmniSharpTestAwait('OmniSharp#actions#usings#Fix', [])
162+
163+
Expect cs(should add another required using between the others):
164+
using System;
165+
using System.Globalization;
166+
using System.Text;
167+
168+
public class Test
169+
{
170+
public Test()
171+
{
172+
Console.WriteLine(Encoding.UTF8.ToString());
173+
Console.WriteLine(DateTime.Parse("1999-01-01T00:01:01Z", CultureInfo.InvariantCulture));
174+
}
175+
}
176+
177+
108178
Given cs():
109179
public class test {
110180
class1 ns1 = new class1();

0 commit comments

Comments
 (0)