def x_show_all_files(self): res = [] for fe in range(1, files_map.Get_Last_Source_File_Entry() + 1): doc = self._fe_map.get(fe, None) res.append({'fe': fe, 'uri': doc.uri if doc is not None else None, 'name': pyutils.name_image(files_map.Get_File_Name(fe)), 'dir': pyutils.name_image(files_map.Get_Directory_Name(fe))}) return res
def apply_change(self, change): """Apply a change to the document.""" text = change["text"] change_range = change.get("range") text_bytes = text.encode(Document.encoding, "replace") if not change_range: # The whole file has changed raise AssertionError # if len(text_bytes) < thin.Files_Map.Get_Buffer_Length(self._fe): # xxxx_replace # else: # xxxx_free # xxxx_allocate # return start_line = change_range["start"]["line"] start_col = change_range["start"]["character"] end_line = change_range["end"]["line"] end_col = change_range["end"]["character"] status = files_map_editor.Replace_Text( self._fe, start_line + 1, start_col, end_line + 1, end_col, ctypes.c_char_p(text_bytes), len(text_bytes), ) if status: return # Failed to replace text. # Increase size self.gap_size *= 2 fileid = files_map.Get_File_Name(self._fe) dirid = files_map.Get_Directory_Name(self._fe) buf_len = files_map.Get_File_Length( self._fe) + len(text_bytes) + self.gap_size files_map.Discard_Source_File(self._fe) new_sfe = files_map.Reserve_Source_File(dirid, fileid, buf_len) files_map_editor.Copy_Source_File(new_sfe, self._fe) files_map.Free_Source_File(self._fe) self._fe = new_sfe status = files_map_editor.Replace_Text( self._fe, start_line + 1, start_col, end_line + 1, end_col, ctypes.c_char_p(text_bytes), len(text_bytes), ) assert status
def sfe_to_document(self, sfe): """Get the document correspond to :param sfe: source file. Can create the document if needed.""" assert sfe != 0 doc = self._fe_map.get(sfe, None) if doc is None: # Could be a document from outside... filename = pyutils.name_image(files_map.Get_File_Name(sfe)) if not os.path.isabs(filename): dirname = pyutils.name_image(files_map.Get_Directory_Name(sfe)) filename = os.path.join(dirname, filename) doc = self.create_document_from_sfe(sfe, filename) return doc