From d71c4eaf6a34ec787f45c7261d6a83f9b9ebdcee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20van=20Br=C3=BCgge?= Date: Thu, 8 Jun 2023 23:04:27 +0200 Subject: [PATCH] hls-notes-plugin: Initial implementation --- cabal.project | 1 + haskell-language-server.cabal | 11 + hls-plugin-api/src/Ide/Types.hs | 20 +- plugins/hls-notes-plugin/LICENSE | 201 ++++++++++++++++++ plugins/hls-notes-plugin/README.md | 30 +++ .../hls-notes-plugin/hls-notes-plugin.cabal | 76 +++++++ .../hls-notes-plugin/src/Ide/Plugin/Notes.hs | 125 +++++++++++ plugins/hls-notes-plugin/test/Main.hs | 43 ++++ .../hls-notes-plugin/test/testdata/NoteDef.hs | 14 ++ .../hls-notes-plugin/test/testdata/Other.hs | 6 + .../hls-notes-plugin/test/testdata/hie.yaml | 5 + src/HlsPlugins.hs | 7 + stack-lts21.yaml | 1 + stack.yaml | 1 + 14 files changed, 539 insertions(+), 2 deletions(-) create mode 100644 plugins/hls-notes-plugin/LICENSE create mode 100644 plugins/hls-notes-plugin/README.md create mode 100644 plugins/hls-notes-plugin/hls-notes-plugin.cabal create mode 100644 plugins/hls-notes-plugin/src/Ide/Plugin/Notes.hs create mode 100644 plugins/hls-notes-plugin/test/Main.hs create mode 100644 plugins/hls-notes-plugin/test/testdata/NoteDef.hs create mode 100644 plugins/hls-notes-plugin/test/testdata/Other.hs create mode 100644 plugins/hls-notes-plugin/test/testdata/hie.yaml diff --git a/cabal.project b/cabal.project index 75dbc2656b5..569678c6e08 100644 --- a/cabal.project +++ b/cabal.project @@ -33,6 +33,7 @@ packages: ./plugins/hls-explicit-record-fields-plugin ./plugins/hls-refactor-plugin ./plugins/hls-overloaded-record-dot-plugin + ./plugins/hls-notes-plugin index-state: 2023-10-06T06:12:29Z diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index 715950a049c..d0403ad828c 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -159,6 +159,11 @@ flag overloadedRecordDot default: True manual: True +flag notes + description: Enable notes plugin + default: True + manual: True + -- formatters flag floskell @@ -296,6 +301,11 @@ common overloadedRecordDot build-depends: hls-overloaded-record-dot-plugin == 2.4.0.0 cpp-options: -Dhls_overloaded_record_dot +common notes + if flag(notes) + build-depends: hls-notes-plugin == 2.2.0.0 + cpp-options: -Dhls_notes + -- formatters common floskell @@ -348,6 +358,7 @@ library , gadt , explicitFixity , explicitFields + , notes , floskell , fourmolu , ormolu diff --git a/hls-plugin-api/src/Ide/Types.hs b/hls-plugin-api/src/Ide/Types.hs index 9159fc45962..1d358dee999 100644 --- a/hls-plugin-api/src/Ide/Types.hs +++ b/hls-plugin-api/src/Ide/Types.hs @@ -568,11 +568,27 @@ instance PluginRequestMethod Method_CodeActionResolve where -- See Note [Resolve in PluginHandlers]. combineResponses _ _ _ _ (x :| _) = x +combineDefinitions :: NonEmpty (Definition |? ([DefinitionLink] |? Null)) -> (Definition |? ([DefinitionLink] |? Null)) +combineDefinitions (x :| []) = x +combineDefinitions (x :| (y:ys)) = combineDefinitions (combineOne x y :| ys) + where + toList (InL x) = [x] + toList (InR xs) = xs + upgrade (Location uri range) = DefinitionLink $ LocationLink Nothing uri range range + maybeSingle [x] = InL x + maybeSingle xs = InR xs + combineOne (InR (InR _)) y = y + combineOne x (InR (InR _)) = x + combineOne (InL (Definition x)) (InL (Definition y)) = InL (Definition (maybeSingle (toList x <> toList y))) + combineOne (InL (Definition x)) (InR (InL ys)) = InR (InL (map upgrade (toList x) <> ys)) + combineOne (InR (InL xs)) (InL (Definition x)) = InR (InL (xs <> map upgrade (toList x))) + combineOne (InR (InL xs)) (InR (InL ys)) = InR (InL (xs <> ys)) + instance PluginRequestMethod Method_TextDocumentDefinition where - combineResponses _ _ _ _ (x :| _) = x + combineResponses _ _ _ _ xs = combineDefinitions xs instance PluginRequestMethod Method_TextDocumentTypeDefinition where - combineResponses _ _ _ _ (x :| _) = x + combineResponses _ _ _ _ xs = combineDefinitions xs instance PluginRequestMethod Method_TextDocumentDocumentHighlight where diff --git a/plugins/hls-notes-plugin/LICENSE b/plugins/hls-notes-plugin/LICENSE new file mode 100644 index 00000000000..261eeb9e9f8 --- /dev/null +++ b/plugins/hls-notes-plugin/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/plugins/hls-notes-plugin/README.md b/plugins/hls-notes-plugin/README.md new file mode 100644 index 00000000000..60a9a4d4c0c --- /dev/null +++ b/plugins/hls-notes-plugin/README.md @@ -0,0 +1,30 @@ +# Note plugin + +The [Note convention](https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/coding-style#2-using-notes) is a nice way to hoist and share big chunks of documentation out of the body of functions. This is done by referencing a long form note from within the function. This plugin extends goto-definition to jump from the reference to the note. + +# Example + +Main.hs +```haskell +module Main where + +main :: IO +main = do + doSomething -- We need this here, see Note [Do Something] in Foo +``` + +Foo.hs +``` +module Foo where + +doSomething :: IO () +doSomething = undefined + +{- +Note [Do Something] +~~~~~~~~~~~~~~~~~~~ +Some very important explanation +-} +``` + +Using "Go-to-definition on the Note reference in `Main.hs` will jump to the beginning of the note in `Foo.hs`. diff --git a/plugins/hls-notes-plugin/hls-notes-plugin.cabal b/plugins/hls-notes-plugin/hls-notes-plugin.cabal new file mode 100644 index 00000000000..37d16d272dc --- /dev/null +++ b/plugins/hls-notes-plugin/hls-notes-plugin.cabal @@ -0,0 +1,76 @@ +cabal-version: 3.0 +name: hls-notes-plugin +version: 2.2.0.0 +synopsis: GHC-style notes for Haskell Language Server +description: + Please see the README on GitHub at +license: Apache-2.0 +license-file: LICENSE +author: Jan van Brügge +maintainer: supermanitu@gmail.com +category: Development +build-type: Simple +extra-source-files: + LICENSE + test/testdata/*.hs + +source-repository head + type: git + location: https://github.com/haskell/haskell-language-server + +common warnings + ghc-options: -Wall -Wno-unticked-promoted-constructors + default-language: Haskell2010 + default-extensions: + BangPatterns + DataKinds + DeriveAnyClass + DeriveGeneric + DerivingStrategies + ExplicitNamespaces + FlexibleContexts + LambdaCase + OverloadedStrings + TupleSections + TypeFamilies + +library + import: warnings + exposed-modules: Ide.Plugin.Notes + build-depends: + , base >=4.12 && <5 + , array + , bytestring + , ghcide + , hls-plugin-api + , hls-graph + , lens + , lsp + , mtl + , regex-tdfa ^>= 1.3.1 + , text + , text-rope + , transformers + , unordered-containers + hs-source-dirs: src + +test-suite tests + import: warnings + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: Main.hs + default-extensions: + OverloadedStrings + build-depends: + , base + , bytestring + , directory + , filepath + , ghcide + , ghcide-test-utils + , hls-notes-plugin + , hls-test-utils + , lens + , lsp-types + , tasty-hunit + , text diff --git a/plugins/hls-notes-plugin/src/Ide/Plugin/Notes.hs b/plugins/hls-notes-plugin/src/Ide/Plugin/Notes.hs new file mode 100644 index 00000000000..76c4db3dd36 --- /dev/null +++ b/plugins/hls-notes-plugin/src/Ide/Plugin/Notes.hs @@ -0,0 +1,125 @@ +module Ide.Plugin.Notes (descriptor, Log) where + +import Control.Lens (ix, (^.), (^?)) +import Control.Monad.Except +import Control.Monad.IO.Class (liftIO) +import Control.Monad.Trans (lift) +import qualified Data.Array as A +import Data.HashMap.Strict (HashMap) +import qualified Data.HashMap.Strict as HM +import qualified Data.HashSet as HS +import Data.Maybe (catMaybes, listToMaybe, + mapMaybe) +import Data.Text (Text, intercalate) +import qualified Data.Text as T +import qualified Data.Text.Utf16.Rope as Rope +import Development.IDE hiding (line) +import Development.IDE.Core.PluginUtils (runActionE, useE) +import Development.IDE.Core.Shake (toKnownFiles) +import qualified Development.IDE.Core.Shake as Shake +import Development.IDE.Graph.Classes (Hashable, NFData) +import GHC.Generics (Generic) +import Ide.Plugin.Error (PluginError (..)) +import Ide.Types +import qualified Language.LSP.Protocol.Lens as L +import Language.LSP.Protocol.Message (Method (Method_TextDocumentDefinition), + SMethod (SMethod_TextDocumentDefinition)) +import Language.LSP.Protocol.Types +import qualified Language.LSP.Server as LSP +import Language.LSP.VFS (VirtualFile (..)) +import Text.Regex.TDFA (Regex, caseSensitive, + defaultCompOpt, + defaultExecOpt, + makeRegexOpts, matchAllText) + +data Log + = LogShake Shake.Log + | LogNotesFound NormalizedFilePath [(Text, Position)] + deriving Show + +data GetNotesInFile = MkGetNotesInFile + deriving (Show, Generic, Eq, Ord) + deriving anyclass (Hashable, NFData) +type instance RuleResult GetNotesInFile = HM.HashMap Text Position + +data GetNotes = MkGetNotes + deriving (Show, Generic, Eq, Ord) + deriving anyclass (Hashable, NFData) +type instance RuleResult GetNotes = HashMap Text (NormalizedFilePath, Position) + +instance Pretty Log where + pretty = \case + LogShake l -> pretty l + LogNotesFound file notes -> + "Found notes in " <> pretty (show file) <> ": [" + <> pretty (intercalate ", " (fmap (\(s, p) -> "\"" <> s <> "\" at " <> T.pack (show p)) notes)) <> "]" + +descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState +descriptor recorder plId = (defaultPluginDescriptor plId) + { Ide.Types.pluginRules = findNotesRules recorder + , Ide.Types.pluginHandlers = mkPluginHandler SMethod_TextDocumentDefinition jumpToNote + } + +findNotesRules :: Recorder (WithPriority Log) -> Rules () +findNotesRules recorder = do + defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \MkGetNotesInFile nfp -> do + findNotesInFile nfp recorder + + defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \MkGetNotes _ -> do + targets <- toKnownFiles <$> useNoFile_ GetKnownTargets + definedNotes <- catMaybes <$> mapM (\nfp -> fmap (HM.map (nfp,)) <$> use MkGetNotesInFile nfp) (HS.toList targets) + pure $ Just $ HM.unions definedNotes + +jumpToNote :: PluginMethodHandler IdeState Method_TextDocumentDefinition +jumpToNote state _ param + | Just nfp <- uriToNormalizedFilePath uriOrig + = do + let Position l c = param ^. L.position + contents <- fmap _file_text . err "Error getting file contents" + =<< lift (LSP.getVirtualFile uriOrig) + line <- err "Line not found in file" (Rope.lines contents ^? ix (fromIntegral l)) + note <- err "No note at this position" $ listToMaybe $ + mapMaybe (atPos $ fromIntegral c) $ matchAllText noteRefRegex line + notes <- runActionE "notes.definedNotes" state $ useE MkGetNotes nfp + (noteFp, pos) <- err "Note not found" (HM.lookup note notes) + pure $ InL (Definition (InL + (Location (fromNormalizedUri $ normalizedFilePathToUri noteFp) (Range pos pos)) + )) + where + uriOrig = toNormalizedUri $ param ^. (L.textDocument . L.uri) + err s = maybe (throwError $ PluginInternalError s) pure + atPos c arr = case arr A.! 0 of + (_, (c', len)) -> if c' <= c && c <= c' + len + then Just (fst (arr A.! 1)) else Nothing +jumpToNote _ _ _ = throwError $ PluginInternalError "conversion to normalized file path failed" + +findNotesInFile :: NormalizedFilePath -> Recorder (WithPriority Log) -> Action (Maybe (HM.HashMap Text Position)) +findNotesInFile file recorder = do + contentOpt <- (snd =<<) <$> use GetFileContents file + content <- case contentOpt of + Just x -> pure x + Nothing -> liftIO $ readFileUtf8 $ fromNormalizedFilePath file + let matches = (A.! 1) <$> matchAllText noteRegex content + m = toPositions matches content + logWith recorder Debug $ LogNotesFound file (HM.toList m) + pure $ Just m + where + uint = fromIntegral . toInteger + toPositions matches = snd . fst . T.foldl' (\case + (([], m), _) -> const (([], m), (0, 0, 0)) + ((x@(name, (char, _)):xs, m), (n, nc, c)) -> \char' -> + let !c' = c + 1 + (!n', !nc') = if char' == '\n' then (n + 1, c') else (n, nc) + p = if char == c then + (xs, HM.insert name (Position (uint n') (uint (char - nc'))) m) + else (x:xs, m) + in (p, (n', nc', c')) + ) ((matches, HM.empty), (0, 0, 0)) + +noteRefRegex, noteRegex :: Regex +(noteRefRegex, noteRegex) = + ( mkReg ("note \\[(.+)\\]" :: String) + , mkReg ("note \\[([[:print:]]+)\\][[:blank:]]*[[:space:]][[:space:]]?~~~" :: String) + ) + where + mkReg = makeRegexOpts (defaultCompOpt { caseSensitive = False }) defaultExecOpt diff --git a/plugins/hls-notes-plugin/test/Main.hs b/plugins/hls-notes-plugin/test/Main.hs new file mode 100644 index 00000000000..7d4f63a0344 --- /dev/null +++ b/plugins/hls-notes-plugin/test/Main.hs @@ -0,0 +1,43 @@ +module Main (main) where + +import Development.IDE.Test +import Ide.Plugin.Notes (Log, descriptor) +import System.Directory (canonicalizePath) +import System.FilePath (()) +import Test.Hls + +plugin :: PluginTestDescriptor Log +plugin = mkPluginTestDescriptor descriptor "notes" + +main :: IO () +main = defaultTestRunner $ + testGroup "Notes" + [ gotoNoteTests + ] + +gotoNoteTests :: TestTree +gotoNoteTests = testGroup "Goto Note Definition" + [ testCase "single_file" $ runSessionWithServer def plugin testDataDir $ do + doc <- openDoc "NoteDef.hs" "haskell" + _ <- waitForAllProgressDone + defs <- getDefinitions doc (Position 3 41) + liftIO $ do + fp <- canonicalizePath "NoteDef.hs" + defs @?= InL (Definition (InL (Location (filePathToUri fp) (Range (Position 5 9) (Position 5 9))))) + , testCase "no_note" $ runSessionWithServer def plugin testDataDir $ do + doc <- openDoc "NoteDef.hs" "haskell" + defs <- getDefinitions doc (Position 1 0) + liftIO $ defs @?= InL (Definition (InR [])) + + , testCase "unopened_file" $ runSessionWithServer def plugin testDataDir $ do + doc <- openDoc "Other.hs" "haskell" + waitForCustomMessage "ghcide/cradle/loaded" (const $ Just ()) + waitForAllProgressDone + defs <- getDefinitions doc (Position 5 20) + liftIO $ do + fp <- canonicalizePath "NoteDef.hs" + defs @?= InL (Definition (InL (Location (filePathToUri fp) (Range (Position 9 6) (Position 9 6))))) + ] + +testDataDir :: FilePath +testDataDir = "test" "testdata" diff --git a/plugins/hls-notes-plugin/test/testdata/NoteDef.hs b/plugins/hls-notes-plugin/test/testdata/NoteDef.hs new file mode 100644 index 00000000000..ef5d9921969 --- /dev/null +++ b/plugins/hls-notes-plugin/test/testdata/NoteDef.hs @@ -0,0 +1,14 @@ +module NoteDef (foo) where + +foo :: Int -> Int +foo _ = 0 -- We always return zero, see Note [Returning zero from foo] + +{- Note [Returning zero from foo] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This is a big long form note, with very important info + +Note [Multiple notes in comment] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This is also a very common thing to do for GHC + +-} diff --git a/plugins/hls-notes-plugin/test/testdata/Other.hs b/plugins/hls-notes-plugin/test/testdata/Other.hs new file mode 100644 index 00000000000..65f9a483aa3 --- /dev/null +++ b/plugins/hls-notes-plugin/test/testdata/Other.hs @@ -0,0 +1,6 @@ +module Other where + +import NoteDef + +bar :: Int +bar = 4 -- See @Note [Multiple notes in comment]@ in NoteDef diff --git a/plugins/hls-notes-plugin/test/testdata/hie.yaml b/plugins/hls-notes-plugin/test/testdata/hie.yaml new file mode 100644 index 00000000000..59cc740ee80 --- /dev/null +++ b/plugins/hls-notes-plugin/test/testdata/hie.yaml @@ -0,0 +1,5 @@ +cradle: + direct: + arguments: + - Other + - NoteDef diff --git a/src/HlsPlugins.hs b/src/HlsPlugins.hs index aadd56bbdee..582636f03c1 100644 --- a/src/HlsPlugins.hs +++ b/src/HlsPlugins.hs @@ -90,6 +90,10 @@ import qualified Ide.Plugin.ExplicitFields as ExplicitFields import qualified Ide.Plugin.OverloadedRecordDot as OverloadedRecordDot #endif +#if hls_notes +import qualified Ide.Plugin.Notes as Notes +#endif + -- formatters #if hls_floskell @@ -216,6 +220,9 @@ idePlugins recorder = pluginDescToIdePlugins allPlugins #endif #if hls_overloaded_record_dot let pId = "overloaded-record-dot" in OverloadedRecordDot.descriptor (pluginRecorder pId) pId : +#endif +#if hls_notes + let pId = "notes" in Notes.descriptor (pluginRecorder pId) pId : #endif GhcIde.descriptors (pluginRecorder "ghcide") diff --git a/stack-lts21.yaml b/stack-lts21.yaml index 5f26370a2ab..6b3344093ae 100644 --- a/stack-lts21.yaml +++ b/stack-lts21.yaml @@ -25,6 +25,7 @@ packages: - ./plugins/hls-gadt-plugin - ./plugins/hls-hlint-plugin - ./plugins/hls-module-name-plugin + - ./plugins/hls-notes-plugin - ./plugins/hls-ormolu-plugin - ./plugins/hls-overloaded-record-dot-plugin - ./plugins/hls-pragmas-plugin diff --git a/stack.yaml b/stack.yaml index bba26fd4b61..a5456bb61bb 100644 --- a/stack.yaml +++ b/stack.yaml @@ -25,6 +25,7 @@ packages: - ./plugins/hls-gadt-plugin - ./plugins/hls-hlint-plugin - ./plugins/hls-module-name-plugin + - ./plugins/hls-notes-plugin - ./plugins/hls-ormolu-plugin - ./plugins/hls-overloaded-record-dot-plugin - ./plugins/hls-pragmas-plugin