hls-plugin-api-2.9.0.0: Haskell Language Server API for plugin communication

Safe Haskell | None
Language | GHC2021

Ide.PluginUtils

Contents

- LSP Range manipulation functions
- Escape
- toAbsolute

Synopsis

- normalize :: Range -> Range
- extendNextLine :: Range -> Range
- extendLineStart :: Range -> Range
- extendToFullLines :: Range -> Range
- data WithDeletions
  - = IncludeDeletions
  - | SkipDeletions
- getProcessID :: IO Int
- makeDiffTextEdit :: Text -> Text -> [TextEdit]
- makeDiffTextEditAdditive :: Text -> Text -> [TextEdit]
- diffText :: ClientCapabilities -> (VersionedTextDocumentIdentifier, Text) -> Text -> WithDeletions -> WorkspaceEdit
- diffText' :: Bool -> (VersionedTextDocumentIdentifier, Text) -> Text -> WithDeletions -> WorkspaceEdit
- pluginDescToIdePlugins :: [PluginDescriptor ideState] -> IdePlugins ideState
- idePluginsToPluginDesc :: IdePlugins ideState -> [PluginDescriptor ideState]
- getClientConfig :: MonadLsp Config m => m Config
- getPluginConfig :: MonadLsp Config m => PluginDescriptor c -> m PluginConfig
- configForPlugin :: Config -> PluginDescriptor c -> PluginConfig
- handlesRequest :: PluginMethod k m => SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> HandleRequestResult
- extractTextInRange :: Range -> Text -> Text
- fullRange :: Text -> Range
- mkLspCommand :: PluginId -> CommandId -> Text -> Maybe [Value] -> Command
- mkLspCmdId :: Text -> PluginId -> CommandId -> Text
- getPid :: IO Text
- allLspCmdIds :: Text -> [(PluginId, [PluginCommand ideState])] -> [Text]
- allLspCmdIds' :: Text -> IdePlugins ideState -> [Text]
- installSigUsr1Handler :: IO () -> IO ()
- subRange :: Range -> Range -> Bool
- positionInRange :: Position -> Range -> Bool
- usePropertyLsp :: forall (s :: Symbol) (k :: PropertyKey) (t :: PropertyType) (r :: [PropertyKey]) m c. (HasProperty s k t r, MonadLsp Config m) => KeyNameProxy s -> PluginDescriptor c -> Properties r -> m (ToHsType t)
- unescape :: Text -> Text
- toAbsolute :: FilePath -> FilePath -> FilePath

# LSP Range manipulation functions

normalize :: Range -> Range #

Extend to the line below and above to replace newline character.

    >>> normalize (Range (Position 5 5) (Position 5 10))
    Range (Position 5 0) (Position 6 0)

extendNextLine :: Range -> Range #

Extend `Range` to the start of the next line.

    >>> extendNextLine (Range (Position 5 5) (Position 5 10))
    Range (Position 5 5) (Position 6 0)

extendLineStart :: Range -> Range #

Extend `Range` to the start of the current line.

    >>> extendLineStart (Range (Position 5 5) (Position 5 10))
    Range (Position 5 0) (Position 5 10)

extendToFullLines :: Range -> Range #

Extend `Range` to include the start of the first line and start of the next line of the last line.

Caveat: It always extend the last line to the beginning of next line, even when the last position is at column 0. This is to keep the compatibility with the implementation of old function `extractRange`.

    >>> extendToFullLines (Range (Position 5 5) (Position 5 10))
    Range (Position 5 0) (Position 6 0)

    >>> extendToFullLines (Range (Position 5 5) (Position 7 2))
    Range (Position 5 0) (Position 8 0)

    >>> extendToFullLines (Range (Position 5 5) (Position 7 0))
    Range (Position 5 0) (Position 8 0)

data WithDeletions #

Constructors

IncludeDeletions |
SkipDeletions |

#### Instances

Instances details

Eq WithDeletions # |
Instance details Defined in Ide.PluginUtils Methods (==) :: WithDeletions -> WithDeletions -> Bool # (/=) :: WithDeletions -> WithDeletions -> Bool #

getProcessID :: IO Int #

makeDiffTextEdit :: Text -> Text -> [TextEdit] #

makeDiffTextEditAdditive :: Text -> Text -> [TextEdit] #

diffText :: ClientCapabilities -> (VersionedTextDocumentIdentifier, Text) -> Text -> WithDeletions -> WorkspaceEdit #

Generate a `WorkspaceEdit` value from a pair of source Text

diffText' :: Bool -> (VersionedTextDocumentIdentifier, Text) -> Text -> WithDeletions -> WorkspaceEdit #

A pure version of `diffText` for testing

pluginDescToIdePlugins :: [PluginDescriptor ideState] -> IdePlugins ideState #

idePluginsToPluginDesc :: IdePlugins ideState -> [PluginDescriptor ideState] #

getClientConfig :: MonadLsp Config m => m Config #

Returns the current client configuration. It is not wise to permanently cache the returned value of this function, as clients can at runtime change their configuration.

getPluginConfig :: MonadLsp Config m => PluginDescriptor c -> m PluginConfig #

Returns the current plugin configuration. It is not wise to permanently cache the returned value of this function, as clients can change their configuration at runtime.

configForPlugin :: Config -> PluginDescriptor c -> PluginConfig #

Lookup the current config for a plugin

handlesRequest #

Arguments

:: PluginMethod k m |
=> SMethod m | Method type.
-> MessageParams m | Whether a plugin is enabled might depend on the message parameters e.g. `pluginFileType` specifies which file extensions a plugin is allowed to handle
-> PluginDescriptor c | Contains meta information such as PluginId and which file types this plugin is able to handle.
-> Config | Generic config description, expected to contain `PluginConfig` configuration for this plugin
-> HandleRequestResult | Is this plugin enabled and allowed to respond to the given request with the given parameters?

Parse the configuration to check if this plugin is globally enabled, and if the feature which handles this method is enabled. Perform sanity checks on the message to see whether the plugin handles this message in particular. This class is only used to determine whether a plugin can handle a specific request. Commands and rules do not use this logic to determine whether or not they are run.

A common reason why a plugin won't handle a request even though it is enabled: * The plugin cannot handle requests associated with the specific URI * Since the implementation of cabal plugins HLS knows plugins specific to Haskell and specific to Cabal file descriptions * The resolve request is not routed to that specific plugin. Each resolve request needs to be routed to only one plugin.

Strictly speaking, we are conflating two concepts here: * Dynamically enabled (e.g. on a per-message basis) * Statically enabled (e.g. by configuration in the lsp-client) * Strictly speaking, this might also change dynamically

But there is no use to split it up into two different methods for now.

extractTextInRange :: Range -> Text -> Text #

Extracts exact matching text in the range.

fullRange :: Text -> Range #

Gets the range that covers the entire text

mkLspCommand :: PluginId -> CommandId -> Text -> Maybe [Value] -> Command #

mkLspCmdId :: Text -> PluginId -> CommandId -> Text #

getPid :: IO Text #

Get the operating system process id for the running server instance. This should be the same for the lifetime of the instance, and different from that of any other currently running instance.

allLspCmdIds :: Text -> [(PluginId, [PluginCommand ideState])] -> [Text] #

allLspCmdIds' :: Text -> IdePlugins ideState -> [Text] #

installSigUsr1Handler :: IO () -> IO () #

subRange :: Range -> Range -> Bool #

positionInRange :: Position -> Range -> Bool #

usePropertyLsp :: forall (s :: Symbol) (k :: PropertyKey) (t :: PropertyType) (r :: [PropertyKey]) m c. (HasProperty s k t r, MonadLsp Config m) => KeyNameProxy s -> PluginDescriptor c -> Properties r -> m (ToHsType t) #

Returns the value of a property defined by the current plugin.

# Escape

unescape :: Text -> Text #

Unescape printable escape sequences within double quotes. This is useful if you have to call `show` indirectly, and it escapes some characters which you would prefer to display as is.

# toAbsolute

toAbsolute :: FilePath -> FilePath -> FilePath #

toAbsolute use `toAbsolute` to state our intention that we are actually make a path absolute the first argument should be the root directory the second argument should be the relative path