<commit_before># Protocol

Encode the following JSON formats into a single line string and pass them to
psc-ide's stdin. You can then read the result from psc-ide's stdout as a single
line. The result needs to be unwrapped from the "wrapper" which separates success
from failure. This wrapper is described at the end of this document.

## Command:
### Load
The `load` command "loads" the requested modules into the server
for completion and type info.

**Params:**
 - `modules :: (optional) [ModuleName]`: A list of modules to load.
  psc-ide-server will try to parse all the declarations in these modules
 - `dependencies :: (optional) [ModuleName]`: A list of modules to load 
  including their dependencies. In contrast to the `module` field, all the
  imports in these Modules will also be loaded.

```json
{
  "command": "load",
  "params": {
    "modules": (optional)["Module.Name1", "Module.Name2"],
    "dependencies": (optional)["Module.Name3"]
  }
}
```

**Result:**

The Load Command returns a string.

### Type
The `type` command looks up the type for a given identifier.

**Params:**
 - `search :: String`: The identifier to look for. Only matches on equality.
 - `filters :: [Filter]`: These filters will be applied before looking for the
  identifier. These filters get combined with *AND*, so a candidate must match *ALL*
  of them to be eligible.
```json
{
  "command": "type",
  "params": {
    "search": "filterM",
    "filters": [Filter]
  }
}
```

**Result:**
The possible types are returned in the same format as completions

### Complete
The `complete` command looks up possible completions/corrections.

**Params**:
 - `filters :: [Filter]`: The same as for the `type` command. A candidate must match
  all filters.
 - `matcher :: (optional) Matcher`: The strategy used for matching candidates after filtering.
  Results are scored internally and will be returned in the descending order where
  the nth element is better then the n+1-th.

  If no matcher is given every candidate, that passes the filters, is returned in no 
  particular order.
```json
{
  "command": "complete",
  "params": {
    "filters": [Filter],
    "matcher": (optional) Matcher
  }
}
```

**Result:**

The following format is returned as the Result:

```json
[
  {
  "module": "Data.Array",
  "identifier": "filter",
  "type": "forall a. (a -> Boolean) -> Array a -> Array a"
  }
]
```

### Pursuit
The `pursuit` command looks up the packages/completions for a given identifier from Pursuit.

**Params:**
 - `query :: String`: With `type: "package"` this should be a module name. With
   `type: "completion"` this can be any string to look up.
 - `type :: String`: Takes the following values:
   - `package`: Looks for packages that contain the given module name.
   - `completion` Looks for declarations for the query from Pursuit.

```json
{
  "command": "pursuit",
  "params": {
    "query": "Data.Array",
    "type": "package"
  }
}
```

**Result:**

`package` returns:

```json
[
  {
  "module": "Module1.Name",
  "package": "purescript-packagename"
  }
]
```

`completion` returns:

```json
[
  {
  "module": "Data.Array",
  "identifier": "filter",
  "type": "forall a. (a -> Boolean) -> Array a -> Array a",
  "package": "purescript-arrays"
  }
]
```

### List/Cwd/Quit
`list` returns all loaded modules.

`cwd` returns the working directory of the server(should be your project root).

`quit` quits the server.

```json
{
  "command": "list|cwd|quit"
}
```

**Result:**
These commands return strings.

## Filter:

### Exact filter
The Exact filter only keeps identifiers that are equal to the search term.

```json
{
  "filter": "exact",
  "params": {
    "search": "filterM"
  }
}
```<commit_msg>Document new list import protocol<commit_after># Protocol

Encode the following JSON formats into a single line string and pass them to
psc-ide's stdin. You can then read the result from psc-ide's stdout as a single
line. The result needs to be unwrapped from the "wrapper" which separates success
from failure. This wrapper is described at the end of this document.

## Command:
### Load
The `load` command "loads" the requested modules into the server
for completion and type info.

**Params:**
 - `modules :: (optional) [ModuleName]`: A list of modules to load.
  psc-ide-server will try to parse all the declarations in these modules
 - `dependencies :: (optional) [ModuleName]`: A list of modules to load 
  including their dependencies. In contrast to the `module` field, all the
  imports in these Modules will also be loaded.

```json
{
  "command": "load",
  "params": {
    "modules": (optional)["Module.Name1", "Module.Name2"],
    "dependencies": (optional)["Module.Name3"]
  }
}
```

**Result:**

The Load Command returns a string.

### Type
The `type` command looks up the type for a given identifier.

**Params:**
 - `search :: String`: The identifier to look for. Only matches on equality.
 - `filters :: [Filter]`: These filters will be applied before looking for the
  identifier. These filters get combined with *AND*, so a candidate must match *ALL*
  of them to be eligible.
```json
{
  "command": "type",
  "params": {
    "search": "filterM",
    "filters": [Filter]
  }
}
```

**Result:**
The possible types are returned in the same format as completions

### Complete
The `complete` command looks up possible completions/corrections.

**Params**:
 - `filters :: [Filter]`: The same as for the `type` command. A candidate must match
  all filters.
 - `matcher :: (optional) Matcher`: The strategy used for matching candidates after filtering.
  Results are scored internally and will be returned in the descending order where
  the nth element is better then the n+1-th.

  If no matcher is given every candidate, that passes the filters, is returned in no 
  particular order.
```json
{
  "command": "complete",
  "params": {
    "filters": [Filter],
    "matcher": (optional) Matcher
  }
}
```

**Result:**

The following format is returned as the Result:

```json
[
  {
  "module": "Data.Array",
  "identifier": "filter",
  "type": "forall a. (a -> Boolean) -> Array a -> Array a"
  }
]
```

### Pursuit
The `pursuit` command looks up the packages/completions for a given identifier from Pursuit.

**Params:**
 - `query :: String`: With `type: "package"` this should be a module name. With
   `type: "completion"` this can be any string to look up.
 - `type :: String`: Takes the following values:
   - `package`: Looks for packages that contain the given module name.
   - `completion` Looks for declarations for the query from Pursuit.

```json
{
  "command": "pursuit",
  "params": {
    "query": "Data.Array",
    "type": "package"
  }
}
```

**Result:**

`package` returns:

```json
[
  {
  "module": "Module1.Name",
  "package": "purescript-packagename"
  }
]
```

`completion` returns:

```json
[
  {
  "module": "Data.Array",
  "identifier": "filter",
  "type": "forall a. (a -> Boolean) -> Array a -> Array a",
  "package": "purescript-arrays"
  }
]
```

### List
#### Modules
`list` lists all loaded modules.

```json
{
  "command": "list",
  "params": {
    "type": "module"
  }
}
```

#### Response:
The list modules commands returns a list of strings.

#### Imports

The list commmand can also list the imports for a given file.

```json
{
  "command": "list",
  "params": {
    "type": "import",
    "file": "/home/kritzcreek/Documents/psc-ide/examples/Main.purs"
  }
}
```

#### Response:

The list import command returns a list of imports where imports are of the following form:

Implicit Import(`import Data.Array`):
```json
[
  {
  "module": "Data.Array",
  "importType": "implicit"
  }
]
```

Implicit qualified Import(`import qualified Data.Array as A`):
```json
[
  {
  "module": "Data.Array",
  "importType": "implicit",
  "qualifier": "A"
  }
]
```

Explicit Import(`import Data.Array (filter, filterM, join)`):
```json
[
  {
  "module": "Data.Array",
  "importType": "explicit",
  "identifiers": ["filter", "filterM", "join"]
  }
]
```

Hiding Import(`import Data.Array hiding (filter, filterM, join)`):
```json
[
  {
  "module": "Data.Array",
  "importType": "hiding",
  "identifiers": ["filter", "filterM", "join"]
  }
]
```
### Cwd/Quit
`cwd` returns the working directory of the server(should be your project root).

`quit` quits the server.

```json
{
  "command": "cwd|quit"
}
```

**Result:**
These commands return strings.

## Filter:

### Exact filter
The Exact filter only keeps identifiers that are equal to the search term.

```json
{
  "filter": "exact",
  "params": {
    "search": "filterM"
  }
}
```
{'fraction_non_alphanumeric': 0.14722351843210452, 'fraction_numerical': 0.0011665888940737283, 'mean_word_length': 3.8162921348314605, 'pattern_counts': {'":': 76, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7502076', 'n_tokens_mistral': 2761, 'n_tokens_neox': 2648, 'n_words': 1039}