From 7d35ad1c589f2bdcc75168c2c010c868e9f13218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aziz=20K=C3=B6ksal?= Date: Mon, 1 May 2023 20:12:05 +0200 Subject: [PATCH 1/5] SQL: recognize `FILTER (...)` --- syntaxes/SQL (Elixir).sublime-syntax | 2 +- tests/syntax_test_sql.ex.sql | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/syntaxes/SQL (Elixir).sublime-syntax b/syntaxes/SQL (Elixir).sublime-syntax index 2957d8e2..b1c997e5 100644 --- a/syntaxes/SQL (Elixir).sublime-syntax +++ b/syntaxes/SQL (Elixir).sublime-syntax @@ -21,7 +21,7 @@ contexts: all|any|array|analy[sz]e|a?symmetric|authorization|at(?=\s+time\s+zone\b)|binary|both|by | (?<=\bat\s)time(?=\s+zone\b) | (?<=\btime\s)zone | (?<=\bdo\s)nothing | (?<=\bon\s)conflict | (?<=\bwith\s)ordinality | cast|cross|column|concurrently|collat(?:e|ion)|create|distinct|(? Date: Mon, 1 May 2023 20:10:58 +0200 Subject: [PATCH 2/5] Commands: improvements to mix_format panel. * Added create_mix_format_panel() function. * Auto-scroll output every 2 sec. * Output a timestamp. * Destroy the panel when error-free. --- commands/mix_format.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/commands/mix_format.py b/commands/mix_format.py index 1b8b1027..addbe98f 100644 --- a/commands/mix_format.py +++ b/commands/mix_format.py @@ -3,6 +3,8 @@ import subprocess import shlex from .utils import * +from time import time as now +from datetime import datetime __author__ = 'Aziz Köksal' __email__ = 'aziz.koeksal@gmail.com' @@ -87,25 +89,40 @@ def call_mix_format(window, **kwargs): window.run_command('erase_view', panel_params) output_view = None + past_timestamp = now() + panel_update_interval = 2 + while proc.poll() is None: stderr_line = proc.stderr.readline().decode(encoding='UTF-8') if stderr_line: if not output_view: - first_lines = '$ cd %s && %s\n\n' % (shlex.quote(cwd), ' '.join(map(shlex.quote, cmd))) - output_view = window.create_output_panel(panel_name) - output_view.settings().set('result_file_regex', r'/([^/]+):(\d+):(\d+)') - output_view.set_read_only(False) - output_view.run_command('append', {'characters': first_lines}) + output_view = create_mix_format_panel(window, panel_name, cmd, cwd) window.run_command('show_panel', panel_params) output_view.run_command('append', {'characters': stderr_line}) + if now() - past_timestamp > panel_update_interval: + output_view.show(output_view.size()) + past_timestamp = now() + if output_view: output_view.set_read_only(True) else: if window.active_panel() == panel_params['panel']: window.run_command('hide_panel', panel_params) + window.destroy_output_panel(panel_name) msg = 'Formatted %s %s!' % (file_path and 'file' or 'directory', repr(file_path or cwd)) print_status_msg(msg) + +def create_mix_format_panel(window, panel_name, cmd_args, cwd): + first_lines = '$ cd %s && %s' % (shlex.quote(cwd), ' '.join(map(shlex.quote, cmd_args))) + first_lines += '\n# Timestamp: %s\n\n' % datetime.now().replace(microsecond=0) + + output_view = window.create_output_panel(panel_name) + output_view.settings().set('result_file_regex', r'/([^/]+):(\d+):(\d+)') + output_view.set_read_only(False) + output_view.run_command('append', {'characters': first_lines}) + + return output_view From 9866cd3bb292e295aca809cf3c5b7ba8494842ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aziz=20K=C3=B6ksal?= Date: Tue, 2 May 2023 19:07:29 +0200 Subject: [PATCH 3/5] Commands: pipe stderr to stdout. --- commands/mix_format.py | 8 ++++---- commands/mix_test.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/commands/mix_format.py b/commands/mix_format.py index addbe98f..465252e9 100644 --- a/commands/mix_format.py +++ b/commands/mix_format.py @@ -82,7 +82,7 @@ def call_mix_format(window, **kwargs): ) return - proc = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + proc = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) panel_name = 'mix_format' panel_params = {'panel': 'output.%s' % panel_name} @@ -93,14 +93,14 @@ def call_mix_format(window, **kwargs): panel_update_interval = 2 while proc.poll() is None: - stderr_line = proc.stderr.readline().decode(encoding='UTF-8') + line = proc.stdout.readline().decode(encoding='UTF-8') - if stderr_line: + if line: if not output_view: output_view = create_mix_format_panel(window, panel_name, cmd, cwd) window.run_command('show_panel', panel_params) - output_view.run_command('append', {'characters': stderr_line}) + output_view.run_command('append', {'characters': line}) if now() - past_timestamp > panel_update_interval: output_view.show(output_view.size()) diff --git a/commands/mix_test.py b/commands/mix_test.py index 30e6f7d5..8283f90f 100644 --- a/commands/mix_test.py +++ b/commands/mix_test.py @@ -564,7 +564,7 @@ def write_output(txt): ) return - proc = subprocess.Popen(cmd_args, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + proc = subprocess.Popen(cmd_args, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if output_view: output_view.settings().set('view_id', output_view.id()) From 0312309fdb749d1ae9363d01c906f2e5dcecd403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aziz=20K=C3=B6ksal?= Date: Tue, 2 May 2023 21:14:29 +0200 Subject: [PATCH 4/5] Commands: fixed syntax detection for enabling/disabling commands. (#58) Use scope suffixes instead of syntax file names. --- commands/utils.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/commands/utils.py b/commands/utils.py index f034ec17..92ccf745 100644 --- a/commands/utils.py +++ b/commands/utils.py @@ -21,16 +21,15 @@ def expand_scope_right(view, begin_point, scope): ) return sublime.Region(begin_point, end_point) -def is_one_of_syntaxes(view, syntaxes): - view_syntax_path = view.settings().get('syntax') - return any(basename + '.sublime-syntax' in view_syntax_path for basename in syntaxes) +def has_one_of_scope_suffixes(view, scope_suffixes): + view_scope_suffixes = view.scope_name(0).split(' ')[0].split('.')[1:] + return any(suffix in view_scope_suffixes for suffix in scope_suffixes) def is_elixir_syntax(view): - return is_one_of_syntaxes(view, ['Elixir']) + return has_one_of_scope_suffixes(view, ['elixir']) def is_formattable_syntax(view): - syntaxes = ['Elixir', 'EEx', 'Elixir (EEx)', 'HTML (EEx)', 'HTML (HEEx)', 'HTML (Surface)'] - return is_one_of_syntaxes(view, syntaxes) + return has_one_of_scope_suffixes(view, ['elixir', 'eex', 'heex', 'surface']) def reverse_find_root_folder(bottom_path): bottom_path = Path(bottom_path) From ca2e7c7586e2c24d9ce1e559ad05e4874d14bf92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aziz=20K=C3=B6ksal?= Date: Tue, 2 May 2023 21:38:50 +0200 Subject: [PATCH 5/5] CHANGELOG: releasing v3.2.0 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ae30ed5..3c1b0598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [v3.2.0] – 2023-05-02 + +- Commands: improved/generalized syntax detection for enabling/disabling commands. +- Commands: fix: output both stdout/stderr when running `mix format`/`mix test`. +- Commands: auto-scroll `mix format` output when it's compiling. +- SQL: recognize `FILTER` in `array_agg(x) FILTER (...)`. + ## [v3.1.5] – 2023-04-30 - Elixir: recognize `name` in `defmodule name do end`.