cursive-ide / cursive

Cursive: The IDE for beautiful Clojure code
588 stars 7 forks source link

Highlight the same symbols #1799

Open metametadata opened 7 years ago

metametadata commented 7 years ago

I think it would be logical if IDE highlighted the same symbols in the file, similarly to keywords (i.e. when the cursor is over the keyword all the occurrences of this keyword are highlighted in current editor tab).

I'm thinking about moving from using keywords to symbols in the specific part of the codebase and would definitely benefit from such feature.

a613 commented 7 years ago

I don't know about on hover, but I have my editor set up so when I click on a symbol it is highlighted throughout the file in bright yellow.

screen shot 2017-09-25 at 12 42 36 pm screen shot 2017-09-25 at 12 43 30 pm
metametadata commented 7 years ago

Yes, this is what I need, but unfortunately the IDE doesn't yet highlight the same Clojure symbols starting with ', e.g. the same 'foo "token" will not be highlighted everywhere when under caret.

cursive-ide commented 7 years ago

@metametadata So the issue is that they're not highlighted when quoted?

metametadata commented 7 years ago

@cursive-ide exactly. Some context: for my exotic use case I need something resembling keywords but also having metadata. So that instead of :foo keyword I would use 'foo symbol. And to make it usable I'd like IDE to highlight same 'foo symbols in the same fashion it would highlight same :foo keywords.

metametadata commented 6 years ago

Still very interested in this landing.

pmoriarty commented 6 years ago

Hi,

This is just a suggestion. I had taken a similar approach when I found I wanted to add metadata to keywords. Later, I found using Vars instead of symbols to be more useful as it fits better with Cursive's navigation, refactoring and documentation lookup support.

(def ^{:some :metadata} foo "foo documentation" 'foo)

Then use #'foo where you use 'foo now and IDEA will highlight usages, navigate from usages to the definition and show documentation with the View -> Quick Documentation function.

Of course, this may not fit your needs if your metadata isn't static.

Paudi

On Wed, 23 May 2018 at 23:12 Yuri Govorushchenko notifications@github.com wrote:

Still very interested in this landing.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cursive-ide/cursive/issues/1799#issuecomment-391513304, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFh8rbDTRvKwmEgDcK4poLHL-sqBdkcks5t1d7VgaJpZM4ORtxE .

metametadata commented 6 years ago

@pmoriarty thank you for a suggestion. I could take this approach but in the specific case I have I'd really like to compress the number of lines of code and not define any new symbols.

In unit tests I use "metaconsts" a lot, i.e. instead of some-real-data I often can pass :--keywords-- around without breaking a test scenario when implemetation doesn't care about data content. Simple pseudo example:

(deftest logic-layer-adds-item-via-db-layer
    (let [db (fake-add-db :--item-to-add-- :--added-item--)
          logic (->Logic db)]
      (is (= :--added-item-- (add logic :--item-to-add--)))))

The next idea is to preserve this approach for testing functions with specs/schemas defined for args and return values. E.g. I managed to patch Schema lib so that I can write tests with "metaconsts with schema hints". Type hints are attached to metaconsts using << helper. So that if [patched] Schema validator encounters a value which has a schema hint in metadata then it doesn't look at the actual value content and just "believes" it is of the type declared in metadata. Example:

; Now db and logic layers have Schemas attached to arguments and return values
(deftest logic-layer-adds-item-via-db-layer
    (let [db (fake-add-db (<< '--item-to-add-- ItemToAddSchema) (<< '--added-item-- ItemSchema))
          logic (->Logic db)]
      ; Note that I don't have to schema hint '--added-item-- here because 
      ; (<< '--added-item-- ItemSchema) == '--added-item--
      (is (= '--added-item-- (add logic (<< '--item-to-add-- ItemSchema))))))

So this is why I need highlighting - to be able to read the tests cases like this easier.

I could use keywords with this trick instead to get the highlighting. But the tests are more noisey then since I'd need to wrap every metaconst with (<< ...) because keywords don't have metadata.

Edit: I should add it depends on the test and sometimes it can be worthwhile to extract item-to-add, etc. as local vars for readibility even though it adds an additional line to test.

metametadata commented 3 months ago

Update: I no longer need such a feature. Instead of '--added-item-- I write (! --added-item--) (! is a function).

But such highlighting seems reasonable, so I'm not sure the issue should be closed.