Skip to content

Commit 95df285

Browse files
committed
feat: help fixes, panic fixes
1 parent 5d3977b commit 95df285

File tree

4 files changed

+123
-69
lines changed

4 files changed

+123
-69
lines changed

lang/constructs/worldgen/density_functions/YClampedGradientFn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
func init() {
1515
traversal.RegisterHelp[*grammar.DensityFn_YClampedGradientContext](
1616
func(construct traversal.Construct, symbol traversal.Symbol, location traversal.TextLocation) *string {
17-
out := "Creates a gradient that runs from a specified y-coordinate to another.<br/>.`Top(int)` and `.Max(float)` define the upper elevation and value, while `.Bottom(int)` and `.Min(float)` define the lower elevation and value.<br/>Example: `YClampedGradient(densityFn).Top(100).Max(0).Bottom(-100).Max(1)"
17+
out := "Creates a gradient that runs from a specified y-coordinate to another.<br/>.`Top(int)` and `.Max(float)` define the upper elevation and value, while `.Bottom(int)` and `.Min(float)` define the lower elevation and value.<br/>Example: `YClampedGradient().Top(100).Max(0).Bottom(-100).Max(1)`"
1818
return &out
1919
},
2020
)

lang/constructs/worldgen/noise_router/NoiseRouter.go

Lines changed: 68 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,80 +11,84 @@ import (
1111
)
1212

1313
func init() {
14-
traversal.Register(func(blockCtx *grammar.NoiseRouterBlockContext, currentNamespace string, scope *traversal.Scope) traversal.Construct {
15-
for _, child := range blockCtx.GetChildren() {
16-
if rule, ok := child.(antlr.ParserRuleContext); ok {
17-
traversal.ConstructRegistry.Construct(rule, currentNamespace, scope)
14+
traversal.Register(func(blockCtx *grammar.NoiseRouterBlockContext, currentNamespace string, scope *traversal.Scope) traversal.Construct {
15+
for _, child := range blockCtx.GetChildren() {
16+
if rule, ok := child.(antlr.ParserRuleContext); ok {
17+
traversal.ConstructRegistry.Construct(rule, currentNamespace, scope)
18+
}
1819
}
19-
}
20-
return nil
21-
})
20+
return nil
21+
})
2222
traversal.Register(func(declaration *grammar.NoiseRouterDeclarationContext, currentNamespace string, scope *traversal.Scope) traversal.Construct {
2323

24-
routerDef := declaration.NoiseRouter()
25-
if routerDef == nil {
26-
scope.DiagnoseSemanticError("Missing noise router definition", declaration)
27-
return nil
28-
}
24+
routerDef := declaration.NoiseRouter()
25+
if routerDef == nil {
26+
scope.DiagnoseSemanticError("Missing noise router definition", declaration)
27+
return nil
28+
}
2929

30-
s := traversal.ProcessDeclaration(declaration.Declare(), routerDef, scope, currentNamespace, "NoiseRouter")
31-
if s == nil {
32-
return nil
33-
}
34-
return s.GetValue()
35-
})
30+
s := traversal.ProcessDeclaration(declaration.Declare(), routerDef, scope, currentNamespace, "NoiseRouter")
31+
if s == nil {
32+
return nil
33+
}
34+
return s.GetValue()
35+
})
3636

3737
traversal.Register(func(router *grammar.NoiseRouterContext, currentNamespace string, scope *traversal.Scope) traversal.Construct {
3838
out := &NoiseRouter{}
3939

40-
finalDensityPresent := false
41-
for _, builderCtx := range router.AllNoiseRouter_Builder() {
42-
builderKindCtx := builderCtx.GetChild(1)
43-
if builderKindCtx == nil {
44-
scope.DiagnoseSemanticError("Missing builder", router)
45-
continue
46-
}
47-
builderKind := builderKindCtx.(antlr.TerminalNode).GetText()
48-
49-
value := traversal.ConstructRegistry.Construct(builderCtx.DensityFn(), currentNamespace, scope)
50-
switch NoiseRouterBuilderKind(builderKind) {
51-
case FinalDensity:
52-
finalDensityPresent = true
53-
out.FinalDensity = value
54-
case Barrier:
55-
out.Barrier = value
56-
case FluidLevelFloodedness:
57-
out.FluidLevelFloodedness = value
58-
case FluidLevelSpread:
59-
out.FluidLevelSpread = value
60-
case Lava:
61-
out.Lava = value
62-
case VeinToggle:
63-
out.VeinToggle = value
64-
case VeinRidged:
65-
out.VeinRidged = value
66-
case VeinGap:
67-
out.VeinGap = value
68-
case Temperature:
69-
out.Temperature = value
70-
case Vegetation:
71-
out.Vegetation = value
72-
case Continents:
73-
out.Continents = value
74-
case Erosion:
75-
out.Erosion = value
76-
case Depth:
77-
out.Depth = value
78-
case Ridges:
79-
out.Ridges = value
80-
}
40+
finalDensityPresent := false
41+
for _, builderCtx := range router.AllNoiseRouter_Builder() {
42+
if builderCtx.GetChildCount() < 2 {
43+
// TODO: Better diagnosis
44+
continue
8145
}
82-
83-
if !finalDensityPresent {
84-
scope.DiagnoseSemanticError("Missing required FinalDensity()", router)
46+
builderKindCtx := builderCtx.GetChild(1)
47+
if builderKindCtx == nil {
48+
// TODO: Better diagnosis
49+
continue
50+
}
51+
builderKind := builderKindCtx.(antlr.TerminalNode).GetText()
52+
53+
value := traversal.ConstructRegistry.Construct(builderCtx.DensityFn(), currentNamespace, scope)
54+
switch NoiseRouterBuilderKind(builderKind) {
55+
case FinalDensity:
56+
finalDensityPresent = true
57+
out.FinalDensity = value
58+
case Barrier:
59+
out.Barrier = value
60+
case FluidLevelFloodedness:
61+
out.FluidLevelFloodedness = value
62+
case FluidLevelSpread:
63+
out.FluidLevelSpread = value
64+
case Lava:
65+
out.Lava = value
66+
case VeinToggle:
67+
out.VeinToggle = value
68+
case VeinRidged:
69+
out.VeinRidged = value
70+
case VeinGap:
71+
out.VeinGap = value
72+
case Temperature:
73+
out.Temperature = value
74+
case Vegetation:
75+
out.Vegetation = value
76+
case Continents:
77+
out.Continents = value
78+
case Erosion:
79+
out.Erosion = value
80+
case Depth:
81+
out.Depth = value
82+
case Ridges:
83+
out.Ridges = value
8584
}
86-
return out
87-
})
85+
}
86+
87+
if !finalDensityPresent {
88+
scope.DiagnoseSemanticError("Missing required FinalDensity()", router)
89+
}
90+
return out
91+
})
8892
}
8993

9094
type NoiseRouter struct {

lang/constructs/worldgen/noise_settings/NoiseSettings.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func getBuilder() *builder_chain.BuilderChain[NoiseSettings] {
4747
if state == nil {
4848
state = traversal.ConstructRegistry.Construct(ctx.ResourceReference(), namespace, scope)
4949
if state == nil {
50+
scope.DiagnoseSemanticWarning("Could not identify block state", ctx)
5051
return
5152
}
5253
target.DefaultBlock = block_states.BlockStateRef(*state.(*traversal.Reference))
@@ -59,6 +60,12 @@ func getBuilder() *builder_chain.BuilderChain[NoiseSettings] {
5960
func(ctx *grammar.Builder_DefaultFluidContext, target *NoiseSettings, scope *traversal.Scope, namespace string) {
6061
state := traversal.ConstructRegistry.Construct(ctx.BlockState(), namespace, scope)
6162
if state == nil {
63+
state = traversal.ConstructRegistry.Construct(ctx.ResourceReference(), namespace, scope)
64+
if state == nil {
65+
scope.DiagnoseSemanticWarning("Could not identify block state", ctx)
66+
return
67+
}
68+
target.DefaultFluid = block_states.BlockStateRef(*state.(*traversal.Reference))
6269
return
6370
}
6471
target.DefaultFluid = state
@@ -71,21 +78,29 @@ func getBuilder() *builder_chain.BuilderChain[NoiseSettings] {
7178
),
7279
builder_chain.Build(
7380
func(ctx *grammar.Builder_HeightContext, target *NoiseSettings, scope *traversal.Scope, namespace string) {
74-
builder_chain.Builder_GetInt(ctx, func(v int) { target.Height = v }, scope, "MinY")
81+
builder_chain.Builder_GetInt(ctx, func(v int) { target.Height = v }, scope, "Height")
7582
},
7683
),
7784
builder_chain.Build(
7885
func(ctx *grammar.Builder_NoiseRouterContext, target *NoiseSettings, scope *traversal.Scope, namespace string) {
79-
if sym, _ := traversal.ExtractInlineConstruct(ctx.NoiseRouter(), namespace, scope, "NoiseRouter"); sym != nil {
86+
router := ctx.NoiseRouter()
87+
if router == nil {
88+
return
89+
}
90+
if sym, _ := traversal.ExtractInlineConstruct(router, namespace, scope, "NoiseRouter"); sym != nil {
8091
target.NoiseRouter = sym.GetValue()
8192
}
8293
},
8394
),
8495
builder_chain.Build(
8596
func(ctx *grammar.Builder_SurfaceRuleContext, target *NoiseSettings, scope *traversal.Scope, namespace string) {
97+
rule := ctx.SurfaceRule()
98+
if rule == nil {
99+
return
100+
}
86101
if sym, _ :=
87-
traversal.ExtractInlineConstruct(ctx.SurfaceRule(), namespace, scope, "SurfaceRule"); sym != nil {
88-
target.NoiseRouter = sym.GetValue()
102+
traversal.ExtractInlineConstruct(rule, namespace, scope, "SurfaceRule"); sym != nil {
103+
target.SurfaceRule = sym.GetValue()
89104
}
90105
},
91106
),
@@ -233,6 +248,8 @@ func (n *NoiseSettings) MarshalJSON() ([]byte, error) {
233248
DefaultBlock traversal.Construct `json:"default_block"`
234249
DefaultFluid traversal.Construct `json:"default_fluid"`
235250
Noise interface{} `json:"noise"`
251+
NoiseRouter traversal.Construct `json:"noise_router"`
252+
SurfaceRule traversal.Construct `json:"surface_rule"`
236253
}{
237254
SeaLevel: n.SeaLevel,
238255
CreaturesEnabled: n.DisableCreatures,
@@ -242,6 +259,8 @@ func (n *NoiseSettings) MarshalJSON() ([]byte, error) {
242259
DefaultBlock: n.DefaultBlock,
243260
DefaultFluid: n.DefaultFluid,
244261
Noise: noise,
262+
NoiseRouter: n.NoiseRouter,
263+
SurfaceRule: n.SurfaceRule,
245264
}, "", " ")
246265
}
247266

lsp/LanguageServer.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func init() {
4646
TextDocumentDocumentSymbol: ls.DocumentSymbols,
4747
TextDocumentFoldingRange: ls.TextDocumentFoldingRange,
4848
TextDocumentHover: ls.TextDocumentHover,
49+
TextDocumentCompletion: ls.TextDocumentCompletion,
4950
}
5051
}
5152

@@ -163,3 +164,33 @@ func (ls *LanguageServer) TextDocumentHover(context *glsp.Context, params *proto
163164

164165
return nil, nil
165166
}
167+
168+
// Returns: []CompletionItem | CompletionList | nil
169+
func (ls *LanguageServer) TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) {
170+
out := protocol.CompletionList{
171+
IsIncomplete: false,
172+
Items: make([]protocol.CompletionItem, 0),
173+
}
174+
175+
out.Items = append(out.Items, protocol.CompletionItem{
176+
Label: "This is a completion item.",
177+
Kind: nil,
178+
Tags: nil,
179+
Detail: nil,
180+
Documentation: nil,
181+
Deprecated: nil,
182+
Preselect: nil,
183+
SortText: nil,
184+
FilterText: nil,
185+
InsertText: nil,
186+
InsertTextFormat: nil,
187+
InsertTextMode: nil,
188+
TextEdit: nil,
189+
AdditionalTextEdits: nil,
190+
CommitCharacters: nil,
191+
Command: nil,
192+
Data: nil,
193+
})
194+
195+
return out, nil
196+
}

0 commit comments

Comments
 (0)