Skip to content

Commit

Permalink
Populating codeOf of ASTModule (#1634)
Browse files Browse the repository at this point in the history
* Populating `codeOf` of `ASTModule`

This error message was annoying me, so here is a fix. I am not sure if it is easy to find the "location" of the module. The region should be able to be computed out of the lengt of `fileContents` and its actual content. I actually thought we had a function like that somewhere @konradweiss?

* make sonarcube happy

---------

Co-authored-by: Maximilian Kaul <[email protected]>
  • Loading branch information
oxisto and maximiliankaul authored Jul 26, 2024
1 parent fdc642b commit 2076f44
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,20 @@ class PythonLanguageFrontend(language: Language<PythonLanguageFrontend>, ctx: Tr
* 3) Remove trailing whitespaces / tabs
*/
override fun codeOf(astNode: Python.AST): String? {
val location = locationOf(astNode)
if (location != null) {
var lines = getRelevantLines(location)
lines = removeExtraAtEnd(location, lines)
lines = fixStartColumn(location, lines)
return if (astNode is Python.ASTModule) {
fileContent
} else {
val location = locationOf(astNode)
if (location != null) {
var lines = getRelevantLines(location)
lines = removeExtraAtEnd(location, lines)
lines = fixStartColumn(location, lines)

return lines.joinToString(separator = lineSeparator.toString())
lines.joinToString(separator = lineSeparator.toString())
} else {
null
}
}
return null
}

private fun getRelevantLines(location: PhysicalLocation): MutableList<String> {
Expand Down

0 comments on commit 2076f44

Please sign in to comment.