all repos

clerk @ 8921805

missing tooling for ledger/hledger
5 files changed, 57 insertions(+), 18 deletions(-)
lsp: benchmark formatting and semantic tokens
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-08-13 13:40:52 +0300
Authored at: 2026-08-13 13:24:23 +0300
Change ID: wxkouysxmyrwvmzpxrzvnxuqllxnlnwy
Parent: 5e2eeb4
M internal/linter/linter_test.go
···
        63
        63
         

      
        64
        64
         func BenchmarkLinter(b *testing.B) {

      
        65
        65
         	ldr := journal.NewLoader()

      
        66
        
        -	rj, err := ldr.Resolve(

      
        67
        
        -		"../../journal/testdata/journals/actual-1ktxns-100accts.journal",

      
        68
        
        -	)

      
        
        66
        +	rj, err := ldr.Resolve("../../journal/testdata/journals/actual-1ktxns-100accts.journal")

      
        69
        67
         	if err != nil {

      
        70
        68
         		b.Fatalf("failed to load benchmark journal: %v", err)

      
        71
        69
         	}

      
M internal/lsp/diagnostics_test.go
···
        1
        1
         package lsp

      
        2
        2
         

      
        3
        3
         import (

      
        4
        
        -	"os"

      
        5
        4
         	"testing"

      
        6
        5
         

      
        7
        6
         	"go.lsp.dev/uri"

      
        8
        7
         )

      
        9
        8
         

      
        10
        9
         func BenchmarkDiagnostics(b *testing.B) {

      
        11
        
        -	path := "../../journal/testdata/journals/actual-1ktxns-100accts.journal"

      
        12
        
        -	src, err := os.ReadFile(path)

      
        13
        
        -	if err != nil {

      
        14
        
        -		b.Fatal(err)

      
        15
        
        -	}

      
        
        10
        +	content := openJouranl(b, "../../journal/testdata/journals/actual-1ktxns-100accts.journal")

      
        16
        11
         

      
        17
        12
         	srv := NewServer("test")

      
        18
        
        -	srv.server.openDoc(uri.URI("file:///test.journal"), string(src), 1, "journal")

      
        
        13
        +	srv.server.openDoc(uri.URI("file:///test.journal"), content, 1, "journal")

      
        19
        14
         

      
        20
        15
         	b.ReportAllocs()

      
        21
        16
         	b.ResetTimer()

      
A internal/lsp/textdocument_format_test.go
···
        
        1
        +package lsp

      
        
        2
        +

      
        
        3
        +import (

      
        
        4
        +	"testing"

      
        
        5
        +

      
        
        6
        +	"go.lsp.dev/protocol"

      
        
        7
        +	"go.lsp.dev/uri"

      
        
        8
        +)

      
        
        9
        +

      
        
        10
        +func BenchmarkFormatting(b *testing.B) {

      
        
        11
        +	content := openJouranl(b, "../../journal/testdata/journals/actual-1ktxns-100accts.journal")

      
        
        12
        +

      
        
        13
        +	srv := NewServer("test")

      
        
        14
        +	srv.server.openDoc(uri.URI("file:///test.journal"), content, 1, "journal")

      
        
        15
        +

      
        
        16
        +	params := &protocol.DocumentFormattingParams{

      
        
        17
        +		TextDocument: protocol.TextDocumentIdentifier{URI: uri.URI("file:///test.journal")},

      
        
        18
        +	}

      
        
        19
        +	// warm up: first request parses and prints

      
        
        20
        +	if _, err := srv.server.Formatting(b.Context(), params); err != nil {

      
        
        21
        +		b.Fatal(err)

      
        
        22
        +	}

      
        
        23
        +	b.ReportAllocs()

      
        
        24
        +	b.ResetTimer()

      
        
        25
        +	for b.Loop() {

      
        
        26
        +		if _, err := srv.server.Formatting(b.Context(), params); err != nil {

      
        
        27
        +			b.Fatal(err)

      
        
        28
        +		}

      
        
        29
        +	}

      
        
        30
        +}

      
M internal/lsp/textdocument_hover_test.go
···
        3
        3
         import (

      
        4
        4
         	"context"

      
        5
        5
         	"fmt"

      
        6
        
        -	"os"

      
        7
        6
         	"strings"

      
        8
        7
         	"testing"

      
        9
        8
         	"time"

      ···
        108
        107
         }

      
        109
        108
         

      
        110
        109
         func BenchmarkHover(b *testing.B) {

      
        111
        
        -	path := "../../journal/testdata/journals/actual-1ktxns-100accts.journal"

      
        112
        
        -	src, err := os.ReadFile(path)

      
        113
        
        -	if err != nil {

      
        114
        
        -		b.Fatal(err)

      
        115
        
        -	}

      
        116
        
        -	content := string(src)

      
        
        110
        +	content := openJouranl(b, "../../journal/testdata/journals/actual-1ktxns-100accts.journal")

      
        117
        111
         

      
        118
        112
         	// Path must match the open doc: hoverAt resolves the document by path.

      
        119
        
        -	an := analyzer.Build(journal.NewLoader().ResolveBytes("/test.journal", src))

      
        
        113
        +	an := analyzer.Build(journal.NewLoader().ResolveBytes("/test.journal", []byte(content)))

      
        120
        114
         

      
        121
        115
         	srv := NewServer("test")

      
        122
        116
         	srv.server.openDoc(uri.URI("file:///test.journal"), content, 1, "journal")

      
M internal/lsp/textdocument_semantic_test.go
···
        2
        2
         

      
        3
        3
         import (

      
        4
        4
         	"fmt"

      
        
        5
        +	"os"

      
        5
        6
         	"slices"

      
        6
        7
         	"strings"

      
        7
        8
         	"testing"

      ···
        218
        219
         	c := string(content)

      
        219
        220
         	return tokenizeForSemantics(c, parseJournalStr(c))

      
        220
        221
         }

      
        
        222
        +

      
        
        223
        +func BenchmarkSemanticTokens(b *testing.B) {

      
        
        224
        +	content := openJouranl(b, "../../journal/testdata/journals/actual-1ktxns-100accts.journal")

      
        
        225
        +

      
        
        226
        +	// Cold path: each iteration re-parses and re-encodes, as after an edit.

      
        
        227
        +	b.ReportAllocs()

      
        
        228
        +	b.ResetTimer()

      
        
        229
        +	for b.Loop() {

      
        
        230
        +		tokens := tokenizeForSemantics(content, parseJournalStr(content))

      
        
        231
        +		_ = encodeSemTokens(tokens)

      
        
        232
        +	}

      
        
        233
        +}

      
        
        234
        +

      
        
        235
        +func openJouranl(t testing.TB, path string) string {

      
        
        236
        +	t.Helper()

      
        
        237
        +	src, err := os.ReadFile(path)

      
        
        238
        +	if err != nil {

      
        
        239
        +		t.Fatal(err)

      
        
        240
        +	}

      
        
        241
        +	return string(src)

      
        
        242
        +}