Skip to content

ca: Allow to enable/disable ToC code action #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Marksman/Config.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ type Config =

static member Default = { caTocEnable = Some true }

member this.CaTocEnable() =
this.caTocEnable
|> Option.orElse (Config.Default.caTocEnable)
|> Option.get

let private configOfTable (table: TomlTable) : LookupResult<Config> =
monad {
let! caTocEnable = getFromTableOpt<bool> table [] [ "code_action"; "toc"; "enable" ]
Expand Down
35 changes: 21 additions & 14 deletions Marksman/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -801,20 +801,27 @@ type MarksmanServer(client: MarksmanClient) =
Disabled = None
Edit = Some edit }

let tocAction =
State.tryFindDoc docPath state
|> Option.bind (CodeActions.tableOfContents opts.Range opts.Context)
|> Option.toArray
|> Array.map (fun ca ->
let wsEdit =
(CodeActions.documentEdit ca.edit ca.newText opts.TextDocument.Uri)

codeAction ca.name wsEdit)

let codeActions: TextDocumentCodeActionResult =
tocAction |> Array.map U2.Second

Mutation.output (LspResult.success (Some codeActions))
match State.tryFindFolderAndDoc docPath state with
| None -> Mutation.output (LspResult.success None)
| Some (folder, doc) ->
let config = Folder.configOrDefault folder

let tocAction =
if config.CaTocEnable() then
CodeActions.tableOfContents opts.Range opts.Context doc
|> Option.toArray
|> Array.map (fun ca ->
let wsEdit =
(CodeActions.documentEdit ca.edit ca.newText opts.TextDocument.Uri)

codeAction ca.name wsEdit)
else
[||]

let codeActions: TextDocumentCodeActionResult =
tocAction |> Array.map U2.Second

Mutation.output (LspResult.success (Some codeActions))


override this.TextDocumentRename(pars) =
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ for wiki-links to detect broken references and duplicate/ambiguous headings.

**NOTE**: If you're on MacOS and are getting a popup about:

> “marksman” can’t be opened because Apple cannot check it for malicious software
> “marksman” can’t be opened because Apple cannot check it for malicious software...

Then you can run the following command to bypass it and let Mac know that it's
fine.
fine:

```sh
xattr -d com.apple.quarantine ~/bin/marksman
xattr -d com.apple.quarantine <path-to-marksman-bin>
```

### Option 2: build from source
Expand Down Expand Up @@ -119,7 +119,7 @@ generally most features should work equaly in all editors.
- **Rename refactor for headings and reference links**:
![Rename Refactor](assets/readme/gifs/rename.gif)

## Features and plans
## Features

✅ - done; 🗓 - planned.

Expand Down Expand Up @@ -147,8 +147,11 @@ See [Configuration](docs/configuration.md) docs for more details.

### Code actions

**Table of Contents**: Marksman has a code action to create and update a table
of contents of a document.
Code actions usually can be enabled/disabled via a configuration option. See
[configuration](#configuration) for more details.

#### Table of Contents
Marksman has a code action to create and update a table of contents of a document.

![Table of Contents](assets/readme/gifs/toc.gif)

Expand Down