Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for a how-to-debug section in the readme #1

Open
DivineDominion opened this issue Apr 1, 2023 · 8 comments
Open

Request for a how-to-debug section in the readme #1

DivineDominion opened this issue Apr 1, 2023 · 8 comments
Labels
documentation Improvements or additions to documentation

Comments

@DivineDominion
Copy link

This looks great, so I tried the package :)

I mostly have Swift code lying around, so I fired up eglot/tree-sitter-mode/codemetrics in Emacs 28.2.

The annotations in the buffer look very tasty -- but I couldn't get the % to increase e.g. here:

CleanShot 2023-04-01 at 09 10 31

It's likely because the function itself returns a closure, and so it appears to 'exit early'. But all the complexity is inside the returned closure. That's my guess because this works:

CleanShot 2023-04-01 at 09 13 52

It'd be great if you could add a getting started section to the README to help folks like me troubleshoot this and e.g. inspect the data codemetrics returns. 🙏

@jcs090218
Copy link
Member

I agreed. I will find some time and update the README. Thanks for the advice! 👍

Here is the short answer for debugging,

  1. (setq codemetrics--show-log t) to see more logs (weather is is useful or not)
  2. M-x codemetrics-debug-mode, it will show depth and score instead of the result (overlays, must use with codemetrics-mode)
  3. Use these functions to see the data codemetrics returns:
  • codemetrics-buffer
  • codemetrics-region
  • codemetrics-analyze

You can use it this way:

(defun my-print-codemetrics-data ()
  "..."
  (interactive)
  (message "%s" (codemetrics-region)))

Then M-x my-print-codemetrics-data the function.

@jcs090218 jcs090218 added the documentation Improvements or additions to documentation label Apr 1, 2023
@konrad1977
Copy link

Does it matter which version of tree-sitter we are using? I am also using Swift but I could only see the overlay in one of my files. I am using this parser for Swift. Its much faster than the Alex Pinkus version https://gitlab.com/woolsweater/tree-sitter-swifter

@konrad1977
Copy link

I got so inspired by your package @jcs090218 so I wrote something like this but for references in code.

Skärmavbild 2023-04-03 kl  08 06 20

@jcs090218
Copy link
Member

Does it matter which version of tree-sitter we are using? I am also using Swift but I could only see the overlay in one of my files. I am using this parser for Swift. Its much faster than the Alex Pinkus version https://gitlab.com/woolsweater/tree-sitter-swifter

This package uses tree-sitter.el, so it uses whatever the parser in the upstream package tree-sitter-langs. Someone just opened a thread here so you can build your own parser, see emacs-tree-sitter/tree-sitter-langs#180. :D

I got so inspired by your package @jcs090218 so I wrote something like this but for references in code.

That's so cool! Are you planning to publish as a package? Can't wait to see this in Emacs! 😄

@konrad1977
Copy link

I have a POC version here. Feel free to report bugs. After looking in your code I know that you way more fluent in Elisp than I am. So feel free to suggest changes.
I tried to add some basic findings of variables in local file. I really need to ironing out bugs.

Skärmavbild 2023-04-05 kl  21 10 38

Source Code:
https://github.com/konrad1977/emacs/blob/main/localpackages/overlay-usage.el

@jcs090218
Copy link
Member

jcs090218 commented Apr 5, 2023

Thanks for sharing! 🚀 ❤️

I might create another package for this, fake-ref-mode, local-ref-mode, etc. It looks very cool! :D

TBH, I am not very good with Swift, so feel free to debug and change the rule sets for your favorite languages. 😅

@konrad1977
Copy link

I am using regex only, tree-sitter would be much more accurate. But it only knows about the current structure, correct? We need LSP support to actually understand that one symbol belongs to the correct object.

What will fake-ref-mode, local-ref-mode do?

@jcs090218
Copy link
Member

It depends on how you create the tool. If we are using tree-sitter, parsing the whole project wouldn't be an issue (it still depends on your project size, time complexity is O(n)). Then we can create IDE like experience (not LSP). For LSP implementation, we can see Emacs Elsa's elsa-lsp.el.

My intention here is to bring up the idea, and this idea is definitely possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants