Skip to content

Commit 33e24d1

Browse files
authored
Support Windsurf for setting cursor position in snippets (#3634)
Inspired by #3302
1 parent c50572c commit 33e24d1

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/ruby_lsp/requests/on_type_formatting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def add_edit_with_text(text, position = @position)
162162

163163
#: (Integer line, Integer character) -> void
164164
def move_cursor_to(line, character)
165-
return unless /Visual Studio Code|Cursor|VSCodium/.match?(@client_name)
165+
return unless /Visual Studio Code|Cursor|VSCodium|Windsurf/.match?(@client_name)
166166

167167
position = Interface::Position.new(
168168
line: line,

test/requests/on_type_formatting_test.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,46 @@ def test_includes_snippets_on_vscodium
10151015
assert_equal(expected_edits.to_json, edits.to_json)
10161016
end
10171017

1018+
def test_includes_snippets_on_windsurf
1019+
document = RubyLsp::RubyDocument.new(
1020+
source: +"",
1021+
version: 1,
1022+
uri: URI("file:///fake.rb"),
1023+
global_state: @global_state,
1024+
)
1025+
1026+
document.push_edits(
1027+
[{
1028+
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } },
1029+
text: "class Foo",
1030+
}],
1031+
version: 2,
1032+
)
1033+
document.parse!
1034+
1035+
edits = RubyLsp::Requests::OnTypeFormatting.new(
1036+
document,
1037+
{ line: 1, character: 2 },
1038+
"\n",
1039+
"Windsurf",
1040+
).perform
1041+
expected_edits = [
1042+
{
1043+
range: { start: { line: 1, character: 2 }, end: { line: 1, character: 2 } },
1044+
newText: "\n",
1045+
},
1046+
{
1047+
range: { start: { line: 1, character: 2 }, end: { line: 1, character: 2 } },
1048+
newText: "end",
1049+
},
1050+
{
1051+
range: { start: { line: 1, character: 2 }, end: { line: 1, character: 2 } },
1052+
newText: "$0",
1053+
},
1054+
]
1055+
assert_equal(expected_edits.to_json, edits.to_json)
1056+
end
1057+
10181058
def test_does_not_confuse_class_parameter_with_keyword
10191059
document = RubyLsp::RubyDocument.new(
10201060
source: +"",

0 commit comments

Comments
 (0)