diff --git a/docs/src/features.md b/docs/src/features.md index 3f4c09dce..77cbf6cb3 100644 --- a/docs/src/features.md +++ b/docs/src/features.md @@ -34,7 +34,7 @@ In addition to the basic "Goto Definition", the protocol also provides further r Additionally, the LSP's "Goto Definition" command can fall back to the built-in Sublime's "Goto Definition" if the `fallback` argument is set to `true`. This way, when there are no results found the built-in "Goto Definition" command will be triggered. -To always open the results in a certain group, you can use the `group` argument. +To attempt to open the results in a certain group, you can use the `group` argument. If the specified `group` does not exist, then it will be ignored. ## Find References diff --git a/plugin/core/open.py b/plugin/core/open.py index 5fb8eea9f..058463665 100644 --- a/plugin/core/open.py +++ b/plugin/core/open.py @@ -15,16 +15,15 @@ opening_files = {} # type: Dict[str, Tuple[Promise[Optional[sublime.View]], ResolveFunc[Optional[sublime.View]]]] -def _return_existing_view(flags: int, existing_view_group: int, active_group: int, specified_group: int) -> bool: +def _return_existing_view(flags: int, is_view_in_active_group: bool, specified_group: int) -> bool: # the specified_group is supplied if specified_group > -1: - # use existing_view_group if it is in the active group - return existing_view_group == active_group + return is_view_in_active_group # open side by side if bool(flags & (sublime.ADD_TO_SELECTION | sublime.REPLACE_MRU)): return False - # existing view is in active group ( no group is specified and not side by side ) - if existing_view_group == active_group: + # view is in active group ( no group is specified and not side by side ) + if is_view_in_active_group: return True # Jump to the file if sublime.FORCE_GROUP is not set return not bool(flags & sublime.FORCE_GROUP) @@ -42,12 +41,8 @@ def open_file( # window.open_file brings the file to focus if it's already opened, which we don't want (unless it's supposed # to open as a separate view). view = window.find_open_file(file) - if view: - return_existing_view = _return_existing_view( - flags, window.get_view_index(view)[0], window.active_group(), group - ) - if return_existing_view: - return Promise.resolve(view) + if view and _return_existing_view(flags, window.get_view_index(view)[0] == window.active_group(), group): + return Promise.resolve(view) view = window.open_file(file, flags, group) if not view.is_loading(): diff --git a/plugin/goto.py b/plugin/goto.py index 9661a081c..52743a779 100644 --- a/plugin/goto.py +++ b/plugin/goto.py @@ -23,7 +23,8 @@ def is_enabled( point: Optional[int] = None, side_by_side: bool = False, force_group: bool = True, - fallback: bool = False + fallback: bool = False, + group: int = -1 ) -> bool: return fallback or super().is_enabled(event, point)