From 456a2355600c2626bc3f3548a2e6f9db3685b733 Mon Sep 17 00:00:00 2001 From: Stamnug <987004590@qq.com> Date: Thu, 12 Dec 2024 21:05:08 +0800 Subject: [PATCH 01/20] add path-mapping function --- LSP.sublime-settings | 9 +++++++++ plugin/core/sessions.py | 2 ++ plugin/core/types.py | 31 +++++++++++++++---------------- plugin/core/views.py | 2 +- plugin/goto_diagnostic.py | 2 +- plugin/locationpicker.py | 3 ++- plugin/references.py | 5 +++-- 7 files changed, 33 insertions(+), 21 deletions(-) diff --git a/LSP.sublime-settings b/LSP.sublime-settings index 6cb35033c..d5ed44adc 100644 --- a/LSP.sublime-settings +++ b/LSP.sublime-settings @@ -342,6 +342,15 @@ // // If the server supports `diagnosticProvider.workspaceDiagnostics`, // // diagnostics are requested for all files in the project folders. // "diagnostics_mode": "open_files", + // + // // Map the paths of URIs in the data exchanged between the server and the client. + // // + // // WARNING: Due to its working principle of modifying the interaction data between + // // the client and the server, it cannot identify the source of the content in the + // // data. If your code file happens to start with a URI and meets the mapping conditions, + // // it may inadvertently send incorrect messages to the server. However, such situations + // // should be virtually nonexistent. + // "path_maps": [ {"local": "file:///C:", "remote": "file:///mnt/c"} ] // } // } "clients": {}, diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index 79f8a3d5c..79e6a6bf1 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -2383,6 +2383,7 @@ def exit(self) -> None: def send_payload(self, payload: dict[str, Any]) -> None: try: + payload = self.config.map_uri_on_payload(payload, is_from_client_to_server=True) self.transport.send(payload) # type: ignore except AttributeError: pass @@ -2425,6 +2426,7 @@ def deduce_payload( return (None, None, None, None, None) def on_payload(self, payload: dict[str, Any]) -> None: + payload = self.config.map_uri_on_payload(payload, is_from_client_to_server=False) handler, result, req_id, typestr, _method = self.deduce_payload(payload) if handler: try: diff --git a/plugin/core/types.py b/plugin/core/types.py index b5d5b932f..fafed05c4 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -854,24 +854,23 @@ def match_view(self, view: sublime.View, scheme: str) -> bool: return False return scheme in self.schemes and sublime.score_selector(syntax.scope, selector) > 0 - def map_client_path_to_server_uri(self, path: str) -> str: - if self.path_maps: - for path_map in self.path_maps: - path, mapped = path_map.map_from_local_to_remote(path) - if mapped: - break - return filename_to_uri(path) - - def map_server_uri_to_client_path(self, uri: str) -> str: - scheme, path = parse_uri(uri) - if scheme not in ("file", "res"): - raise ValueError(f"{uri}: {scheme} URI scheme is unsupported") - if self.path_maps: + def map_uri_on_payload(self, payload: Any, is_from_client_to_server: bool) -> Any: + if isinstance(payload, dict): + for k, v in payload.items(): + payload[k] = self.map_uri_on_payload(v, is_from_client_to_server) + + if isinstance(payload, list): + for i, v in enumerate(payload): + payload[i] = self.map_uri_on_payload(v, is_from_client_to_server) + + if isinstance(payload, str) and payload.startswith("file://"): for path_map in self.path_maps: - path, mapped = path_map.map_from_remote_to_local(path) + path, mapped = path_map.map_from_local_to_remote(payload) if is_from_client_to_server else \ + path_map.map_from_remote_to_local(payload) if mapped: - break - return path + payload = path + + return payload def is_disabled_capability(self, capability_path: str) -> bool: for value in self.disabled_capabilities.walk(capability_path): diff --git a/plugin/core/views.py b/plugin/core/views.py index 654fabef7..46b0581c7 100644 --- a/plugin/core/views.py +++ b/plugin/core/views.py @@ -771,7 +771,7 @@ def location_to_human_readable( scheme, _ = parse_uri(uri) if scheme == "file": fmt = "{}:{}" - pathname = config.map_server_uri_to_client_path(uri) + pathname = parse_uri(uri)[1] if base_dir and is_subpath_of(pathname, base_dir): pathname = pathname[len(os.path.commonprefix((pathname, base_dir))) + 1:] elif scheme == "res": diff --git a/plugin/goto_diagnostic.py b/plugin/goto_diagnostic.py index 5f3018481..e5b01b045 100644 --- a/plugin/goto_diagnostic.py +++ b/plugin/goto_diagnostic.py @@ -265,7 +265,7 @@ def open_location( session: Session, location: Location, flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE, group: int = -1 ) -> sublime.View: uri, position = get_uri_and_position_from_location(location) - file_name = to_encoded_filename(session.config.map_server_uri_to_client_path(uri), position) + file_name = to_encoded_filename(parse_uri(uri)[1], position) return session.window.open_file(file_name, flags=flags | sublime.NewFileFlags.ENCODED_POSITION, group=group) diff --git a/plugin/locationpicker.py b/plugin/locationpicker.py index 97d5f73b0..0854f4b16 100644 --- a/plugin/locationpicker.py +++ b/plugin/locationpicker.py @@ -7,6 +7,7 @@ from .core.protocol import LocationLink from .core.protocol import Position from .core.sessions import Session +from .core.url import parse_uri from .core.views import get_uri_and_position_from_location from .core.views import location_to_human_readable from .core.views import to_encoded_filename @@ -49,7 +50,7 @@ def open_basic_file( if group is None: group = session.window.active_group() if uri.startswith("file:"): - filename = session.config.map_server_uri_to_client_path(uri) + filename = parse_uri(uri)[1] else: prefix = 'res:/Packages' # Note: keep in sync with core/url.py#_to_resource_uri assert uri.startswith(prefix) diff --git a/plugin/references.py b/plugin/references.py index 09e97cdd7..a86006e8f 100644 --- a/plugin/references.py +++ b/plugin/references.py @@ -9,6 +9,7 @@ from .core.sessions import Session from .core.settings import userprefs from .core.types import ClientConfig +from .core.url import parse_uri from .core.views import get_line from .core.views import get_symbol_kind_from_scope from .core.views import get_uri_and_position_from_location @@ -183,7 +184,7 @@ def _show_references_in_quick_panel( pt = selection[0].b view_filename = self.view.file_name() for idx, location in enumerate(locations): - if view_filename != session.config.map_server_uri_to_client_path(location['uri']): + if view_filename != parse_uri(location['uri'])[1]: continue index = idx if position_to_offset(location['range']['start'], self.view) > pt: @@ -246,7 +247,7 @@ def _group_locations_by_uri( grouped_locations: dict[str, list[tuple[Point, str]]] = {} for location in locations: uri, position = get_uri_and_position_from_location(location) - file_path = config.map_server_uri_to_client_path(uri) + file_path = parse_uri(uri)[1] point = Point.from_lsp(position) # get line of the reference, to showcase its use reference_line = get_line(window, file_path, point.row) From a6b3ee2c39fa1b7d6337e921904ba9d5a753aaa6 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 18:56:23 +0800 Subject: [PATCH 02/20] Update views.py --- plugin/core/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/core/views.py b/plugin/core/views.py index 46b0581c7..b63df4039 100644 --- a/plugin/core/views.py +++ b/plugin/core/views.py @@ -771,7 +771,7 @@ def location_to_human_readable( scheme, _ = parse_uri(uri) if scheme == "file": fmt = "{}:{}" - pathname = parse_uri(uri)[1] + pathname = config.map_uri_on_payload(uri, is_from_client_to_server=False) if base_dir and is_subpath_of(pathname, base_dir): pathname = pathname[len(os.path.commonprefix((pathname, base_dir))) + 1:] elif scheme == "res": From 41d14105e06676702da4898c0e805477091d3819 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 18:57:13 +0800 Subject: [PATCH 03/20] Update locationpicker.py --- plugin/locationpicker.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/locationpicker.py b/plugin/locationpicker.py index 0854f4b16..c2c2f1b71 100644 --- a/plugin/locationpicker.py +++ b/plugin/locationpicker.py @@ -7,7 +7,6 @@ from .core.protocol import LocationLink from .core.protocol import Position from .core.sessions import Session -from .core.url import parse_uri from .core.views import get_uri_and_position_from_location from .core.views import location_to_human_readable from .core.views import to_encoded_filename @@ -50,7 +49,7 @@ def open_basic_file( if group is None: group = session.window.active_group() if uri.startswith("file:"): - filename = parse_uri(uri)[1] + filename = session.config.map_uri_on_payload(uri, is_from_client_to_server=False) else: prefix = 'res:/Packages' # Note: keep in sync with core/url.py#_to_resource_uri assert uri.startswith(prefix) From e1e94a9181933b42830dfd6e837b0d25325f994d Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 18:58:34 +0800 Subject: [PATCH 04/20] Update goto_diagnostic.py --- plugin/goto_diagnostic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/goto_diagnostic.py b/plugin/goto_diagnostic.py index e5b01b045..4c9ade382 100644 --- a/plugin/goto_diagnostic.py +++ b/plugin/goto_diagnostic.py @@ -265,7 +265,7 @@ def open_location( session: Session, location: Location, flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE, group: int = -1 ) -> sublime.View: uri, position = get_uri_and_position_from_location(location) - file_name = to_encoded_filename(parse_uri(uri)[1], position) + file_name = to_encoded_filename(session.config.map_uri_on_payload(uri, is_from_client_to_server=False), position) return session.window.open_file(file_name, flags=flags | sublime.NewFileFlags.ENCODED_POSITION, group=group) From 607e5d58e9e2b565bb5852d032f65f9b37a199c8 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 18:59:29 +0800 Subject: [PATCH 05/20] Update references.py --- plugin/references.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/references.py b/plugin/references.py index a86006e8f..90bb5d904 100644 --- a/plugin/references.py +++ b/plugin/references.py @@ -9,7 +9,6 @@ from .core.sessions import Session from .core.settings import userprefs from .core.types import ClientConfig -from .core.url import parse_uri from .core.views import get_line from .core.views import get_symbol_kind_from_scope from .core.views import get_uri_and_position_from_location @@ -184,7 +183,7 @@ def _show_references_in_quick_panel( pt = selection[0].b view_filename = self.view.file_name() for idx, location in enumerate(locations): - if view_filename != parse_uri(location['uri'])[1]: + if view_filename != session.config.map_uri_on_payload(location['uri'], is_from_client_to_server=False): continue index = idx if position_to_offset(location['range']['start'], self.view) > pt: From ea4daf36e29818adb04fea42ea03f94e789b4aa9 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 18:59:50 +0800 Subject: [PATCH 06/20] Update references.py --- plugin/references.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/references.py b/plugin/references.py index 90bb5d904..a3062c39d 100644 --- a/plugin/references.py +++ b/plugin/references.py @@ -246,7 +246,7 @@ def _group_locations_by_uri( grouped_locations: dict[str, list[tuple[Point, str]]] = {} for location in locations: uri, position = get_uri_and_position_from_location(location) - file_path = parse_uri(uri)[1] + file_path = config.map_uri_on_payload(uri, is_from_client_to_server=False) point = Point.from_lsp(position) # get line of the reference, to showcase its use reference_line = get_line(window, file_path, point.row) From dd301a2d7fba539f1dc489a864859b9616852c86 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 19:22:10 +0800 Subject: [PATCH 07/20] Update views.py --- plugin/core/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/core/views.py b/plugin/core/views.py index b63df4039..654fabef7 100644 --- a/plugin/core/views.py +++ b/plugin/core/views.py @@ -771,7 +771,7 @@ def location_to_human_readable( scheme, _ = parse_uri(uri) if scheme == "file": fmt = "{}:{}" - pathname = config.map_uri_on_payload(uri, is_from_client_to_server=False) + pathname = config.map_server_uri_to_client_path(uri) if base_dir and is_subpath_of(pathname, base_dir): pathname = pathname[len(os.path.commonprefix((pathname, base_dir))) + 1:] elif scheme == "res": From 7ed9c77368ea597d2d655776cc886b602aa360ff Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 19:23:17 +0800 Subject: [PATCH 08/20] Update goto_diagnostic.py --- plugin/goto_diagnostic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/goto_diagnostic.py b/plugin/goto_diagnostic.py index 4c9ade382..5f3018481 100644 --- a/plugin/goto_diagnostic.py +++ b/plugin/goto_diagnostic.py @@ -265,7 +265,7 @@ def open_location( session: Session, location: Location, flags: sublime.NewFileFlags = sublime.NewFileFlags.NONE, group: int = -1 ) -> sublime.View: uri, position = get_uri_and_position_from_location(location) - file_name = to_encoded_filename(session.config.map_uri_on_payload(uri, is_from_client_to_server=False), position) + file_name = to_encoded_filename(session.config.map_server_uri_to_client_path(uri), position) return session.window.open_file(file_name, flags=flags | sublime.NewFileFlags.ENCODED_POSITION, group=group) From 34b0455919c4a373b588791daa281d1cb5583935 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 19:23:53 +0800 Subject: [PATCH 09/20] Update locationpicker.py --- plugin/locationpicker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/locationpicker.py b/plugin/locationpicker.py index c2c2f1b71..97d5f73b0 100644 --- a/plugin/locationpicker.py +++ b/plugin/locationpicker.py @@ -49,7 +49,7 @@ def open_basic_file( if group is None: group = session.window.active_group() if uri.startswith("file:"): - filename = session.config.map_uri_on_payload(uri, is_from_client_to_server=False) + filename = session.config.map_server_uri_to_client_path(uri) else: prefix = 'res:/Packages' # Note: keep in sync with core/url.py#_to_resource_uri assert uri.startswith(prefix) From 42555c328126d62f9bf9b5ac8ef30b1dfea52b58 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 19:24:19 +0800 Subject: [PATCH 10/20] Update references.py --- plugin/references.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/references.py b/plugin/references.py index a3062c39d..c23707027 100644 --- a/plugin/references.py +++ b/plugin/references.py @@ -183,7 +183,7 @@ def _show_references_in_quick_panel( pt = selection[0].b view_filename = self.view.file_name() for idx, location in enumerate(locations): - if view_filename != session.config.map_uri_on_payload(location['uri'], is_from_client_to_server=False): + if view_filename != session.config.map_server_uri_to_client_path(location['uri']): continue index = idx if position_to_offset(location['range']['start'], self.view) > pt: From 7caff6488a888977b0346b3c288ee461757df55f Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 19:24:38 +0800 Subject: [PATCH 11/20] Update references.py --- plugin/references.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/references.py b/plugin/references.py index c23707027..09e97cdd7 100644 --- a/plugin/references.py +++ b/plugin/references.py @@ -246,7 +246,7 @@ def _group_locations_by_uri( grouped_locations: dict[str, list[tuple[Point, str]]] = {} for location in locations: uri, position = get_uri_and_position_from_location(location) - file_path = config.map_uri_on_payload(uri, is_from_client_to_server=False) + file_path = config.map_server_uri_to_client_path(uri) point = Point.from_lsp(position) # get line of the reference, to showcase its use reference_line = get_line(window, file_path, point.row) From 211b9689e8a0d6f8e8e53730f5ce5768004cef9f Mon Sep 17 00:00:00 2001 From: Stamnug <987004590@qq.com> Date: Sun, 22 Dec 2024 19:45:28 +0800 Subject: [PATCH 12/20] Update types.py --- plugin/core/types.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugin/core/types.py b/plugin/core/types.py index fafed05c4..deb8e2368 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -872,6 +872,15 @@ def map_uri_on_payload(self, payload: Any, is_from_client_to_server: bool) -> An return payload + def map_client_path_to_server_uri(self, path: str) -> str: + return self.map_uri_on_payload(filename_to_uri(path), is_from_client_to_server=True) + + def map_server_uri_to_client_path(self, uri: str) -> str: + scheme, path = parse_uri(self.map_uri_on_payload(uri, is_from_client_to_server=False)) + if scheme not in ("file", "res"): + raise ValueError(f"{uri}: {scheme} URI scheme is unsupported") + return path + def is_disabled_capability(self, capability_path: str) -> bool: for value in self.disabled_capabilities.walk(capability_path): if isinstance(value, bool): From 77e9be541159752b91ff6e35bdc268ac484fa666 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 19:59:18 +0800 Subject: [PATCH 13/20] Update types.py --- plugin/core/types.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugin/core/types.py b/plugin/core/types.py index deb8e2368..e05e46b4c 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -853,6 +853,15 @@ def match_view(self, view: sublime.View, scheme: str) -> bool: if not selector: return False return scheme in self.schemes and sublime.score_selector(syntax.scope, selector) > 0 + + def map_client_path_to_server_uri(self, path: str) -> str: + return self.map_uri_on_payload(filename_to_uri(path), is_from_client_to_server=True) + + def map_server_uri_to_client_path(self, uri: str) -> str: + scheme, path = parse_uri(self.map_uri_on_payload(uri, is_from_client_to_server=False)) + if scheme not in ("file", "res"): + raise ValueError(f"{uri}: {scheme} URI scheme is unsupported") + return path def map_uri_on_payload(self, payload: Any, is_from_client_to_server: bool) -> Any: if isinstance(payload, dict): @@ -872,15 +881,6 @@ def map_uri_on_payload(self, payload: Any, is_from_client_to_server: bool) -> An return payload - def map_client_path_to_server_uri(self, path: str) -> str: - return self.map_uri_on_payload(filename_to_uri(path), is_from_client_to_server=True) - - def map_server_uri_to_client_path(self, uri: str) -> str: - scheme, path = parse_uri(self.map_uri_on_payload(uri, is_from_client_to_server=False)) - if scheme not in ("file", "res"): - raise ValueError(f"{uri}: {scheme} URI scheme is unsupported") - return path - def is_disabled_capability(self, capability_path: str) -> bool: for value in self.disabled_capabilities.walk(capability_path): if isinstance(value, bool): From 5ef96616fc6b398aa09d3447011e8064a30da56f Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 20:05:50 +0800 Subject: [PATCH 14/20] Update types.py --- plugin/core/types.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/plugin/core/types.py b/plugin/core/types.py index e05e46b4c..0add32ce1 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -845,6 +845,24 @@ def set_view_status(self, view: sublime.View, message: str) -> None: def erase_view_status(self, view: sublime.View) -> None: view.erase_status(self.status_key) + def map_uri_on_payload(self, payload: Any, is_from_client_to_server: bool) -> Any: + if isinstance(payload, dict): + for k, v in payload.items(): + payload[k] = self.map_uri_on_payload(v, is_from_client_to_server) + + if isinstance(payload, list): + for i, v in enumerate(payload): + payload[i] = self.map_uri_on_payload(v, is_from_client_to_server) + + if isinstance(payload, str) and payload.startswith("file://"): + for path_map in self.path_maps: + path, mapped = path_map.map_from_local_to_remote(payload) if is_from_client_to_server else \ + path_map.map_from_remote_to_local(payload) + if mapped: + payload = path + + return payload + def match_view(self, view: sublime.View, scheme: str) -> bool: syntax = view.syntax() if not syntax: @@ -863,24 +881,6 @@ def map_server_uri_to_client_path(self, uri: str) -> str: raise ValueError(f"{uri}: {scheme} URI scheme is unsupported") return path - def map_uri_on_payload(self, payload: Any, is_from_client_to_server: bool) -> Any: - if isinstance(payload, dict): - for k, v in payload.items(): - payload[k] = self.map_uri_on_payload(v, is_from_client_to_server) - - if isinstance(payload, list): - for i, v in enumerate(payload): - payload[i] = self.map_uri_on_payload(v, is_from_client_to_server) - - if isinstance(payload, str) and payload.startswith("file://"): - for path_map in self.path_maps: - path, mapped = path_map.map_from_local_to_remote(payload) if is_from_client_to_server else \ - path_map.map_from_remote_to_local(payload) - if mapped: - payload = path - - return payload - def is_disabled_capability(self, capability_path: str) -> bool: for value in self.disabled_capabilities.walk(capability_path): if isinstance(value, bool): From dd2bbc61ffe308aa7262bec9b30b118aa369cdcc Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 20:08:44 +0800 Subject: [PATCH 15/20] Update types.py --- plugin/core/types.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugin/core/types.py b/plugin/core/types.py index 0add32ce1..d89897f8d 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -845,6 +845,15 @@ def set_view_status(self, view: sublime.View, message: str) -> None: def erase_view_status(self, view: sublime.View) -> None: view.erase_status(self.status_key) + def match_view(self, view: sublime.View, scheme: str) -> bool: + syntax = view.syntax() + if not syntax: + return False + selector = self.selector.strip() + if not selector: + return False + return scheme in self.schemes and sublime.score_selector(syntax.scope, selector) > 0 + def map_uri_on_payload(self, payload: Any, is_from_client_to_server: bool) -> Any: if isinstance(payload, dict): for k, v in payload.items(): @@ -862,15 +871,6 @@ def map_uri_on_payload(self, payload: Any, is_from_client_to_server: bool) -> An payload = path return payload - - def match_view(self, view: sublime.View, scheme: str) -> bool: - syntax = view.syntax() - if not syntax: - return False - selector = self.selector.strip() - if not selector: - return False - return scheme in self.schemes and sublime.score_selector(syntax.scope, selector) > 0 def map_client_path_to_server_uri(self, path: str) -> str: return self.map_uri_on_payload(filename_to_uri(path), is_from_client_to_server=True) From ae4dd82de47bac3772f05497b520a42b38f030c6 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 20:10:33 +0800 Subject: [PATCH 16/20] Update types.py --- plugin/core/types.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugin/core/types.py b/plugin/core/types.py index d89897f8d..0add32ce1 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -845,15 +845,6 @@ def set_view_status(self, view: sublime.View, message: str) -> None: def erase_view_status(self, view: sublime.View) -> None: view.erase_status(self.status_key) - def match_view(self, view: sublime.View, scheme: str) -> bool: - syntax = view.syntax() - if not syntax: - return False - selector = self.selector.strip() - if not selector: - return False - return scheme in self.schemes and sublime.score_selector(syntax.scope, selector) > 0 - def map_uri_on_payload(self, payload: Any, is_from_client_to_server: bool) -> Any: if isinstance(payload, dict): for k, v in payload.items(): @@ -871,6 +862,15 @@ def map_uri_on_payload(self, payload: Any, is_from_client_to_server: bool) -> An payload = path return payload + + def match_view(self, view: sublime.View, scheme: str) -> bool: + syntax = view.syntax() + if not syntax: + return False + selector = self.selector.strip() + if not selector: + return False + return scheme in self.schemes and sublime.score_selector(syntax.scope, selector) > 0 def map_client_path_to_server_uri(self, path: str) -> str: return self.map_uri_on_payload(filename_to_uri(path), is_from_client_to_server=True) From fc1e0d2a0fa359558a0b2779563732e55f2c9311 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Sun, 22 Dec 2024 20:11:50 +0800 Subject: [PATCH 17/20] Update types.py --- plugin/core/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/core/types.py b/plugin/core/types.py index 0add32ce1..a5371eb7e 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -871,7 +871,7 @@ def match_view(self, view: sublime.View, scheme: str) -> bool: if not selector: return False return scheme in self.schemes and sublime.score_selector(syntax.scope, selector) > 0 - + def map_client_path_to_server_uri(self, path: str) -> str: return self.map_uri_on_payload(filename_to_uri(path), is_from_client_to_server=True) From e77be171f89ac2cc0e6f58edbb121480fa73d1f4 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Mon, 23 Dec 2024 12:32:26 +0800 Subject: [PATCH 18/20] Update types.py --- plugin/core/types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/core/types.py b/plugin/core/types.py index a5371eb7e..0bde33dc3 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -854,13 +854,13 @@ def map_uri_on_payload(self, payload: Any, is_from_client_to_server: bool) -> An for i, v in enumerate(payload): payload[i] = self.map_uri_on_payload(v, is_from_client_to_server) - if isinstance(payload, str) and payload.startswith("file://"): + if isinstance(payload, str) and payload.startswith("file://"): for path_map in self.path_maps: path, mapped = path_map.map_from_local_to_remote(payload) if is_from_client_to_server else \ path_map.map_from_remote_to_local(payload) if mapped: payload = path - + return payload def match_view(self, view: sublime.View, scheme: str) -> bool: From e22f8324a34b5298b71e0195537b19cb214a8467 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Mon, 23 Dec 2024 18:19:54 +0800 Subject: [PATCH 19/20] Update types.py --- plugin/core/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/core/types.py b/plugin/core/types.py index 0bde33dc3..74c29bd93 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -854,7 +854,7 @@ def map_uri_on_payload(self, payload: Any, is_from_client_to_server: bool) -> An for i, v in enumerate(payload): payload[i] = self.map_uri_on_payload(v, is_from_client_to_server) - if isinstance(payload, str) and payload.startswith("file://"): + if isinstance(payload, str) and payload.startswith("file://") and self.path_maps: for path_map in self.path_maps: path, mapped = path_map.map_from_local_to_remote(payload) if is_from_client_to_server else \ path_map.map_from_remote_to_local(payload) From 0057794141ad48bdee46b7e74d445f19a2c0e5d6 Mon Sep 17 00:00:00 2001 From: 95833 <987004590@qq.com> Date: Mon, 23 Dec 2024 18:38:22 +0800 Subject: [PATCH 20/20] Update test_configs.py --- tests/test_configs.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_configs.py b/tests/test_configs.py index ef1e2ea94..b2fa610bd 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -145,12 +145,12 @@ def test_path_maps(self): "selector": "source.foo", "path_maps": [ { - "local": "/home/user/projects/myproject", - "remote": "/workspace" + "local": "file:///home/user/projects/myproject", + "remote": "file:///workspace" }, { - "local": "/home/user/projects/another", - "remote": "/workspace2" + "local": "file:///home/user/projects/another", + "remote": "file:///workspace2" } ] })