-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for Python.IndentationError
- Loading branch information
Showing
3 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,45 @@ | ||
package python | ||
|
||
import lib "github.com/nedpals/errgoengine" | ||
import ( | ||
"fmt" | ||
|
||
lib "github.com/nedpals/errgoengine" | ||
) | ||
|
||
var IndentationError = lib.ErrorTemplate{ | ||
Name: "IndentationError", | ||
Pattern: compileTimeError("IndentationError: unindent does not match any outer indentation level"), | ||
OnGenExplainFn: func(cd *lib.ContextData, gen *lib.ExplainGenerator) { | ||
gen.Add("The code is not indented properly") | ||
gen.Add("This error occurs when there is a mismatch in the indentation levels in the code.") | ||
}, | ||
OnGenBugFixFn: func(cd *lib.ContextData, gen *lib.BugFixGenerator) { | ||
// TODO: | ||
gen.Add("Correct the indentation", func(s *lib.BugFixSuggestion) { | ||
// use the previous sibling's spacing as basis | ||
prevSibling := cd.MainError.Nearest.PrevNamedSibling() | ||
if prevSibling.Type() == "function_definition" { | ||
prevSibling = prevSibling.ChildByFieldName("body").LastNamedChild() | ||
} | ||
|
||
fmt.Println(prevSibling.String()) | ||
spaces := cd.MainError.Document.LineAt(prevSibling.StartPosition().Line)[:prevSibling.StartPosition().Column] | ||
|
||
s.AddStep("Ensure consistent indentation by using the correct spacing for each level of indentation."). | ||
AddFix(lib.FixSuggestion{ | ||
NewText: "", | ||
StartPosition: lib.Position{ | ||
Line: cd.MainError.Nearest.StartPosition().Line, | ||
}, | ||
EndPosition: cd.MainError.Nearest.StartPosition(), | ||
}). | ||
AddFix(lib.FixSuggestion{ | ||
NewText: spaces, | ||
StartPosition: lib.Position{ | ||
Line: cd.MainError.Nearest.StartPosition().Line, | ||
}, | ||
EndPosition: lib.Position{ | ||
Line: cd.MainError.Nearest.StartPosition().Line, | ||
}, | ||
}) | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters