Skip to content

Commit 5cb16b7

Browse files
committed
chore: coderabbit reviews
1 parent 3bc8879 commit 5cb16b7

14 files changed

Lines changed: 48 additions & 30 deletions

cmd/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func flushProject(root *lib.FileTreeLike, rootPath string) {
128128
func mkdirIfNotExists(dirPath string) error {
129129
_, err := fs.Stat(os.DirFS("."), dirPath)
130130
if err != nil {
131-
if strings.HasSuffix(err.Error(), "no such file or directory") {
131+
if os.IsNotExist(err) {
132132
err = os.MkdirAll(dirPath, 0755)
133133
if err != nil {
134134
return err

flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
packages.default = pkgs.buildGoModule {
6868
pname = "mms";
69-
version = "0.3.4";
69+
version = "0.4.0";
7070
src = ./.;
7171
vendorHash = null;
7272
# If you use vendoring, run `go mod vendor` and replace null with the hash
@@ -79,7 +79,7 @@
7979

8080
packages.wasm = pkgs.stdenvNoCC.mkDerivation {
8181
pname = "mms-wasm";
82-
version = "0.3.4";
82+
version = "0.4.0";
8383
src = ./.;
8484
buildInputs = [ pkgs.go ];
8585
buildPhase = ''

lang/DensityFn.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ var Cache = spec.NewFunctionSpec(
141141
}
142142

143143
kind := "minecraft:"
144-
switch v := spec.GetEnumNodeValue(n.Arguments[0]); *v {
144+
v := spec.GetEnumNodeValue(n.Arguments[0])
145+
if v == nil {
146+
return nil
147+
}
148+
switch *v {
145149
case "flat":
146150
kind += "flat_cache"
147151
case "2d":
@@ -397,6 +401,9 @@ func serializeRangeChoice(n spec.FunctionNode) any {
397401
}
398402

399403
func getDensityFn(n spec.FunctionNode) any {
404+
if len(n.Arguments) == 0 {
405+
return nil
406+
}
400407
switch arg := n.Arguments[0].(type) {
401408
case ast.Symbol:
402409
return arg.ToSerializable()

lang/Dimensions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func serializeDimensionType(n spec.FunctionNode) any {
5151
MonsterLightLevel float64 `json:"monster_light_level" mms_builder:"MonsterLightLevel"`
5252
MonsterLightLimit float64 `json:"monster_light_limit" mms_builder:"MonsterLightLimit"`
5353
LogicalHeight float64 `json:"logical_height" mms_builder:"LogicalHeight"`
54-
CloudHeight float64 `json:"cloud_height" mms_builder:"CLoudHeight"`
54+
CloudHeight float64 `json:"cloud_height" mms_builder:"CloudHeight"`
5555
MinY float64 `json:"min_y" mms_builder:"MinY"`
5656
Height float64 `json:"height" mms_builder:"Height"`
5757

lang/Noise.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ func GetInlinedNoiseRef(v ast.Node) string {
101101
}
102102
if val := spec.GetReferenceNodeValue(v, ast.SymbolNoise); !lib.IsNilInterface(val) {
103103
return *val
104-
} else if fn := v.(*spec.FunctionNode); fn != nil {
104+
} else if fn, ok := v.(*spec.FunctionNode); ok && fn != nil {
105105
return fn.Ref()
106106
}
107107
return ""
108108
}
109109

110110
func ExtractInlineNoiseSymbol(argIdx int) func(spec.FunctionNode) []ast.Symbol {
111111
return func(fn spec.FunctionNode) []ast.Symbol {
112-
if len(fn.Arguments) < 1 {
112+
if argIdx < 0 || argIdx >= len(fn.Arguments) {
113113
return nil
114114
}
115115
if inlineNoise, ok := fn.Arguments[argIdx].(*spec.FunctionNode); ok {

lang/SharedBuilders.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var SimpleFloatFn = spec.NewOverloadSpec(
1818
)
1919
var SimpleIntFn = spec.NewOverloadSpec(
2020
[]spec.ValueSpec{
21-
spec.NewNumberSpec(true),
21+
spec.NewNumberSpec(false),
2222
},
2323
nil,
2424
nil,

lang/ast/DiagnosticErrorListener.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func (l *DiagnosticsErrorListener) SyntaxError(recognizer antlr.Recognizer, offe
4747
}
4848

4949
loc := SourceLocation{
50-
Start: Location{Line: line, Column: startCol},
51-
Stop: Location{Line: line, Column: stopCol},
50+
Start: Location{Line: line, Column: startCol, Index: startIdx},
51+
Stop: Location{Line: line, Column: stopCol, Index: stopIdx},
5252
Filename: l.filename,
5353
}
5454
l.diagnostics.Add(Diagnostic{

lang/ast/Locations.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ func (sl SourceLocation) ToLspRange() protocol.Range {
7676
}
7777

7878
func (sl SourceLocation) Intersects(other SourceLocation) bool {
79-
return sl.ContainsLocation(other.Start) || sl.ContainsLocation(other.Stop)
79+
selfContainsOtherBound := sl.ContainsLocation(other.Start) || sl.ContainsLocation(other.Stop)
80+
otherContainsSelfBound := other.ContainsLocation(sl.Start) || other.ContainsLocation(sl.Stop)
81+
82+
return selfContainsOtherBound || otherContainsSelfBound
83+
8084
}
8185

8286
func (sl SourceLocation) Contains(other SourceLocation) bool {
@@ -88,10 +92,10 @@ func (sl SourceLocation) ContainsLocation(l Location) bool {
8892
if !lineContained {
8993
return false
9094
}
91-
if sl.Start.Line == l.Line && sl.Start.Column >= l.Column {
95+
if sl.Start.Line == l.Line && sl.Start.Column > l.Column {
9296
return false
9397
}
94-
if sl.Stop.Line == l.Line && sl.Stop.Column <= l.Column {
98+
if sl.Stop.Line == l.Line && sl.Stop.Column < l.Column {
9599
return false
96100
}
97101
return true

lang/spec/Block.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func NewBlockSpecList(
3737
blocks: make(map[string]*BlockSpec),
3838
}
3939
for _, bs := range blocks {
40-
out.Add(&bs)
40+
bsCopy := bs
41+
out.Add(&bsCopy)
4142
}
4243
return out
4344
}

lang/spec/Enum.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ func (e EnumSpec) Match(valueCtx grammar.IValueContext) (ast.Node, []ast.Diagnos
7979
spec: e,
8080
Value: value,
8181
BaseSymbol: ast.BaseSymbol{
82-
BaseNode: ast.BaseNode{
83-
Location: &l,
84-
},
82+
Location: &l,
83+
BaseNode: ast.BaseNode{},
8584
},
8685
}
8786

0 commit comments

Comments
 (0)