|
2 | 2 | {-# LANGUAGE OverloadedStrings #-} |
3 | 3 | {-# LANGUAGE TypeFamilies #-} |
4 | 4 | module Ide.PluginUtils |
5 | | - ( WithDeletions(..), |
6 | | - getProcessID, |
| 5 | + ( -- * LSP Range manipulation functions |
7 | 6 | normalize, |
| 7 | + extendNextLine, |
| 8 | + extendLineStart, |
| 9 | + WithDeletions(..), |
| 10 | + getProcessID, |
8 | 11 | makeDiffTextEdit, |
9 | 12 | makeDiffTextEditAdditive, |
10 | 13 | diffText, |
@@ -67,9 +70,27 @@ import qualified Text.Megaparsec.Char.Lexer as P |
67 | 70 | -- --------------------------------------------------------------------- |
68 | 71 |
|
69 | 72 | -- | Extend to the line below and above to replace newline character. |
| 73 | +-- |
| 74 | +-- >>> normalize (Range (Position 5 5) (Position 5 10)) |
| 75 | +-- Range (Position 5 0) (Position 6 0) |
70 | 76 | normalize :: Range -> Range |
71 | | -normalize (Range (Position sl _) (Position el _)) = |
72 | | - Range (Position sl 0) (Position (el + 1) 0) |
| 77 | +normalize = extendLineStart . extendNextLine |
| 78 | + |
| 79 | +-- | Extend 'Range' to the start of the next line. |
| 80 | +-- |
| 81 | +-- >>> extendNextLine (Range (Position 5 5) (Position 5 10)) |
| 82 | +-- Range (Position 5 5) (Position 6 0) |
| 83 | +extendNextLine :: Range -> Range |
| 84 | +extendNextLine (Range s (Position el _)) = |
| 85 | + Range s (Position (el + 1) 0) |
| 86 | + |
| 87 | +-- | Extend 'Range' to the start of the current line. |
| 88 | +-- |
| 89 | +-- >>> extendLineStart (Range (Position 5 5) (Position 5 10)) |
| 90 | +-- Range (Position 5 0) (Position 5 10) |
| 91 | +extendLineStart :: Range -> Range |
| 92 | +extendLineStart (Range (Position sl _) e) = |
| 93 | + Range (Position sl 0) e |
73 | 94 |
|
74 | 95 | -- --------------------------------------------------------------------- |
75 | 96 |
|
|
0 commit comments