|
| 1 | +Describe lsp#internal#diagnostics#under_cursor |
| 2 | + " refer to lsp#test#projectdir('go') . '/documentdiagnostics.go' |
| 3 | + |
| 4 | + It should not trigger diagnostics when cursor is outside diagnostic range |
| 5 | + let l:diagnostics = [ |
| 6 | + \ { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 7 | + \ ] |
| 8 | + Assert Equals(lsp#internal#diagnostics#under_cursor#_get_closest_diagnostic(l:diagnostics, 1, 1), {}) |
| 9 | + End |
| 10 | + |
| 11 | + It should trigger diagnostic when cursor is exactly at start position |
| 12 | + let l:diagnostics = [ |
| 13 | + \ { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 14 | + \ ] |
| 15 | + let l:expected = { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 16 | + Assert Equals(lsp#internal#diagnostics#under_cursor#_get_closest_diagnostic(l:diagnostics, 7, 13), l:expected) |
| 17 | + End |
| 18 | + |
| 19 | + It should not trigger diagnostic when cursor is at line before start position |
| 20 | + let l:diagnostics = [ |
| 21 | + \ { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 22 | + \ ] |
| 23 | + Assert Equals(lsp#internal#diagnostics#under_cursor#_get_closest_diagnostic(l:diagnostics, 6, 13), {}) |
| 24 | + End |
| 25 | + |
| 26 | + It should not trigger diagnostic when cursor is one character before start position |
| 27 | + let l:diagnostics = [ |
| 28 | + \ { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 29 | + \ ] |
| 30 | + Assert Equals(lsp#internal#diagnostics#under_cursor#_get_closest_diagnostic(l:diagnostics, 7, 12), {}) |
| 31 | + End |
| 32 | + |
| 33 | + It should trigger diagnostic when cursor is at start column on an intermediate line within range |
| 34 | + let l:diagnostics = [ |
| 35 | + \ { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 36 | + \ ] |
| 37 | + let l:expected = { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 38 | + Assert Equals(lsp#internal#diagnostics#under_cursor#_get_closest_diagnostic(l:diagnostics, 8, 1), l:expected) |
| 39 | + End |
| 40 | + |
| 41 | + It should trigger diagnostic when cursor is at end column on an intermediate line within range |
| 42 | + let l:diagnostics = [ |
| 43 | + \ { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 44 | + \ ] |
| 45 | + let l:expected = { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 46 | + Assert Equals(lsp#internal#diagnostics#under_cursor#_get_closest_diagnostic(l:diagnostics, 8, 15), l:expected) |
| 47 | + End |
| 48 | + |
| 49 | + It should trigger diagnostic when cursor is exactly at end position |
| 50 | + let l:diagnostics = [ |
| 51 | + \ { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 52 | + \ ] |
| 53 | + let l:expected = { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 54 | + Assert Equals(lsp#internal#diagnostics#under_cursor#_get_closest_diagnostic(l:diagnostics, 9, 5), l:expected) |
| 55 | + End |
| 56 | + |
| 57 | + It should not trigger diagnostic when cursor is at line after end position |
| 58 | + let l:diagnostics = [ |
| 59 | + \ { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 60 | + \ ] |
| 61 | + Assert Equals(lsp#internal#diagnostics#under_cursor#_get_closest_diagnostic(l:diagnostics, 10, 5), {}) |
| 62 | + End |
| 63 | + |
| 64 | + It should not return diagnostic when cursor is one character after end position |
| 65 | + let l:diagnostics = [ |
| 66 | + \ { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 67 | + \ ] |
| 68 | + Assert Equals(lsp#internal#diagnostics#under_cursor#_get_closest_diagnostic(l:diagnostics, 9, 6), {}) |
| 69 | + End |
| 70 | + |
| 71 | + It should return the closest diagnostic when multiple diagnostics exist across different ranges |
| 72 | + let l:diagnostics = [ |
| 73 | + \ { 'range': {'start': {'character': 10, 'line': 4}, 'end': {'character': 7, 'line': 10}} }, |
| 74 | + \ { 'range': {'start': {'character': 12, 'line': 6}, 'end': {'character': 5, 'line': 8}} } |
| 75 | + \ ] |
| 76 | + let l:expected = { 'range': {'start': {'character': 10, 'line': 4}, 'end': {'character': 7, 'line': 10}} } |
| 77 | + Assert Equals(lsp#internal#diagnostics#under_cursor#_get_closest_diagnostic(l:diagnostics, 7, 3), l:expected) |
| 78 | + End |
| 79 | + |
| 80 | + It should return the most specific diagnostic when multiple diagnostics overlap at cursor position |
| 81 | + let l:diagnostics = [ |
| 82 | + \ { 'range': {'start': {'character': 10, 'line': 4}, 'end': {'character': 15, 'line': 4}} }, |
| 83 | + \ { 'range': {'start': {'character': 12, 'line': 4}, 'end': {'character': 14, 'line': 4}} } |
| 84 | + \ ] |
| 85 | + let l:expected = { 'range': {'start': {'character': 12, 'line': 4}, 'end': {'character': 14, 'line': 4}} } |
| 86 | + Assert Equals(lsp#internal#diagnostics#under_cursor#_get_closest_diagnostic(l:diagnostics, 5, 13), l:expected) |
| 87 | + End |
| 88 | +End |
0 commit comments