1
0
Fork 0

Remove old definition/references after reparse

pull/88/head
Felix Becker 2016-10-18 11:14:42 +02:00
parent 691a0bddfe
commit f95ebceb02
2 changed files with 42 additions and 0 deletions

View File

@ -167,12 +167,24 @@ class PhpDocument
$traverser->traverse($stmts); $traverser->traverse($stmts);
// Unregister old definitions
if (isset($this->definitions)) {
foreach ($this->definitions as $fqn => $node) {
$this->project->removeDefinition($fqn);
}
}
// Register this document on the project for all the symbols defined in it // Register this document on the project for all the symbols defined in it
$this->definitions = $definitionCollector->definitions; $this->definitions = $definitionCollector->definitions;
foreach ($definitionCollector->definitions as $fqn => $node) { foreach ($definitionCollector->definitions as $fqn => $node) {
$this->project->setDefinitionUri($fqn, $this->uri); $this->project->setDefinitionUri($fqn, $this->uri);
} }
// Unregister old references
if (isset($this->references)) {
foreach ($this->references as $fqn => $node) {
$this->project->removeReferenceUri($fqn, $this->uri);
}
}
// Register this document on the project for references // Register this document on the project for references
$this->references = $referencesCollector->references; $this->references = $referencesCollector->references;
foreach ($referencesCollector->references as $fqn => $nodes) { foreach ($referencesCollector->references as $fqn => $nodes) {

View File

@ -150,6 +150,18 @@ class Project
$this->definitions[$fqn] = $uri; $this->definitions[$fqn] = $uri;
} }
/**
* Unsets a document URI as the container for a specific symbol
* and removes all references pointing to that symbol
*
* @param string $fqn The fully qualified name of the symbol
* @return void
*/
public function removeDefinition(string $fqn) {
unset($this->definitions[$fqn]);
unset($this->references[$fqn]);
}
/** /**
* Adds a document URI as a referencee of a specific symbol * Adds a document URI as a referencee of a specific symbol
* *
@ -167,6 +179,24 @@ class Project
} }
} }
/**
* Removes a document URI as the container for a specific symbol
*
* @param string $fqn The fully qualified name of the symbol
* @param string $uri The URI
* @return void
*/
public function removeReferenceUri(string $fqn, string $uri) {
if (!isset($this->references[$fqn])) {
return;
}
$index = array_search($fqn, $this->references[$fqn], true);
if ($index === false) {
return;
}
array_splice($this->references[$fqn], $index, 1);
}
/** /**
* Returns all documents that reference a symbol * Returns all documents that reference a symbol
* *