From edd721d29182879a3d479d0ffffa61dc3a6fdfb1 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Fri, 16 Dec 2016 23:13:30 +0100 Subject: [PATCH] Reset definitions and references on content update --- src/PhpDocument.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/PhpDocument.php b/src/PhpDocument.php index 76009a9..b838cd3 100644 --- a/src/PhpDocument.php +++ b/src/PhpDocument.php @@ -141,7 +141,24 @@ class PhpDocument public function updateContent(string $content) { $this->content = $content; - $stmts = null; + + // Unregister old definitions + if (isset($this->definitions)) { + foreach ($this->definitions as $fqn => $definition) { + $this->index->removeDefinition($fqn); + } + } + + // Unregister old references + if (isset($this->referenceNodes)) { + foreach ($this->referenceNodes as $fqn => $node) { + $this->index->removeReferenceUri($fqn, $this->uri); + } + } + + $this->referenceNodes = null; + $this->definitions = null; + $this->definitionNodes = null; $errorHandler = new ErrorHandler\Collecting; $stmts = $this->parser->parse($content, $errorHandler); @@ -187,25 +204,12 @@ class PhpDocument $traverser->traverse($stmts); - // Unregister old definitions - if (isset($this->definitions)) { - foreach ($this->definitions as $fqn => $definition) { - $this->index->removeDefinition($fqn); - } - } // Register this document on the project for all the symbols defined in it $this->definitions = $definitionCollector->definitions; $this->definitionNodes = $definitionCollector->nodes; foreach ($definitionCollector->definitions as $fqn => $definition) { $this->index->setDefinition($fqn, $definition); } - - // Unregister old references - if (isset($this->referenceNodes)) { - foreach ($this->referenceNodes as $fqn => $node) { - $this->index->removeReferenceUri($fqn, $this->uri); - } - } // Register this document on the project for references $this->referenceNodes = $referencesCollector->nodes; foreach ($referencesCollector->nodes as $fqn => $nodes) {