Compare commits
No commits in common. "592bd8c628b105af19b47503257e51e636b64606" and "49d673b0b8bb3691318532df0d4dc88edf780fcc" have entirely different histories.
592bd8c628
...
49d673b0b8
52
java
52
java
@ -16,18 +16,14 @@ def locate_launcher_configuration (jdt_ls_path):
|
||||
|
||||
# TODO
|
||||
def locate_lombok ():
|
||||
return os.path.join(os.environ['HOME'], ".m2/repository/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar")
|
||||
return "/home/malacoda/.m2/repository/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar"
|
||||
|
||||
class Java(LspServer):
|
||||
def __init__ (self, arguments):
|
||||
self.path = arguments[0]
|
||||
|
||||
command = ["java"]
|
||||
if "--enable-lombok" in arguments:
|
||||
arguments.remove("--enable-lombok")
|
||||
command.append(f"-javaagent:{locate_lombok()}")
|
||||
|
||||
command = command + [
|
||||
super().__init__([
|
||||
"java",
|
||||
f"-javaagent:{locate_lombok()}",
|
||||
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044",
|
||||
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
|
||||
"-Dosgi.bundles.defaultStartLevel=4",
|
||||
@ -40,19 +36,35 @@ class Java(LspServer):
|
||||
"--add-modules=ALL-SYSTEM",
|
||||
"--add-opens", "java.base/java.util=ALL-UNNAMED",
|
||||
"--add-opens", "java.base/java.lang=ALL-UNNAMED"
|
||||
] + arguments[1:]
|
||||
|
||||
super().__init__(command)
|
||||
] + arguments[1:])
|
||||
|
||||
@command("java.apply.workspaceEdit")
|
||||
def workspaceEdit (self, arguments):
|
||||
print(f"we {arguments}", file=sys.stderr)
|
||||
for argument in arguments:
|
||||
self.send_to_client({
|
||||
"id": -1,
|
||||
"method": "workspace/applyEdit",
|
||||
"params": {
|
||||
"edit": {
|
||||
"changes": argument['changes']
|
||||
}
|
||||
}
|
||||
})
|
||||
for file_name, changes in argument['changes'].items():
|
||||
file_name = file_name[len(FILE_URI):]
|
||||
file_contents = ""
|
||||
|
||||
if os.path.exists(file_name):
|
||||
with open(file_name) as in_file:
|
||||
file_contents = in_file.read()
|
||||
|
||||
for change in changes:
|
||||
file_contents = perform_change(file_contents, change)
|
||||
|
||||
with open(file_name, "w") as out_file:
|
||||
out_file.write(file_contents)
|
||||
|
||||
def get_character_offset (file_contents, line, character):
|
||||
line_pos = 0
|
||||
while line > 0:
|
||||
line_pos = file_contents.index("\n", line_pos) + 1
|
||||
line = line - 1
|
||||
return line_pos + character
|
||||
|
||||
def perform_change (file_text, change):
|
||||
change_start = get_character_offset(file_text, change['range']['start']['line'], change['range']['start']['character'])
|
||||
change_end = get_character_offset(file_text, change['range']['end']['line'], change['range']['end']['character'])
|
||||
print(f"change {change_start} {change['newText']} {change_end}", file=sys.stderr)
|
||||
return file_text[:change_start] + change['newText'] + file_text[change_end:]
|
||||
|
@ -40,9 +40,6 @@ def process_messages (source, sink, handlers, log):
|
||||
print("stop message handler", file=log)
|
||||
|
||||
def transmit_payload (payload, sink):
|
||||
if isinstance(payload, dict):
|
||||
payload = json.dumps(payload)
|
||||
|
||||
sink.write(f"{CONTENT_LENGTH}{len(payload)}\r\n\r\n{payload}".encode())
|
||||
sink.flush()
|
||||
|
||||
@ -97,10 +94,10 @@ class LspServer:
|
||||
run(self.command)
|
||||
|
||||
def send_to_client (self, payload):
|
||||
transmit_payload(payload, sys.stdout.buffer)
|
||||
transmit_payload(sys.stdout, payload)
|
||||
|
||||
def send_to_server (self, payload):
|
||||
transmit_payload(payload, self.process.stdout)
|
||||
transmit_payload(self.process.stdout, payload)
|
||||
|
||||
def close (self):
|
||||
if self.process:
|
||||
|
Loading…
x
Reference in New Issue
Block a user