command should work, but doesnt in editor

This commit is contained in:
Megadash452 2022-10-25 22:37:33 -04:00
parent 9f240e1150
commit 7169fbb709

View file

@ -220,8 +220,8 @@ class LanguageServer:
property with type Widget, the id of the source widget in a property
binding, ...)"""
open_file = self._open_files[params["textDocument"]["uri"]]
# TODO: request only has a start Position of the reference id. how to get the end Position to get id string??
# obj_id = open_file.text[utils.pos_to_idx(params["position"]["line"], params["position"]["character"], open_file.text):].split()[0]
span_start = utils.pos_to_idx(params["position"]["line"], params["position"]["character"], open_file.text)
obj_id = str(tokenizer._tokenize(open_file.text[span_start:]))
full_range = {
"start": { "line": 0, "character": 0 },
@ -232,29 +232,24 @@ class LanguageServer:
# "end": { "line": 0, "character": 0 },
# }
for obj in open_file.ast.objects_by_id():
# TODO: how to get the token's string representation?
if obj.tokens["id"] == obj_id:
# TODO: get span of widget class and span of closing }
if str(obj.tokens["id"]) == obj_id:
tokens = list(obj.get_semantic_tokens())
# Gets the first token of the widget object
position = utils.idx_to_pos(tokens[0], open_file.text)
# Full range starts at the position of the first token of the widget
position = utils.idx_to_pos(tokens[0].start, open_file.text)
full_range["start"]["line"] = position[0]
full_range["start"]["character"] = position[1]
# Goes through all the tokens (starting from the 2nd) of the widget object
# Goes through all the tokens (starting from the 2nd) of the widget object until ID token
for token in tokens[1:]:
position = utils.idx_to_pos(obj.get_semantic_tokens(), open_file.text)
full_range["end"]["line"] = position[0]
full_range["end"]["character"] = position[1] # + len(token)
# TODO: how to get the token's string representation?
if token == obj_id and id_range == None:
if str(token) == obj_id:
position = utils.idx_to_pos(token.start, open_file.text)
id_range = {
"start": { "line": position[0], "character": position[1] },
"end": { "line": position[0], "character": position[1] + len(obj_id) },
}
full_range["end"] = id_range["end"]
break
break
if id_range: