def extract_variables(window: sublime.Window) -> dict: variables = window.extract_variables() variables["package"] = core.current_package() project = variables.get('project_path') if project: variables['workspaceFolder'] = project return variables
def extract_variables(window: sublime.Window) -> Dict[str, str]: variables = window.extract_variables() variables["storage_path"] = get_storage_path() variables["cache_path"] = sublime.cache_path() variables["temp_dir"] = tempfile.gettempdir() variables["home"] = os.path.expanduser('~') return variables
def start_client(window: sublime.Window, config: ClientConfig): project_path = get_project_path(window) if project_path is None: return None if settings.show_status_messages: window.status_message("Starting " + config.name + "...") debug("starting in", project_path) # Create a dictionary of Sublime Text variables variables = window.extract_variables() # Expand language server command line environment variables expanded_args = list( sublime.expand_variables(os.path.expanduser(arg), variables) for arg in config.binary_args ) # Override OS environment variables env = os.environ.copy() for var, value in config.env.items(): # Expand both ST and OS environment variables env[var] = os.path.expandvars(sublime.expand_variables(value, variables)) client = start_server(expanded_args, project_path, env) if not client: window.status_message("Could not start " + config.name + ", disabling") debug("Could not start", config.binary_args, ", disabling") return None initializeParams = { "processId": client.process.pid, "rootUri": filename_to_uri(project_path), "rootPath": project_path, "capabilities": { "textDocument": { "completion": { "completionItem": { "snippetSupport": True } }, "synchronization": { "didSave": True } }, "workspace": { "applyEdit": True } } } if config.init_options: initializeParams['initializationOptions'] = config.init_options client.send_request( Request.initialize(initializeParams), lambda result: handle_initialize_result(result, client, window, config)) return client
def start_client(window: sublime.Window, project_path: str, config: ClientConfig): if config.name in client_start_listeners: handler_startup_hook = client_start_listeners[config.name] if not handler_startup_hook(window): return if settings.show_status_messages: window.status_message("Starting " + config.name + "...") debug("starting in", project_path) # Create a dictionary of Sublime Text variables variables = window.extract_variables() # Expand language server command line environment variables expanded_args = list( sublime.expand_variables(os.path.expanduser(arg), variables) for arg in config.binary_args) # Override OS environment variables env = os.environ.copy() for var, value in config.env.items(): # Expand both ST and OS environment variables env[var] = os.path.expandvars( sublime.expand_variables(value, variables)) # TODO: don't start process if tcp already up or command empty? process = start_server(expanded_args, project_path, env) if not process: window.status_message("Could not start " + config.name + ", disabling") debug("Could not start", config.binary_args, ", disabling") return None if config.tcp_port is not None: client = attach_tcp_client(config.tcp_port, process, settings) else: client = attach_stdio_client(process, settings) if not client: window.status_message("Could not connect to " + config.name + ", disabling") return None return client
def get_window_env(window: sublime.Window, config: ClientConfig): # Create a dictionary of Sublime Text variables variables = window.extract_variables() # Expand language server command line environment variables expanded_args = list( sublime.expand_variables(os.path.expanduser(arg), variables) for arg in config.binary_args) # Override OS environment variables env = os.environ.copy() for var, value in config.env.items(): # Expand both ST and OS environment variables env[var] = os.path.expandvars( sublime.expand_variables(value, variables)) return expanded_args, env
def get_window_env(window: sublime.Window, config: ClientConfig): # Create a dictionary of Sublime Text variables variables = window.extract_variables() # Expand language server command line environment variables expanded_args = list( sublime.expand_variables(os.path.expanduser(arg), variables) for arg in config.binary_args ) # Override OS environment variables env = os.environ.copy() for var, value in config.env.items(): # Expand both ST and OS environment variables env[var] = os.path.expandvars(sublime.expand_variables(value, variables)) return expanded_args, env
def start_client(window: sublime.Window, project_path: str, config: ClientConfig): if config.name in client_start_listeners: handler_startup_hook = client_start_listeners[config.name] if not handler_startup_hook(window): return if settings.show_status_messages: window.status_message("Starting " + config.name + "...") debug("starting in", project_path) # Create a dictionary of Sublime Text variables variables = window.extract_variables() # Expand language server command line environment variables expanded_args = list( sublime.expand_variables(os.path.expanduser(arg), variables) for arg in config.binary_args ) # Override OS environment variables env = os.environ.copy() for var, value in config.env.items(): # Expand both ST and OS environment variables env[var] = os.path.expandvars(sublime.expand_variables(value, variables)) # TODO: don't start process if tcp already up or command empty? process = start_server(expanded_args, project_path, env) if not process: window.status_message("Could not start " + config.name + ", disabling") debug("Could not start", config.binary_args, ", disabling") return None if config.tcp_port is not None: client = attach_tcp_client(config.tcp_port, process, settings) else: client = attach_stdio_client(process, settings) if not client: window.status_message("Could not connect to " + config.name + ", disabling") return None return client
def __init__(self, window: sublime.Window) -> None: self.window = window try: self.__data = window.project_data()["settings"]["cmake"] except Exception: default = get_setting(window.active_view(), "default_build_folder", "$folder/build") self.__data = {"build_folder": default} self.unexpanded_build_folder = self.__get_val( "build_folder") # type: str self.__data = expand(window, self.__data) self.build_folder = self.__get_val("build_folder") # type: str self.working_dir = self.__get_val("root_folder") # type: str if self.working_dir: self.working_dir = realpath(self.working_dir) else: try: self.working_dir = window.extract_variables()["folder"] except KeyError: self.working_dir = "" if not isfile(join(self.working_dir, "CMakeLists.txt")): raise FileNotFoundError()
def start_client(window: sublime.Window, config: ClientConfig): project_path = get_project_path(window) if project_path is None: return None if settings.show_status_messages: window.status_message("Starting " + config.name + "...") debug("starting in", project_path) # Create a dictionary of Sublime Text variables variables = window.extract_variables() # Expand language server command line environment variables expanded_args = list( sublime.expand_variables(os.path.expanduser(arg), variables) for arg in config.binary_args ) # Override OS environment variables env = os.environ.copy() for var, value in config.env.items(): # Expand both ST and OS environment variables env[var] = os.path.expandvars(sublime.expand_variables(value, variables)) # TODO: don't start process if tcp already up or command empty? process = start_server(expanded_args, project_path, env) if not process: window.status_message("Could not start " + config.name + ", disabling") debug("Could not start", config.binary_args, ", disabling") return None if config.tcp_port is not None: client = attach_tcp_client(config.tcp_port, process, project_path) else: client = attach_stdio_client(process, project_path) if not client: window.status_message("Could not connect to " + config.name + ", disabling") return None client.set_crash_handler(lambda: handle_server_crash(window, config)) initializeParams = { "processId": os.getpid(), "rootUri": filename_to_uri(project_path), "rootPath": project_path, "capabilities": { "textDocument": { "synchronization": { "didSave": True }, "hover": { "contentFormat": ["markdown", "plaintext"] }, "completion": { "completionItem": { "snippetSupport": True, "documentationFormat": ["plaintext"] }, "completionItemKind": { "valueSet": [ CompletionItemKind.Text, CompletionItemKind.Method, CompletionItemKind.Function, CompletionItemKind.Constructor, CompletionItemKind.Field, CompletionItemKind.Variable, CompletionItemKind.Class, CompletionItemKind.Interface, CompletionItemKind.Module, CompletionItemKind.Property, CompletionItemKind.Unit, CompletionItemKind.Value, CompletionItemKind.Enum, CompletionItemKind.Keyword, CompletionItemKind.Snippet, CompletionItemKind.Color, CompletionItemKind.File, CompletionItemKind.Reference ] } }, "signatureHelp": { "signatureInformation": { "documentationFormat": ["markdown", "plaintext"] } }, "references": {}, "documentHighlight": {}, "documentSymbol": { "symbolKind": { "valueSet": [ SymbolKind.File, SymbolKind.Module, SymbolKind.Namespace, SymbolKind.Package, SymbolKind.Class, SymbolKind.Method, SymbolKind.Property, SymbolKind.Field, # SymbolKind.Constructor, # SymbolKind.Enum, SymbolKind.Interface, SymbolKind.Function, SymbolKind.Variable, SymbolKind.Constant # SymbolKind.String, # SymbolKind.Number, # SymbolKind.Boolean, # SymbolKind.Array ] } }, "formatting": {}, "rangeFormatting": {}, "definition": {}, "codeAction": {}, "rename": {} }, "workspace": { "applyEdit": True, "didChangeConfiguration": {} } } } if config.init_options: initializeParams['initializationOptions'] = config.init_options client.send_request( Request.initialize(initializeParams), lambda result: handle_initialize_result(result, client, window, config)) return client
def expand(window: sublime.Window, d) -> 'Any': return sublime.expand_variables(d, window.extract_variables())