Base handling of java source dir paths

This commit is contained in:
itdominator 2024-10-02 00:58:16 -05:00
parent e3774ee5f3
commit 84b24d6767
2 changed files with 41 additions and 8 deletions

View File

@ -1,4 +1,5 @@
# Python imports
import urllib.parse as url_parse
# Lib imports
import gi
@ -89,6 +90,9 @@ class EditorControllerMixin(KeyInputController, EditorEventsMixin):
result = message.result[0]
line = result["range"]["start"]["line"]
uri = result["uri"].replace("file://", "")
if "jdt:" in uri:
uri = self.parse_java_jdt_to_uri(uri)
file = f"{uri}:{line}"
event_system.emit("handle_file_from_ipc", file)
@ -98,7 +102,25 @@ class EditorControllerMixin(KeyInputController, EditorEventsMixin):
source_view = None
def parse_java_jdt_to_uri(self, uri):
parse_str = url_parse.unquote(uri)
post_stub, \
pre_stub = parse_str.split("?=")
post_stub = post_stub.replace("jdt://contents/", "")
replace_stub = post_stub[
post_stub.index(".jar") + 4 : post_stub.index(".class")
]
post_stub = post_stub.replace(replace_stub, replace_stub.replace(".", "/") ) \
.replace(".jar", "-sources.jar:")
post_stub = post_stub.replace(".class", ".java")
pre_stub = pre_stub[
pre_stub.index("/\\/") + 2 : pre_stub.index(".jar")
]
pre_stub = pre_stub[: pre_stub.rfind("/") + 1 ].replace("\\", "")
return f"file://{pre_stub}{post_stub}"
# Gotten logic from:
# https://stackoverflow.com/questions/7139645/find-the-cursor-position-on-a-gtksourceview-window

View File

@ -1,4 +1,5 @@
# Python imports
import zipfile
# Lib imports
import gi
@ -122,7 +123,17 @@ class EditorNotebook(EditorControllerMixin, Gtk.Notebook):
return
if isinstance(gfile, str):
parts = gfile.split(":")
parts = gfile.replace("file://", "").split(":")
if len(parts) > 2:
with zipfile.ZipFile(parts[0], 'r') as file:
file.extract(parts[1][1:], "/tmp/newton_extracts")
gfile = Gio.File.new_for_path( f"/tmp/newton_extracts/{ parts[1][1:] }" )
try:
line = int(parts[2])
except Exception:
...
else:
gfile = Gio.File.new_for_path(parts[0])
try:
line = int(parts[1]) if len(parts) > 1 else 0