Skip to content

Commit

Permalink
Add bracket indentation semantics to (* *)
Browse files Browse the repository at this point in the history
Background: ionide/ionide-fsgrammar#209

This comes from a comment regarding a pull request that I made on the
ionide-fsgrammar repository, which removes the `(* *)` bracket pair
from the "brackets" field of language-configuration.json. One issue
with doing this is that we lose the bracket-like indentation that
VSCode provides by default for all bracket pairs.

In other words, when I hit Enter in the following configuration,
cursor location represented by the white block:

    (*█*)

It should indent the cursor and then put the `*)` on the next line
with the same indentation level as the `(*` as follows:

    (*
        █
    *)

when I hit Enter with an unaccompanied `(*`:

    (*█

It should simply indent as follows:

    (*
        █

Lastly, an unaccompanied `*)` should outdent. That is,

        *)█

should become

    *)█
  • Loading branch information
mbottini committed Apr 1, 2024
1 parent b0d2ebe commit 9c9031e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Components/LanguageConfiguration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ module LanguageConfiguration =
jsOptions<IndentationRule> (fun o ->
o.increaseIndentPattern <-
Regex(
"""^(\s*(module|type|let|static member|member)\b.*=\s*)$|^(\s*(with get|and set)\b.*=.*)$|^(\s*(if|elif|then|else|static member|member)).*$"""
"""^(\s*(module|type|let|static member|member)\b.*=\s*)$|^(\s*(with get|and set)\b.*=.*)$|^(\s*(if|elif|then|else|static member|member|\(\*)).*$"""
)

o.decreaseIndentPattern <- Regex("""^(\s*(else|elif|and)).*$"""))
o.decreaseIndentPattern <- Regex("""^(\s*(else|elif|and|\*\))).*$"""))

let setLanguageConfiguration (triggerNotification: bool) =
// Config always setted
Expand All @@ -33,9 +33,7 @@ module LanguageConfiguration =
action.indentAction <- IndentAction.None
action.appendText <- Some "/// ")

rule.beforeText <- Regex("^\s*\/{3}.*$"))

|]
rule.beforeText <- Regex("^\s*\/{3}.*$")) |]
))

let activateSmartIndent = "FSharp.smartIndent" |> Configuration.get false
Expand Down

0 comments on commit 9c9031e

Please sign in to comment.