Skip to content

Commit

Permalink
fix: skip parsing document if content is the same
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Mar 10, 2024
1 parent b27f334 commit 9b5509f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions errgoengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ func ParseFiles(contextData *ContextData, defaultLanguage *Language, files fs.Re
// check if document already exists
existingDoc, docExists := contextData.Documents[path]

if docExists && existingDoc.BytesContentEquals(contents) {
// do not parse if content is the same
continue
}

// check matched languages
selectedLanguage := defaultLanguage
if docExists {
Expand Down
8 changes: 8 additions & 0 deletions source.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,14 @@ type Document struct {
Tree *sitter.Tree
}

func (doc *Document) StringContentEquals(str string) bool {
return doc.Contents == str
}

func (doc *Document) BytesContentEquals(cnt []byte) bool {
return doc.Contents == string(cnt)
}

func (doc *Document) RootNode() SyntaxNode {
return WrapNode(doc, doc.Tree.RootNode())
}
Expand Down

0 comments on commit 9b5509f

Please sign in to comment.