Skip to content

olsp can keep incorrect document src in its state because of encoding issues #934

@ulugbekna

Description

@ulugbekna

olsp sometimes formats code into illegal state, e.g., given file

let foo ~i ~j = i + j
let bar = 10
let y = foo ~i:5

let lst = []

let map = List.m

let map = List.m []

let map = List.m

olsp formats it to

let foo ~i ~j = i + j
let bar = 10
let y = foo ~i:5
let lst = []
let map = List.mlet map = List.m []
let map = List.m

trace (notice how ofmt says it's disabled but still formats code)

[Trace - 10:35:22 PM] Sending request 'textDocument/formatting - (374)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/ulugbek/code/merlin/tests/test-dirs/completion/application_context.t/application_context.ml"
    },
    "options": {
        "tabSize": 2,
        "insertSpaces": true
    }
}


File tests/test-dirs/completion/application_context.t/application_context.ml
Warning: Ocamlformat disabled because [--enable-outside-detected-project] is not set and no [.ocamlformat] was found within the project (root: ../merlin)
[Trace - 10:35:22 PM] Received response 'textDocument/formatting - (374)' in 3ms.
Result: [
    {
        "newText": "",
        "range": {
            "end": {
                "character": 0,
                "line": 4
            },
            "start": {
                "character": 0,
                "line": 3
            }
        }
    },
    {
        "newText": "",
        "range": {
            "end": {
                "character": 0,
                "line": 10
            },
            "start": {
                "character": 0,
                "line": 5
            }
        }
    },
    {
        "newText": "let map = List.m []\nlet map = List.m\n",
        "range": {
            "end": {
                "character": 0,
                "line": 11
            },
            "start": {
                "character": 0,
                "line": 11
            }
        }
    }
]

ofmt also sometimes gets stuck and can't get format; restarting olsp enables it to format again.


this must be some ofmt-rpc issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions