For more advanced completion you can extend LSP package,
here’s an example
import weakref
from .core.protocol import Request, SymbolInformation, SymbolTag
from .core.registry import LspTextCommand
from .core.typing import Any, List, Tuple, Dict, Union
from .core.views import SYMBOL_KINDS
import os
import sublime
SUPPRESS_INPUT_SETTING_KEY = 'lsp_suppress_input'
def unpack_lsp_kind(kind: int) -> Tuple[int, str, str, str]:
if 1 <= kind <= len(SYMBOL_KINDS):
return SYMBOL_KINDS[kind - 1]
return sublime.KIND_ID_AMBIGUOUS, "?", "???", "comment"
def format_symbol_kind(kind: int) -> str:
if 1 <= kind <= len(SYMBOL_KINDS):
return SYMBOL_KINDS[kind - 1][2]
return str(kind)
def get_symbol_scope_from_lsp_kind(kind: int) -> str:
if 1 <= kind <= len(SYMBOL_KINDS):
return SYMBOL_KINDS[kind - 1][3]
return 'comment'
def symbol_information_to_name(
item: SymbolInformation,
show_file_name: bool = True
) -> str:
st_kind, st_icon, st_display_type, _ = unpack_lsp_kind(item['kind'])
tags = item.get("tags") or []
if SymbolTag.Deprecated in tags:
st_display_type = "⚠ {} - Deprecated".format(st_display_type)
container = item.get("containerName") or ""
details = [] # List[str]
if container:
details.append(container)
if show_file_name:
file_name = os.path.basename(item['location']['uri'])
details.append(file_name)
return item["name"]
class LspWorkspaceSymbolsTwoCommand(LspTextCommand):
capability = 'workspaceSymbolProvider'
def run(self, edit: sublime.Edit, symbol_query_input: str) -> None:
if symbol_query_input:
session = self.best_session(self.capability)
if session:
params = {"query": symbol_query_input}
request = Request("workspace/symbol", params, None, progress=True)
self.weaksession = weakref.ref(session)
session.send_request(request, lambda r: self._handle_response(
symbol_query_input, r), self._handle_error)
def _open_file(self, symbols: List[SymbolInformation], index: int) -> None:
if index != -1:
session = self.weaksession()
if session:
session.open_location_async(symbols[index]['location'], sublime.ENCODED_POSITION)
def _handle_response(self, query: str, response: Union[List[SymbolInformation], None]) -> None:
if response:
matches = response
print(list(map(symbol_information_to_name, matches)))
# window = self.view.window()
# if window:
# window.show_quick_panel(
# list(map(symbol_information_to_quick_panel_item, matches)),
# lambda i: self._open_file(matches, i))
else:
sublime.message_dialog("No matches found for query string: '{}'".format(query))
def _handle_error(self, error: Dict[str, Any]) -> None:
reason = error.get("message", "none provided by server :(")
msg = "command 'workspace/symbol' failed. Reason: {}".format(reason)
sublime.error_message(msg)
run this in command palate to test it out
view.run_command('lsp_workspace_symbols_two', {"symbol_query_input": "Tex"})