code-intelligence 4.2.2__py3-none-win_amd64.whl → 4.3.1__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ from .goober import (
13
13
  # SHAME - Bump when fixing things too embarrassing to admit.
14
14
  # PROUD.DEFAULT.SHAME
15
15
  # \ | /
16
- __version__ = "4.2.2"
16
+ __version__ = "4.3.1"
17
17
  __version_info__ = tuple(int(i) for i in __version__.split('.'))
18
18
 
19
19
  __all__ = [
@@ -10,10 +10,24 @@ from enum import IntEnum, IntFlag
10
10
 
11
11
  DIR = Path(__file__).parent
12
12
 
13
+ class Str_C(C.Structure):
14
+ _fields_ = [
15
+ ("data" , C.c_char_p),
16
+ ("length", C.c_uint32),
17
+ ]
18
+
19
+ def to_bytes(self) -> bytes:
20
+ return C.string_at(self.data, self.length)
21
+
22
+ def to_str_c(s: str | bytes) -> Str_C:
23
+ if isinstance(s, str):
24
+ s = s.encode()
25
+ return Str_C(s, len(s))
26
+
13
27
  _lib = C.CDLL(str(DIR / "libcode_intelligence.so"))
14
28
 
15
29
  SCAN_CALLBACK = C.CFUNCTYPE(None, C.c_void_p)
16
- _lib.enqueue_scan_file.argtypes = [SCAN_CALLBACK, C.c_void_p, C.c_char_p, C.c_uint64]
30
+ _lib.enqueue_scan_file.argtypes = [SCAN_CALLBACK, C.c_void_p, Str_C, C.c_uint64]
17
31
  _lib.enqueue_scan_file.restype = None
18
32
 
19
33
  class Definition_Link_C(C.Structure):
@@ -26,7 +40,7 @@ class Definition_Link_C(C.Structure):
26
40
  ]
27
41
 
28
42
  FIND_CALLBACK = C.CFUNCTYPE(None, C.c_void_p, C.POINTER(Definition_Link_C), C.c_int, C.c_void_p)
29
- _lib.enqueue_find_symbols_in_text.argtypes = [FIND_CALLBACK, C.c_void_p, C.c_char_p, C.c_bool, C.c_bool]
43
+ _lib.enqueue_find_symbols_in_text.argtypes = [FIND_CALLBACK, C.c_void_p, Str_C, C.c_bool, C.c_bool, C.POINTER(Str_C), C.c_uint32]
30
44
  _lib.enqueue_find_symbols_in_text.restype = None
31
45
 
32
46
  _lib.enqueue_stop.argtypes = []
@@ -72,6 +86,16 @@ class Definition_Link:
72
86
  line_0_based : int = 0
73
87
  column_0_based : int = 0
74
88
 
89
+ @classmethod
90
+ def from_c(cls, link: Definition_Link_C):
91
+ return cls(
92
+ start_offset_in_text=link.start_offset_in_utf8_text,
93
+ end_offset_in_text=link.end_offset_in_utf8_text,
94
+ source_file=link.source_file.decode('utf-8'),
95
+ line_0_based=link.line_0_based,
96
+ column_0_based=link.column_0_based,
97
+ )
98
+
75
99
 
76
100
  # Using ["..."] syntax to create a copy independant of
77
101
  # whether any other library sets the signature for those functions.
@@ -115,7 +139,7 @@ def scan_file(file, language: Language, callback=None, data=None) -> bool:
115
139
  c_callback, data_ptr = C_AFTER_SCAN, _wrap_data_ptr((callback, data))
116
140
 
117
141
  # print(f"[PY] sending next request {file}")
118
- _lib.enqueue_scan_file(c_callback, data_ptr, os.fsencode(file), language)
142
+ _lib.enqueue_scan_file(c_callback, data_ptr, to_str_c(os.fsencode(file)), language)
119
143
 
120
144
  # never drop the request (it would be a memory leak)
121
145
  return True
@@ -124,18 +148,22 @@ def scan_file(file, language: Language, callback=None, data=None) -> bool:
124
148
  @SCAN_CALLBACK
125
149
  def C_AFTER_SCAN(data_ptr):
126
150
  callback, data = _unwrap_data_ptr(data_ptr)
127
- if callback is not None:
128
- callback(data)
151
+ assert callback is not None, "Don't feed youself NULL callbacks!"
152
+ callback(data)
129
153
 
130
154
 
131
- def find_symbols_in_text(text: str, callback=None, data=None, ignore_word_like: bool = False, sync: bool = False) -> bool:
155
+ def find_symbols_in_text(text: str, callback=None, data=None, ignore_word_like: bool = False, sync: bool = False, first_look_at_these_files: list[Path|str] = []) -> bool:
132
156
  if callback is None:
133
- c_callback, data_ptr = C_NO_CALLBACK, 0
134
- else:
135
- c_callback, data_ptr = C_AFTER_FIND, _wrap_data_ptr((callback, data))
157
+ return True
158
+
159
+ c_callback, data_ptr = C_AFTER_FIND, _wrap_data_ptr((callback, data))
160
+
161
+ first_look_at_these_files_c = (Str_C * len(first_look_at_these_files))()
162
+ for i, it in enumerate(first_look_at_these_files):
163
+ first_look_at_these_files_c[i] = to_str_c(os.fsencode(it))
136
164
 
137
165
  # print("[PY] sending find_symbols_in_text")
138
- _lib.enqueue_find_symbols_in_text(c_callback, data_ptr, text.encode(), ignore_word_like, sync)
166
+ _lib.enqueue_find_symbols_in_text(c_callback, data_ptr, to_str_c(text), ignore_word_like, sync, first_look_at_these_files_c, len(first_look_at_these_files))
139
167
 
140
168
  # never drop the request (it would be a memory leak)
141
169
  return True
@@ -145,18 +173,11 @@ def find_symbols_in_text(text: str, callback=None, data=None, ignore_word_like:
145
173
  def C_AFTER_FIND(data_ptr, links_ptr, count, strings_handle):
146
174
  callback, data = _unwrap_data_ptr(data_ptr)
147
175
  try:
148
- if callback is not None:
149
- results = [Definition_Link()] * count
150
- for i in range(count):
151
- link = links_ptr[i]
152
- results[i] = Definition_Link(
153
- start_offset_in_text=link.start_offset_in_utf8_text,
154
- end_offset_in_text=link.end_offset_in_utf8_text,
155
- source_file=link.source_file.decode('utf-8'),
156
- line_0_based=link.line_0_based,
157
- column_0_based=link.column_0_based,
158
- )
159
- callback(data, results)
176
+ assert callback is not None, "Don't feed youself NULL callbacks!"
177
+ results = [Definition_Link()] * count
178
+ for i in range(count):
179
+ results[i] = Definition_Link.from_c(links_ptr[i])
180
+ callback(data, results)
160
181
  finally:
161
182
  if links_ptr: _lib.free_memory(links_ptr)
162
183
  if strings_handle: _lib.free_memory(strings_handle)
@@ -221,7 +242,8 @@ if __name__ == "__main__":
221
242
  scan_file(path, Language.PYTHON, scan_callback, path)
222
243
 
223
244
  text = sys.argv[1]
224
- find_symbols_in_text(text, find_callback, data=(text, "before"))
245
+ find_symbols_in_text(text, find_callback, data=(text, "before"),
246
+ first_look_at_these_files=["hello.py", "yay.so"])
225
247
 
226
248
  print("[PY] WAIT, WAIT, WAIT!")
227
249
  wait_for_callbacks_in_seconds(20)
Binary file
@@ -1,4 +1,4 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code_intelligence
3
- Version: 4.2.2
3
+ Version: 4.3.1
4
4
  Summary: Code intelligence library
@@ -0,0 +1,6 @@
1
+ code_intelligence-4.3.1.dist-info/METADATA,sha256=fVFNZJ-357mc0lh0JO1nXwnuOPGfLII4Lnr0XANPBac,100
2
+ code_intelligence-4.3.1.dist-info/RECORD,,
3
+ code_intelligence-4.3.1.dist-info/WHEEL,sha256=aD7J6E7Slys9i0J65v6Ehfi0DHYa5rImRhUDp62Iwh0,98
4
+ code_intelligence/__init__.py,sha256=Tqxn-pY_ZsW8tv4ynDBmj3Xb6dg9wguqC3yls9hBWC4,587
5
+ code_intelligence/goober.py,sha256=XzT3wqxZae2OgvS9Uktcrr6tW3inxRNmUokvi-nIq2c,7596
6
+ code_intelligence/libcode_intelligence.so,sha256=Kx0BpK3TQKBHDWNCsNYq5vuDvZB7jqkvGuGLLefaU_E,8294912
@@ -1,6 +0,0 @@
1
- code_intelligence-4.2.2.dist-info/METADATA,sha256=rZXF32YBKPTTroc4vgTxereZWlDOjz0VV5k42b0iKT4,100
2
- code_intelligence-4.2.2.dist-info/RECORD,,
3
- code_intelligence-4.2.2.dist-info/WHEEL,sha256=aD7J6E7Slys9i0J65v6Ehfi0DHYa5rImRhUDp62Iwh0,98
4
- code_intelligence/__init__.py,sha256=nQPGzPpVtVdbEkTI2dGXmBdEXm8x0Q0_KbDhz-IiB80,587
5
- code_intelligence/goober.py,sha256=sb8NcJDfvHlJj7mXuAQpZ7apOtpQtg-7Ra5BrBZhwc4,6801
6
- code_intelligence/libcode_intelligence.so,sha256=bSSY32V9sln7FrntGw2iD_DO_xO5VbdXLq1wz5WKvrA,8276992