Skip to content

Commit

Permalink
added rescan on save
Browse files Browse the repository at this point in the history
  • Loading branch information
deweller committed May 27, 2013
1 parent 3c43549 commit c6eeb56
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
*.pyc
var/log/*
.php_intel_data
*.sqlite3
*.sublime-project
*.sublime-workspace
.tags*
Expand Down
4 changes: 1 addition & 3 deletions PHP/lib/local/PHPIntel/Context/ContextBuilder.php
Expand Up @@ -55,7 +55,7 @@ public function resolveContext($tokens, $position_map, $str_position, $statement
$token_0 = LexerUtil::buildTokenDescriptionArray($tokens[$token_offset - 2]);
$token_1 = LexerUtil::buildTokenDescriptionArray($tokens[$token_offset - 1]);
$token_2 = LexerUtil::buildTokenDescriptionArray($tokens[$token_offset - 0]);
Logger::log("tokens are 0)".token_name($token_0[0]).":".$token_0[1]." 1)".token_name($token_1[0]).":".$token_1[1]." 2)".token_name($token_2[0]).":".$token_2[1]."");
// Logger::log("tokens are 0)".token_name($token_0[0]).":".$token_0[1]." 1)".token_name($token_1[0]).":".$token_1[1]." 2)".token_name($token_2[0]).":".$token_2[1]."");

$context_data = array();
switch (true) {
Expand Down Expand Up @@ -106,15 +106,13 @@ public function resolveContext($tokens, $position_map, $str_position, $statement

protected function resolveClassForVariable($variable, $statements)
{
Logger::log("resolveClassForVariable");
if ($variable === '$this') {
return $this->getCurrentClassName($statements);
}

// get the class name assigned to this variable
$visitor = new VariableClassResolverVisitor($variable);
$this->traverseStatements($visitor, $statements);
Logger::log("traverseStatements end");
return $visitor->getResolvedClassName();
}

Expand Down
21 changes: 16 additions & 5 deletions PHPCodeIntel.py
Expand Up @@ -178,6 +178,12 @@ def startPHPDaemon(self):
self.debugMsg("starting proc " + ' '.join(args))
proc = subprocess.Popen(args, stdout=subprocess.PIPE, startupinfo=startupinfo, env=proc_env, cwd=self.bin_path)

def rescanFile(self, view, src_file):
src_file = view.file_name()
if src_file == None:
return
db_file = self.getProjectRoot(view, src_file) + '/.php_intel.sqlite3'
self.runRemoteCommandInPHPDaemon('scanFile', [src_file, db_file])



Expand All @@ -190,11 +196,7 @@ class PhpCodeIntelScanFileCommand(PhpCodeIntelBase, sublime_plugin.TextCommand):

def run(self, edit):
self.loadSettings(self.view)
src_file = self.view.file_name()
if src_file == None:
return
db_file = self.getProjectRoot(self.view, src_file) + '/.php_intel.sqlite3'
self.runRemoteCommandInPHPDaemon('scanFile', [src_file, db_file])
self.rescanFile(self.view, self.view.file_name())

# scans a project
class PhpCodeIntelScanProjectCommand(PhpCodeIntelBase, sublime_plugin.TextCommand):
Expand Down Expand Up @@ -248,13 +250,22 @@ def on_query_completions(self, view, prefix, locations):
pos = sel.end()

completions_array = self.runRemoteCommandInPHPDaemon('autoComplete', [content, pos, php_intel_file])
if completions_array == None:
self.debugMsg("completions_array was None");
return

# convert completions array into tuples for python
completions = []
for item in completions_array:
completions.append((item[0], item[1]))
return completions

def on_post_save(self, view):
self.loadSettings(view)
if self.getSetting('rescan_on_save', True) == True:
self.rescanFile(view, view.file_name())


def getContent(self, view):
content = view.substr(sublime.Region(0, view.size()))
sel = view.sel()[0]
Expand Down
2 changes: 2 additions & 0 deletions Sublime/Settings/PHPCodeIntel.sublime-settings
Expand Up @@ -10,6 +10,8 @@
// allow autocompletions
"autocomplete_enabled": true,

// rescan a file every time it is saved
"rescan_on_save": true,


// show debug messages to the console
Expand Down

0 comments on commit c6eeb56

Please sign in to comment.