1313use Complete \Resolver \ScopeResolver ;
1414use Parser \Processor \IndexProcessor ;
1515use Parser \Processor \ScopeProcessor ;
16-
16+ use Psr \ Log \ LoggerInterface ;
1717
1818class ContentManager {
1919 public function __construct (
@@ -22,14 +22,16 @@ public function __construct(
2222 ContextResolver $ contextResolver ,
2323 Completer $ completer ,
2424 IndexProcessor $ indexProcessor ,
25- ScopeProcessor $ scopeProcessor
25+ ScopeProcessor $ scopeProcessor ,
26+ LoggerInterface $ logger
2627 ){
27- $ this ->parser = $ parser ;
28- $ this ->generator = $ generator ;
29- $ this ->contextResolver = $ contextResolver ;
30- $ this ->completer = $ completer ;
31- $ this ->indexProcessor = $ indexProcessor ;
32- $ this ->scopeProcessor = $ scopeProcessor ;
28+ $ this ->parser = $ parser ;
29+ $ this ->generator = $ generator ;
30+ $ this ->contextResolver = $ contextResolver ;
31+ $ this ->completer = $ completer ;
32+ $ this ->indexProcessor = $ indexProcessor ;
33+ $ this ->scopeProcessor = $ scopeProcessor ;
34+ $ this ->logger = $ logger ;
3335 $ this ->cachePool = [];
3436 }
3537 public function createCompletion (
@@ -49,23 +51,24 @@ public function createCompletion(
4951 );
5052 try {
5153 $ scope = $ this ->processFileContent ($ project , $ lines , $ line , $ file );
52- echo microtime (1 ) - $ start ;
53- echo " for indexing preparing \n" ;
54- echo microtime (1 ) - $ start ;
55- echo " for scope preparing \n" ;
54+ if (empty ($ scope )){
55+ $ scope = new Scope ;
56+ }
57+ $ this ->logger ->addDebug (sprintf (
58+ "%s seconds for ast processing "
59+ , (microtime (1 ) - $ start )));
5660 }
5761 catch (\Exception $ e ){
5862 $ scope = new Scope ;
5963 }
6064 $ entries = $ this ->findEntries ($ project , $ scope , $ completionLine , $ column , $ lines );
61- echo microtime (1 ) - $ start ;
62- echo " for entries preparing \n" ;
65+ $ this ->logger ->addDebug (sprintf (
66+ "%s seconds for entries generation "
67+ , (microtime (1 ) - $ start )));
6368 }
6469 elseif (!empty ($ content )) {
6570 $ this ->updateFileIndex ($ project , $ content , $ file );
6671 }
67- echo microtime (1 ) - $ start ;
68- echo " seconds for creaeting completion \n" ;
6972
7073 return [
7174 "entries " => $ entries ,
@@ -88,7 +91,7 @@ protected function prepareContent($content, $line, $column){
8891 else {
8992 $ badLine = $ lines [$ line -1 ];
9093 }
91- $ completionLine = substr ($ badLine , 0 , $ column+ 1 );
94+ $ completionLine = substr ($ badLine , 0 , $ column- 1 );
9295 $ lines [$ line -1 ] = "" ;
9396 return [$ lines , trim ($ badLine ), trim ($ completionLine )];
9497 }
@@ -111,13 +114,13 @@ protected function processFileContent(Project $project, $lines, $line, $file){
111114 if (!$ fqcn ){
112115 return ;
113116 }
114- if (!array_key_exists ($ file , $ this ->cachePool )){
115- $ this ->cachePool [$ file ] = [0 , null , null ];
117+ if (false && !array_key_exists ($ file , $ this ->cachePool )){
118+ $ this ->cachePool [$ file ] = [0 , [], [] ];
116119 }
117120 if ($ this ->isValidCache ($ file , $ content )){
118121 list ($ hash , $ indexNodes , $ scopeNodes ) = $ this ->cachePool [$ file ];
119122 }
120- else {
123+ if ( empty ( $ scopeNodes )) {
121124 $ this ->indexProcessor ->clearResultNodes ();
122125 $ this ->scopeProcessor ->clearResultNodes ();
123126 $ this ->scopeProcessor ->setIndex ($ project ->getIndex ());
@@ -151,4 +154,5 @@ private function isValidCache($file, $content){
151154 private $ indexProcessor ;
152155 private $ scopeProcessor ;
153156 private $ cachePool ;
157+ private $ logger ;
154158}
0 commit comments