Skip to content

Commit

Permalink
Version 0.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrorgirardi committed Nov 4, 2023
2 parents 1d38f47 + a26ce00 commit ec18b8a
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 100 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Pep.sublime-workspace
.clj-kondo
.vscode
.cpcache
.idea/
.idea/
.ruff_cache
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to this project will be documented in this file.

## 0.20.0 - 2023-11-04
New:
- [Command to Toggle View Annotations #70](https://github.com/pedrorgirardi/Pep/issues/70)

Breaking:
- Removed Command `PgPepClearAnnotationsCommand`
- Removed Command `PgPepAnnotateCommand`
- Removed Commands `PgPepClearHighlightedCommand` and `PgPepToggleHighlightCommand`
- Removed Command `PgPepViewNamespaceStatusCommand` and its settings:
- `view_status_show_namespace`
- `view_status_show_namespace_prefix`
- `view_status_show_namespace_suffix`

## 0.19.0 - 2023-10-31
There were many internal changes in this version and I'm sorry I made some breaking changes.

Expand Down
12 changes: 2 additions & 10 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,8 @@
"command": "pg_pep_analyze"
},
{
"caption": "Pep: Annotate View",
"command": "pg_pep_annotate"
},
{
"caption": "Pep: Clear View Annotations",
"command": "pg_pep_clear_annotations"
},
{
"caption": "Pep: Toggle Highlighting",
"command": "pg_pep_toggle_highlight"
"caption": "Pep: Toggle View Annotations",
"command": "pg_pep_toggle_view_annotations"
},
{
"caption": "Pep: Outline",
Expand Down
10 changes: 0 additions & 10 deletions Pep.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
// (Doesn't do anything if there isn't a *.sublime-project file.)
"analyze_classpath_on_load_project": true,


// True if warnings/errors should be displayed right after the analysis is completed.
// It's a 'tighter feedback loop' to display warnings/errors after the analysis, but some might find it distracting.
"annotate_view_after_analysis": false,
Expand All @@ -52,15 +51,6 @@
// True if you would like to see the number of clj-kondo warnings, if any, in the status bar.
"view_status_show_warnings": false,

// True if you would like to show the namespace of the view in the status bar.
"view_status_show_namespace": false,

// If you would like to add a custom prefix to the namespace of the view in the status bar.
"view_status_show_namespace_prefix": "Namespace: ",

// If you would like to add a custom suffix to the namespace of the view in the status bar.
"view_status_show_namespace_suffix": "",

// True if you would like to see the number of highlighted regions in the status bar.
"view_status_show_highlighted": false,

Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
| Command | Description |
| ------- | ----------- |
| `pg_pep_analyze` | Analyze view, paths or classpath |
| `pg_pep_browse_classpath` | Go to anything in the classpath |
| `pg_pep_outline` | Show symbols defined in the namespace - it might also be known as 'file structure' |
| `pg_pep_goto_anything` | Go to anything in view or paths |
| `pg_pep_goto_anything_in_classpath` | Go to anything in the classpath |
| `pg_pep_goto_anything_in_view_paths` | Go to anything in view or paths |
| `pg_pep_goto_namespace` | Go to namespace in paths |
| `pg_pep_goto_definition` | Go to definition of symbol or keyword under the cursor |
| `pg_pep_goto_warning_error_in_view` | Go to clj-kondo analysis finding (warning or error) |
Expand All @@ -21,8 +21,6 @@
| `pg_pep_select` | Select occurrences of symbol or keyword under the cursor |
| `pg_pep_replace` | Replace occurrences of symbol or keyword under the cursor |
| `pg_pep_highlight` | Highlight occurrences of symbol or keyword under the cursor |
| `pg_pep_annotate_view` | Annotate view (show warnings/errors) |
| `pg_pep_clear_view_annotations` | Clear view annotations |
| `pg_pep_copy_name` | Copy name of keyword or symbol to the clipboard |
| `pg_pep_show_name` | Show name of keyword or symbol in a popup |

Expand Down
5 changes: 3 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{:deps {org.clojure/clojure {:mvn/version "1.11.0"}
org.clojure/clojurescript {:mvn/version "1.10.879"}}}
{:deps
{org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/clojurescript {:mvn/version "1.11.121"}}}
88 changes: 15 additions & 73 deletions pep.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
# Setting used to override the clj-kondo config for a view analysis.
S_PEP_CLJ_KONDO_CONFIG = "pep_clj_kondo_config"

# Setting used to toggle a view's annotations.
S_PEP_ANNOTATE_VIEW = "pep_annotate_view"

# Configuration shared by paths and view analysis - without a common configuration the index would be inconsistent.
CLJ_KONDO_VIEW_PATHS_ANALYSIS_CONFIG = "{:var-definitions true, :var-usages true, :arglists true, :locals true, :keywords true, :symbols true, :java-class-definitions false, :java-class-usages true, :java-member-definitions false, :instance-invocations true}"
CLJ_KONDO_CLASSPATH_ANALYSIS_CONFIG = "{:var-usages false :var-definitions {:shallow true} :arglists true :keywords true :java-class-definitions false}"
Expand All @@ -74,7 +77,7 @@ def af_annotate(context, analysis):
"""
Analysis Function to annotate view.
Depends on setting to annotate on save.
Depends on setting to annotate view after analysis.
"""
if view := context["view"]:
if annotate_view_after_analysis(view.window()):
Expand Down Expand Up @@ -109,20 +112,11 @@ def af_status_summary(context, analysis):
view.run_command("pg_pep_view_summary_status")


def af_status_namespace(context, analysis):
"""
Analysis Function to show a view's namespace in the status bar.
"""
if view := context["view"]:
view.run_command("pg_pep_view_namespace_status")


# Default functions to run after analysis.
DEFAULT_VIEW_ANALYSIS_FUNCTIONS = [
af_annotate,
af_highlight_thingy,
af_status_summary,
af_status_namespace,
]


Expand Down Expand Up @@ -2761,6 +2755,13 @@ def finding_minihtml(finding):
</body>
"""

# Erase regions from previous analysis.
erase_analysis_regions(view)

# Skip annotation if view explicitly set the custom setting to disable it.
if view.settings().get(S_PEP_ANNOTATE_VIEW) is False:
return

analysis = view_analysis(view.id())

findings = analysis_findings(analysis)
Expand All @@ -2779,9 +2780,6 @@ def finding_minihtml(finding):
warning_region_set.append(finding_region(finding))
warning_minihtml_set.append(finding_minihtml(finding))

# Erase regions from previous analysis.
erase_analysis_regions(view)

redish = view.style_for_scope("region.redish").get("foreground")
orangish = view.style_for_scope("region.orangish").get("foreground")

Expand Down Expand Up @@ -4106,25 +4104,12 @@ def run(self, edit):
highlight_thingy(self.view)


class PgPepClearHighlightedCommand(sublime_plugin.TextCommand):
class PgPepToggleViewAnnotationsCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.erase_regions(HIGHLIGHTED_REGIONS_KEY)
self.view.set_status(HIGHLIGHTED_STATUS_KEY, "")
# Is enabled by default:
annotate = self.view.settings().get(S_PEP_ANNOTATE_VIEW, True)


class PgPepToggleHighlightCommand(sublime_plugin.TextCommand):
def __init__(self, view):
self.view = view
self.is_toggled = (
True if self.view.get_regions(HIGHLIGHTED_REGIONS_KEY) else False
)

def run(self, edit):
self.view.run_command(
"pg_pep_clear_highlighted" if self.is_toggled else "pg_pep_highlight"
)

self.is_toggled = not self.is_toggled
self.view.settings().set(S_PEP_ANNOTATE_VIEW, not annotate)


class PgPepViewSummaryStatusCommand(sublime_plugin.TextCommand):
Expand All @@ -4144,9 +4129,6 @@ def run(self, edit):

status_message = ", ".join(status_messages) if status_messages else ""

if status_message:
status_message = "⚠ " + status_message

# Show the number of errors and/or warnings.
# (Setting the value to the empty string will clear the status.)
self.view.set_status("pg_pep_view_summary", status_message)
Expand All @@ -4155,46 +4137,6 @@ def run(self, edit):
print("Pep: Error: PgPepViewSummaryStatusCommand", traceback.format_exc())


class PgPepViewNamespaceStatusCommand(sublime_plugin.TextCommand):
def run(self, edit):
try:
analysis = view_analysis(self.view.id())

view_namespace = ""

if view_status_show_namespace(self.view.window()):
# It's possible to get the namespace wrong since it's a list of definitions,
# but it's unlikely because of the scope (view) of the analysis.
if namespaces := list(analysis_nindex(analysis).keys()):
namespace_prefix = (
view_status_show_namespace_prefix(self.view.window()) or ""
)

namespace_suffix = (
view_status_show_namespace_suffix(self.view.window()) or ""
)

view_namespace = namespace_prefix + namespaces[0] + namespace_suffix

self.view.set_status("pg_pep_view_namespace", view_namespace)

except Exception:
print("Pep: Error: PgPepViewNamespaceStatusCommand", traceback.format_exc())


class PgPepClearAnnotationsCommand(sublime_plugin.TextCommand):
def run(self, edit):
erase_analysis_regions(self.view)


class PgPepAnnotateCommand(sublime_plugin.TextCommand):
def run(self, edit):
try:
annotate_view(self.view)
except Exception:
print("Pep: Error: PgPepAnnotateCommand", traceback.format_exc())


# ---


Expand Down
3 changes: 3 additions & 0 deletions tests/example.clj
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ x
(foo 1)

(foo 1)

;; TODO: It should highlight `foo` too.
'example/foo
10 changes: 10 additions & 0 deletions tests/symbols.clj
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
;; Problem:
;; Pep finds usages of these symbols in paths,
;; but from a var it doesn't find a symbol.
;;
;; Solution:
;; Searching for usages of symbol or var should
;; also include symbols.
;;
;; See https://github.com/pedrorgirardi/Pep/issues/68

'clojure.core/map

'example/foo
Expand Down

0 comments on commit ec18b8a

Please sign in to comment.