commercialhaskell / stack-ide

Stack-based JSON interface to ide-backend
98 stars 23 forks source link

Add autocompletion #3

Closed Codas closed 9 years ago

Codas commented 9 years ago

This PR adds autocompletion support to ide-backend-client.

Example call to the autocompletion API:

{
  "request": "getAutocompletion",
  "module": "IdeSession.Client",
  "autocomplete": {
    "filePath": "src/IdeSession/Client.hs",
    "prefix": "fr"
  }
}

Example response

{
  "response": "getAutocompletion",
  "completions": [
    {
      "name": "fromEnum",
      "definedIn": "GHC.Enum"
    },
    // ...
    {
      "name": "fromJSON",
      "type": "JsonGrammar-1.0.1:Language.JsonGrammar.Grammar.Json a => aeson-0.8.0.2:Data.Aeson.Types.Internal.Value -> Either String a",
      "definedIn": "IdeSession.Client.JsonAPI"
    },
    {
      "name": "fromRational",
      "definedIn": "GHC.Real"
    }
  ]
}

Autocompletion with qualified imports is also supported. Request:

{
  "request": "getAutocompletion",
  "module": "IdeSession.Client",
  "autocomplete": {
    "filePath": "src/IdeSession/Client.hs",
    "prefix": "Text.Lazy.fold"
  }
}

Response:

{
  "response": "getAutocompletion",
  "completions": [
    {
      "qualifier": "Text.Lazy.",
      "name": "foldl",
      "definedIn": "Data.Text.Lazy"
    },
    // ...
    {
      "qualifier": "Text.Lazy.",
      "name": "foldlChunks",
      "definedIn": "Data.Text.Internal.Lazy"
    }
  ]
}

Type information is only available for candidates that are used or defined in the current module. (Or whenever ide-backend supplies type information for autocompletion candidates)

chrisdone commented 9 years ago

Awesome!