-
Notifications
You must be signed in to change notification settings - Fork 5
/
preferences.py
87 lines (61 loc) · 2.2 KB
/
preferences.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import sublime
import os
import json
import re
import hashlib
st_version = 2
if sublime.version() == '' or int(sublime.version()) > 3000:
st_version = 3
class PCIPrefs:
preference_options = (
("daemon_port", 20001),
("php_path", "/usr/bin/php"),
("rescan_on_save", False),
("php_extensions", (".php")),
("debug_enabled", False),
("scan_all_project_folders", True),
("include_dirs", []),
("exclude_patterns", []),
)
def load(self, view):
self.settings = sublime.load_settings('PHPCodeIntel.sublime-settings')
if sublime.active_window() is not None:
project_settings = view.settings()
if project_settings.has("PHPCodeIntel"):
self.project_settings = project_settings.get('PHPCodeIntel')
else:
self.project_settings = {}
else:
self.project_settings = {}
for (key, default) in self.preference_options:
setattr(self, key, self._load_setting(key, default))
self._init_db_path()
def _load_setting(self, key, default=None):
if key in self.project_settings:
return self.project_settings.get(key)
value = self.settings.get(key)
if value == None:
value = default
return value
def _init_db_path(self):
self.db_folder = os.path.expanduser(os.path.join('~', '.phpcodeintel'))
if not os.path.exists(self.db_folder):
os.makedirs(self.db_folder)
def getProjectScanDirs(self, view):
scan_dirs = []
if self.scan_all_project_folders:
folders = view.window().folders()
scan_dirs.extend(folders)
scan_dirs.extend(self.include_dirs)
return scan_dirs
def getDBFilePath(self, view):
project_path = view.window().project_file_name()
if project_path == None:
return None
basedir,basename = os.path.split(project_path)
name = basename[:-16]+'-'+hashlib.md5(project_path.encode('utf-8')).hexdigest()
return os.path.join(self.db_folder, name+'.sqlite3')
def load(view):
prefs = PCIPrefs()
prefs.load(view)
return prefs