Skip to content

Commit fd0b2ea

Browse files
committed
small improvements
1 parent 965d61b commit fd0b2ea

File tree

1 file changed

+19
-16
lines changed
  • plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal

1 file changed

+19
-16
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Outline.hs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ where
1414
import Control.Monad.IO.Class
1515
import Data.Maybe
1616
import Data.Text qualified as T
17-
import Data.Text.Encoding (decodeASCII, decodeLatin1)
17+
import Data.Text.Encoding (decodeUtf8)
1818
import Development.IDE.Core.Rules
1919
import Development.IDE.Core.Shake (IdeState (shakeExtras), runIdeAction, useWithStaleFast)
2020
import Development.IDE.Types.Location (toNormalizedFilePath')
@@ -27,7 +27,7 @@ import Distribution.Fields.Field
2727
import Distribution.Parsec.Position (Position)
2828
import Ide.Plugin.Cabal.Completion.Types (ParseCabalFields (..), cabalPositionToLSPPosition)
2929
import Ide.Plugin.Cabal.Orphans ()
30-
import Ide.Types
30+
import Ide.Types ( PluginMethodHandler )
3131
import Language.LSP.Protocol.Message qualified as LSP
3232
import Language.LSP.Protocol.Types qualified as LSP
3333

@@ -47,16 +47,16 @@ documentSymbolForField :: Field Position -> Maybe LSP.DocumentSymbol
4747
documentSymbolForField (Field (Name pos fieldName) fieldLines) =
4848
Just
4949
(defDocumentSymbol range)
50-
{ LSP._name = decodeASCII fieldName,
51-
LSP._kind = LSP.SymbolKind_Object,
50+
{ LSP._name = decodeUtf8 fieldName,
51+
LSP._kind = LSP.SymbolKind_Field,
5252
LSP._children = Just $ mapMaybe documentSymbolForFieldLine fieldLines
5353
}
5454
where
55-
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII fieldName
55+
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 fieldName
5656
documentSymbolForField (Section (Name pos fieldName) sectionArgs fields) =
5757
Just
5858
(defDocumentSymbol range)
59-
{ LSP._name = decodeASCII fieldName,
59+
{ LSP._name = decodeUtf8 fieldName,
6060
LSP._kind = LSP.SymbolKind_Object,
6161
LSP._children =
6262
Just
@@ -65,48 +65,51 @@ documentSymbolForField (Section (Name pos fieldName) sectionArgs fields) =
6565
)
6666
}
6767
where
68-
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII fieldName
68+
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 fieldName
6969

7070
documentSymbolForSectionArgs :: SectionArg Position -> Maybe LSP.DocumentSymbol
7171
documentSymbolForSectionArgs (SecArgName pos identifier) =
7272
Just
7373
(defDocumentSymbol range)
74-
{ LSP._name = decodeLatin1 identifier,
74+
{ LSP._name = decodeUtf8 identifier,
7575
LSP._kind = LSP.SymbolKind_Variable,
7676
LSP._children = Nothing
7777
}
7878
where
79-
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII identifier
79+
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 identifier
8080
documentSymbolForSectionArgs (SecArgStr pos quotedString) =
8181
Just
8282
(defDocumentSymbol range)
83-
{ LSP._name = decodeLatin1 quotedString,
83+
{ LSP._name = decodeUtf8 quotedString,
8484
LSP._kind = LSP.SymbolKind_Constant,
8585
LSP._children = Nothing
8686
}
8787
where
88-
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII quotedString
88+
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 quotedString
8989
documentSymbolForSectionArgs (SecArgOther pos string) =
9090
Just
9191
(defDocumentSymbol range)
92-
{ LSP._name = decodeLatin1 string,
92+
{ LSP._name = decodeUtf8 string,
9393
LSP._kind = LSP.SymbolKind_String,
9494
LSP._children = Nothing
9595
}
9696
where
97-
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII string
97+
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 string
9898

9999
documentSymbolForFieldLine :: FieldLine Position -> Maybe LSP.DocumentSymbol
100100
documentSymbolForFieldLine (FieldLine pos line) =
101101
Just
102102
(defDocumentSymbol range)
103-
{ LSP._name = decodeLatin1 line, -- since there is no ascii invariant (?)
103+
{ LSP._name = decodeUtf8 line,
104104
LSP._kind = LSP.SymbolKind_Field,
105-
LSP._children = Nothing -- can't delete even though the base case covers this (?)
105+
LSP._children = Nothing
106106
}
107107
where
108-
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeASCII line
108+
range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 line
109+
109110

111+
-- | Creates a single point LSP range
112+
-- using cabal position
110113
cabalPositionToLSPRange :: Position -> LSP.Range
111114
cabalPositionToLSPRange pos = LSP.Range lspPos lspPos
112115
where

0 commit comments

Comments
 (0)