Skip to content

Commit 8b9b1de

Browse files
authored
Merge pull request #4 from nimblebun/feature/loose-checking
add loose checking option for events and args
2 parents f0acb00 + af5a498 commit 8b9b1de

20 files changed

+135
-37
lines changed

config/.tscrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
"maxMessageLineLength": {
44
"plain": 35,
55
"portrait": 28
6+
},
7+
8+
"looseChecking": {
9+
"events": false,
10+
"arguments": false
611
}
712
},
813

config/config_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ func TestUpdate(t *testing.T) {
223223
"setup": {
224224
"maxMessageLineLength": {
225225
"portrait": 30
226+
},
227+
228+
"looseChecking": {
229+
"arguments": true
226230
}
227231
},
228232
@@ -279,6 +283,14 @@ func TestUpdate(t *testing.T) {
279283
)
280284
}
281285

286+
if conf.Setup.LooseChecking.Arguments != true {
287+
t.Errorf(
288+
"config.Config#Update() -> Setup.LooseChecking.Arguments got %v, want %v",
289+
conf.Setup.LooseChecking.Arguments,
290+
true,
291+
)
292+
}
293+
282294
mim, found := conf.GetTSCDefinition("<MIM")
283295

284296
if !found {

config/config_types.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@ type MaxMessageLineLength struct {
1212
Portrait int `json:"portrait,omitempty"`
1313
}
1414

15+
// LooseChecking specifies whether the language server should perform checks on
16+
// event IDs and arguments in a loosely fashion. For more information, see:
17+
// https://docs.nimblebun.works/tscrc-json#setup-loose-checking
18+
type LooseChecking struct {
19+
Events bool `json:"events,omitempty"`
20+
Arguments bool `json:"arguments,omitempty"`
21+
}
22+
1523
// SetupConfig contains options for the TSC diagnostics
1624
type SetupConfig struct {
17-
MaxMessageLineLength `json:"maxMessageLineLength,omitempty"`
25+
MaxMessageLineLength MaxMessageLineLength `json:"maxMessageLineLength,omitempty"`
26+
LooseChecking LooseChecking `json:"looseChecking,omitempty"`
1827
}
1928

2029
// TSCDefinition is the definition of a TSC command

config/default.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ var DefaultConfig = []byte(`{
1010
"maxMessageLineLength": {
1111
"plain": 35,
1212
"portrait": 28
13+
},
14+
15+
"looseChecking": {
16+
"events": false,
17+
"arguments": false
1318
}
1419
},
1520

langserver/handlers/document_symbol.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ func (mh *MethodHandler) TextDocumentSymbol(ctx context.Context, req *jrpc2.Requ
2626
return symbols, err
2727
}
2828

29+
config, err := lsctx.Config(ctx)
30+
2931
handler := filehandler.FromDocumentURI(params.TextDocument.URI)
3032

3133
path, err := handler.FullPath()
@@ -46,7 +48,7 @@ func (mh *MethodHandler) TextDocumentSymbol(ctx context.Context, req *jrpc2.Requ
4648
Text: contents,
4749
}
4850

49-
symbols = tsc.GetEventSymbols(contents, doc)
51+
symbols = tsc.GetEventSymbols(contents, doc, config)
5052

5153
return symbols, nil
5254
}

langserver/handlers/folding.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ func (mh *MethodHandler) TextDocumentFoldingRange(ctx context.Context, req *jrpc
2424
return []lsp.FoldingRange{}, err
2525
}
2626

27+
config, err := lsctx.Config(ctx)
28+
if err != nil {
29+
return []lsp.FoldingRange{}, err
30+
}
31+
2732
handler := filehandler.FromDocumentURI(params.TextDocument.URI)
2833
path, err := handler.FullPath()
2934
if err != nil {
@@ -41,6 +46,6 @@ func (mh *MethodHandler) TextDocumentFoldingRange(ctx context.Context, req *jrpc
4146
Text: string(contents),
4247
}
4348

44-
ranges := tsc.GetFoldingRanges(doc)
49+
ranges := tsc.GetFoldingRanges(doc, config)
4550
return ranges, nil
4651
}

langserver/handlers/service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func (service *Service) Assigner() (jrpc2.Assigner, error) {
151151
}
152152

153153
ctx = lsctx.WithFileSystem(ctx, fs)
154+
ctx = lsctx.WithConfig(ctx, &conf)
154155

155156
return handle(ctx, req, mh.TextDocumentSymbol)
156157
},
@@ -162,6 +163,7 @@ func (service *Service) Assigner() (jrpc2.Assigner, error) {
162163
}
163164

164165
ctx = lsctx.WithFileSystem(ctx, fs)
166+
ctx = lsctx.WithConfig(ctx, &conf)
165167

166168
return handle(ctx, req, mh.TextDocumentFoldingRange)
167169
},

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func main() {
1212
app := cli.NewApp()
1313
app.Name = "tsc-ls"
1414
app.Usage = "language Server for the TSC scripting language"
15-
app.Version = "0.1.4"
15+
app.Version = "0.1.5"
1616

1717
app.Commands = []*cli.Command{
1818
{

tsc/event_symbols.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ import (
44
"regexp"
55

66
"pkg.nimblebun.works/go-lsp"
7+
"pkg.nimblebun.works/tsc-language-server/config"
78
"pkg.nimblebun.works/tsc-language-server/langserver/textdocument"
89
)
910

1011
// GetEventSymbols will return a list of events as LSP-compatible symbols.
11-
func GetEventSymbols(text string, textDocumentItem lsp.TextDocumentItem) []lsp.DocumentSymbol {
12+
func GetEventSymbols(text string, textDocumentItem lsp.TextDocumentItem, conf *config.Config) []lsp.DocumentSymbol {
1213
document := textdocument.From(textDocumentItem)
1314

1415
// this will match #0000 until the end of the line
1516
re := regexp.MustCompile("#(?:[0-9]{4}).*")
1617

18+
if conf.Setup.LooseChecking.Events {
19+
// this will match #0000, #0ABC
20+
re = regexp.MustCompile("#(?:.{4})")
21+
}
22+
1723
symbols := make([]lsp.DocumentSymbol, 0)
1824

1925
for _, match := range re.FindAllStringIndex(text, -1) {

tsc/event_symbols_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
"pkg.nimblebun.works/go-lsp"
7+
"pkg.nimblebun.works/tsc-language-server/config"
78
"pkg.nimblebun.works/tsc-language-server/tsc"
89
)
910

@@ -23,7 +24,9 @@ func TestGetEventSymbols(t *testing.T) {
2324
Text: text,
2425
}
2526

26-
symbols := tsc.GetEventSymbols(text, document)
27+
conf := config.New()
28+
29+
symbols := tsc.GetEventSymbols(text, document, &conf)
2730

2831
t.Run("should return correct number of symbols", func(t *testing.T) {
2932
if len(symbols) != 5 {

0 commit comments

Comments
 (0)