From f4d57a525c1cd88a075ad69d23e0a76b9ead0f56 Mon Sep 17 00:00:00 2001 From: George Gerasev Date: Mon, 1 Jul 2024 19:26:52 +0300 Subject: [PATCH] outline tests changes --- .../src/Ide/Plugin/Cabal/Outline.hs | 35 ++++++----- plugins/hls-cabal-plugin/test/Outline.hs | 58 ++++++++++--------- .../schema/ghc98/default-config.golden.json | 3 +- .../ghc98/vscode-extension-schema.golden.json | 6 ++ 4 files changed, 56 insertions(+), 46 deletions(-) diff --git a/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Outline.hs b/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Outline.hs index fc3d449254..a272b5e2e1 100644 --- a/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Outline.hs +++ b/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Outline.hs @@ -3,7 +3,6 @@ {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ViewPatterns #-} module Ide.Plugin.Cabal.Outline where @@ -26,8 +25,8 @@ import Ide.Plugin.Cabal.Completion.Types (ParseCabalFields (..), import Ide.Plugin.Cabal.Orphans () import Ide.Types (PluginMethodHandler) import Language.LSP.Protocol.Message (Method (..)) -import qualified Language.LSP.Protocol.Types as LSP import Language.LSP.Protocol.Types (DocumentSymbol (..)) +import qualified Language.LSP.Protocol.Types as LSP moduleOutline :: PluginMethodHandler IdeState Method_TextDocumentDocumentSymbol @@ -49,18 +48,18 @@ documentSymbolForField :: Field Position -> Maybe DocumentSymbol documentSymbolForField (Field (Name pos fieldName) _) = Just (defDocumentSymbol range) - { LSP._name = decodeUtf8 fieldName, - LSP._kind = LSP.SymbolKind_Field, - LSP._children = Nothing + { _name = decodeUtf8 fieldName, + _kind = LSP.SymbolKind_Field, + _children = Nothing } where range = cabalPositionToLSPRange pos `addNameLengthToLSPRange` decodeUtf8 fieldName documentSymbolForField (Section (Name pos fieldName) sectionArgs fields) = Just (defDocumentSymbol range) - { LSP._name = joinedName, - LSP._kind = LSP.SymbolKind_Object, - LSP._children = + { _name = joinedName, + _kind = LSP.SymbolKind_Object, + _children = Just (mapMaybe documentSymbolForField fields) } @@ -92,13 +91,13 @@ addNameLengthToLSPRange (LSP.Range pos1 (LSP.Position line char)) name = (LSP.Position line (char + fromIntegral (T.length name))) defDocumentSymbol :: LSP.Range -> DocumentSymbol -defDocumentSymbol range = DocumentSymbol {..} - where - _detail = Nothing - _deprecated = Nothing - _name = "" - _kind = LSP.SymbolKind_File - _range = range - _selectionRange = range - _children = Nothing - _tags = Nothing +defDocumentSymbol range = DocumentSymbol + { _detail = Nothing + , _deprecated = Nothing + , _name = "" + , _kind = LSP.SymbolKind_File + , _range = range + , _selectionRange = range + , _children = Nothing + , _tags = Nothing + } diff --git a/plugins/hls-cabal-plugin/test/Outline.hs b/plugins/hls-cabal-plugin/test/Outline.hs index 0e9e8582a5..e0c52930e1 100644 --- a/plugins/hls-cabal-plugin/test/Outline.hs +++ b/plugins/hls-cabal-plugin/test/Outline.hs @@ -5,8 +5,7 @@ module Outline ( outlineTests ) where -import qualified Ide.Plugin.Cabal.Outline as Outline -import qualified Language.LSP.Protocol.Types as LSP +import Ide.Plugin.Cabal.Outline (defDocumentSymbol) import Test.Hls import Utils @@ -39,32 +38,37 @@ outlineTests = [sectionArgDocumentSymbol] ] where - fieldDocumentSymbol = (Outline.defDocumentSymbol (LSP.Range {_start = LSP.Position {_line = 0, _character = 0}, - _end = LSP.Position {_line = 0, _character = 8}})) - { LSP._name = "homepage", - LSP._kind = LSP.SymbolKind_Field, - LSP._children = Nothing + fieldDocumentSymbol :: DocumentSymbol + fieldDocumentSymbol = (defDocumentSymbol (Range {_start = Position {_line = 0, _character = 0}, + _end = Position {_line = 0, _character = 8}})) + { _name = "homepage", + _kind = SymbolKind_Field, + _children = Nothing } - fieldLineDocumentSymbol = (Outline.defDocumentSymbol (LSP.Range {_start = LSP.Position {_line = 0, _character = 0}, - _end = LSP.Position {_line = 0, _character = 13}})) - { LSP._name = "cabal-version", - LSP._kind = LSP.SymbolKind_Field, - LSP._children = Nothing -- the values of fieldLine are removed from the outline + fieldLineDocumentSymbol :: DocumentSymbol + fieldLineDocumentSymbol = (defDocumentSymbol (Range {_start = Position {_line = 0, _character = 0}, + _end = Position {_line = 0, _character = 13}})) + { _name = "cabal-version", + _kind = SymbolKind_Field, + _children = Nothing -- the values of fieldLine are removed from the outline } - sectionDocumentSymbol = (Outline.defDocumentSymbol (LSP.Range {_start = LSP.Position {_line = 0, _character = 2}, - _end = LSP.Position {_line = 0, _character = 15}})) - { LSP._name = "build-depends", - LSP._kind = LSP.SymbolKind_Field, - LSP._children = Nothing -- the values of fieldLine are removed from the outline + sectionDocumentSymbol :: DocumentSymbol + sectionDocumentSymbol = (defDocumentSymbol (Range {_start = Position {_line = 0, _character = 2}, + _end = Position {_line = 0, _character = 15}})) + { _name = "build-depends", + _kind = SymbolKind_Field, + _children = Nothing -- the values of fieldLine are removed from the outline } - sectionArgDocumentSymbol = (Outline.defDocumentSymbol (LSP.Range {_start = LSP.Position {_line = 0, _character = 2}, - _end = LSP.Position {_line = 0, _character = 19}})) - { LSP._name = "if os ( windows )", - LSP._kind = LSP.SymbolKind_Object, - LSP._children = Just $ [sectionArgChildrenDocumentSymbol] } - sectionArgChildrenDocumentSymbol = (Outline.defDocumentSymbol (LSP.Range {_start = LSP.Position {_line = 1, _character = 4}, - _end = LSP.Position {_line = 1, _character = 17}})) - { LSP._name = "build-depends", - LSP._kind = LSP.SymbolKind_Field, - LSP._children = Nothing + sectionArgDocumentSymbol :: DocumentSymbol + sectionArgDocumentSymbol = (defDocumentSymbol (Range {_start = Position {_line = 0, _character = 2}, + _end = Position {_line = 0, _character = 19}})) + { _name = "if os ( windows )", + _kind = SymbolKind_Object, + _children = Just $ [sectionArgChildrenDocumentSymbol] } + sectionArgChildrenDocumentSymbol :: DocumentSymbol + sectionArgChildrenDocumentSymbol = (defDocumentSymbol (Range {_start = Position {_line = 1, _character = 4}, + _end = Position {_line = 1, _character = 17}})) + { _name = "build-depends", + _kind = SymbolKind_Field, + _children = Nothing } diff --git a/test/testdata/schema/ghc98/default-config.golden.json b/test/testdata/schema/ghc98/default-config.golden.json index 2859e3d720..9b51765ec8 100644 --- a/test/testdata/schema/ghc98/default-config.golden.json +++ b/test/testdata/schema/ghc98/default-config.golden.json @@ -11,7 +11,8 @@ "cabal": { "codeActionsOn": true, "completionOn": true, - "diagnosticsOn": true + "diagnosticsOn": true, + "symbolsOn": true }, "cabal-fmt": { "config": { diff --git a/test/testdata/schema/ghc98/vscode-extension-schema.golden.json b/test/testdata/schema/ghc98/vscode-extension-schema.golden.json index d113264901..6dd980b2be 100644 --- a/test/testdata/schema/ghc98/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc98/vscode-extension-schema.golden.json @@ -35,6 +35,12 @@ "scope": "resource", "type": "boolean" }, + "haskell.plugin.cabal.symbolsOn": { + "default": true, + "description": "Enables cabal symbols", + "scope": "resource", + "type": "boolean" + }, "haskell.plugin.callHierarchy.globalOn": { "default": true, "description": "Enables callHierarchy plugin",