Signature help, formatting, and a fix that writes a missing signature
- textDocument/signatureHelp: the function whose call the cursor is in, with the parameter that is being written marked. A definition shows its head as written; an import, a trait's method and a builtin show their type. It reads tokens as far as the cursor, so a call that is not closed has help. - textDocument/formatting: the whole text as bjo fmt lays it out. The server runs bjo -q fmt - on the buffer's text. - A quick fix at a function with no signature writes the one its body gives it, on a line above the definition (CheckDecl.observeMissingSignature, in the compiler). - The server says version 0.8.0. Needs the compiler at its commit "CheckDecl.observeMissingSignature". Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
d421ec9363
commit
ce426b94df
8 changed files with 695 additions and 11 deletions
67
Format.fs
Normal file
67
Format.fs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/// Formatting: the text of a file laid out as `bjo fmt` lays it out.
|
||||
///
|
||||
/// The formatter is `bjo/format.bjo`, a Bjolang program, so the server runs
|
||||
/// `bjo fmt -`, which reads the text on standard input and writes it laid out
|
||||
/// on standard output. What an editor gets is then what the command line
|
||||
/// writes.
|
||||
module BjolangLsp.Format
|
||||
|
||||
open System
|
||||
open System.Diagnostics
|
||||
open System.IO
|
||||
open System.Text
|
||||
|
||||
/// How long `bjo fmt -` may take. The first run after the compiler changed
|
||||
/// builds `bjo`, which is the longest that it takes.
|
||||
let private limit = TimeSpan.FromSeconds 120.0
|
||||
|
||||
/// `text` laid out, or why it cannot be: the text does not read, or `bjo` is
|
||||
/// not there or failed.
|
||||
///
|
||||
/// - `-q`: `bjo` then says nothing about a build of itself.
|
||||
/// - Standard output and standard error are read while the process runs, so
|
||||
/// that a long text does not fill a pipe and stop it.
|
||||
let source (text: string) : Result<string, string> =
|
||||
let launcher = Path.Combine(Bjolang.Paths.root, "bjo", "bjo")
|
||||
|
||||
if not (File.Exists launcher) then
|
||||
Error $"There is no bjo at %s{launcher}."
|
||||
else
|
||||
let info =
|
||||
ProcessStartInfo(
|
||||
launcher,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
StandardInputEncoding = UTF8Encoding false,
|
||||
StandardOutputEncoding = UTF8Encoding false,
|
||||
StandardErrorEncoding = UTF8Encoding false
|
||||
)
|
||||
|
||||
for argument in [ "-q"; "fmt"; "-" ] do
|
||||
info.ArgumentList.Add argument
|
||||
|
||||
try
|
||||
use p = Process.Start info
|
||||
let out = p.StandardOutput.ReadToEndAsync()
|
||||
let err = p.StandardError.ReadToEndAsync()
|
||||
p.StandardInput.Write text
|
||||
p.StandardInput.Close()
|
||||
|
||||
if not (p.WaitForExit(int limit.TotalMilliseconds)) then
|
||||
try
|
||||
p.Kill true
|
||||
with _ ->
|
||||
()
|
||||
|
||||
Error "bjo fmt did not end in time."
|
||||
elif p.ExitCode <> 0 then
|
||||
// `bjo fmt: line 3: a ( that is never closed`
|
||||
match err.Result.Trim() with
|
||||
| "" -> Error $"bjo fmt failed with exit code %d{p.ExitCode}."
|
||||
| why -> Error why
|
||||
else
|
||||
Ok out.Result
|
||||
with ex ->
|
||||
Error $"bjo fmt could not be run: %s{ex.Message}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue