|
| 1 | +require_relative "../../test_helper" |
| 2 | + |
| 3 | +class TestLSPCommands < Textbringer::TestCase |
| 4 | + def test_lsp_completion_context_invoked_with_prefix |
| 5 | + # When there is a prefix typed, always use Invoked (triggerKind 1) |
| 6 | + context = lsp_completion_context("fo", ["."], ".") |
| 7 | + assert_equal({ triggerKind: 1 }, context) |
| 8 | + end |
| 9 | + |
| 10 | + def test_lsp_completion_context_invoked_no_trigger_char |
| 11 | + # Empty prefix but char before start is not a trigger character |
| 12 | + context = lsp_completion_context("", ["."], "x") |
| 13 | + assert_equal({ triggerKind: 1 }, context) |
| 14 | + end |
| 15 | + |
| 16 | + def test_lsp_completion_context_invoked_no_trigger_chars_configured |
| 17 | + # No trigger characters configured on the server |
| 18 | + context = lsp_completion_context("", [], ".") |
| 19 | + assert_equal({ triggerKind: 1 }, context) |
| 20 | + end |
| 21 | + |
| 22 | + def test_lsp_completion_context_trigger_character |
| 23 | + # Empty prefix and char before start is a trigger character → TriggerCharacter (triggerKind 2) |
| 24 | + context = lsp_completion_context("", ["."], ".") |
| 25 | + assert_equal({ triggerKind: 2, triggerCharacter: "." }, context) |
| 26 | + end |
| 27 | + |
| 28 | + def test_lsp_completion_context_trigger_character_colon |
| 29 | + # Empty prefix and :: trigger |
| 30 | + context = lsp_completion_context("", [":", "::", "."], ":") |
| 31 | + assert_equal({ triggerKind: 2, triggerCharacter: ":" }, context) |
| 32 | + end |
| 33 | + |
| 34 | + def test_lsp_completion_context_prefix_overrides_trigger_char |
| 35 | + # Even when char before start is a trigger char, prefix present → Invoked |
| 36 | + context = lsp_completion_context("bo", ["."], ".") |
| 37 | + assert_equal({ triggerKind: 1 }, context) |
| 38 | + end |
| 39 | +end |
0 commit comments