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

Improve the use of semantic #11511

Closed
wants to merge 5 commits into from
Closed

Conversation

bet4it
Copy link
Contributor

@bet4it bet4it commented Oct 26, 2018

This pull request has the same effects as #9354, except that it works globally rather that only works in emacs-lisp-mode, and it's more clear what we have done and what we will lose.
Other language layers are well configured in spacemacs, so I don't think we need semantic to search system databases for them.

As what has been described in #7736 (comment), the setting in #7736 has been overrided by mode local variables and has no effects. So I revert it.

Resolve #1907.

@bet4it
Copy link
Contributor Author

bet4it commented Nov 4, 2018

#7736 has disabled many good features semantic can provide, such as:
semantic
semantic can help us complete library functions, and it's handy especially for small projects which I don't want to enable large completion tools such as rtags or lsp. The most important thing is that it's a built-in module in emacs.
So I add company-semantic to company-backends.

semantic-idle-summary-mode is conflict with gtags so we should disable it when gtags is enabled.

@bet4it bet4it changed the title semantic: Don't let semanticdb search system databases Improve the use of semantic Nov 4, 2018
;; Disable semantic-idle-summary when use gtags layer.
;; Gtags provides more useful information but can not do it properly
;; when this mode is enabled since the minibuffer is cleared all the time."
(defun spacemacs//disable-semantic-idle-summary-mode ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function can be extracted to semantic layer. Since it's being used in multiple layers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Is it proper to put it into semantic's packages.el?

layers/+lang/python/packages.el Outdated Show resolved Hide resolved
@duianto
Copy link
Collaborator

duianto commented May 4, 2019

And can you add entries for the changes to the changelog.develop.

@duianto duianto self-assigned this May 4, 2019
@duianto
Copy link
Collaborator

duianto commented May 4, 2019

In the changelog:

  • Changed the default throttle for =semanticdb-find= routines. Always don't
    search system databases to speed up semantic (thanks to bet4it)

I'm guessing that the first word in the second sentence: "Always" was a typo, since the commit just says:

Don't let semanticdb search system databases

I fixed it.

@duianto
Copy link
Collaborator

duianto commented May 4, 2019

Thank you for contributing to Spacemacs!
The PR has been cherry-picked into the develop branch, you can safely delete your branch.

@bet4it
Copy link
Contributor Author

bet4it commented May 4, 2019

If semantic layer and lsp layer is both enabled, and when semantic want to read the C header file to do completion, lsp will ask us how to deal with the header file ( Import project or not ). Not sure who should have a change to fix it.

@duianto
Copy link
Collaborator

duianto commented May 4, 2019

@yyoncho might be able to help, s/he seems to be part of the lsp-mode team.

IMO better names are the lsp-mode server ids. And just a heads up - at some point, we(lsp-mode team) will provide and option to manage the server priorities using variables so ideally, this configuration should disappear.

source: #11913 (comment)

@yyoncho
Copy link
Contributor

yyoncho commented May 4, 2019

@bet4it this seems to be a semantic bug(it runs the major mode hooks for the files that it opens temporary but I need a callstack to confirm that, you may do M-x debug-on-entry and post the callstack). You may workaround the issue by blacklisting the folder.

@yyoncho
Copy link
Contributor

yyoncho commented May 4, 2019

@duianto feel free to CC me for lsp related stuff.

@bet4it
Copy link
Contributor Author

bet4it commented May 5, 2019

@yyoncho This is the callstack:

  lsp--find-root-interactively(#s(lsp-session :folders ("/usr/include/lldb/" "/usr/include/bits/" "/usr/include/llvm/Support/" "/usr/include/c++/8.2.1/" ") :folders-blacklist nil :server-id->folders #<hash-table equal 0/65 0x242a86d> :folder->servers #<hash-table equal 1/65 0x242aa9d> :metadata #<hash-table equal 0/65 0x242aabd>))
  lsp--calculate-root(#s(lsp-session :folders ("/usr/include/lldb/" "/usr/include/bits/" "/usr/include/llvm/Support/" "/usr/include/c++/8.2.1/") :folders-blacklist nil :server-id->folders #<hash-table equal 0/65 0x242a86d> :folder->servers #<hash-table equal 1/65 0x242aa9d> :metadata #<hash-table equal 0/65 0x242aabd>) "/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/stddef.h")
  lsp--try-project-root-workspaces(nil nil)
  lsp()
  (lambda nil (if (memql (function company-lsp) company-backends) (with-no-warnings company-backends) (setq company-backends (cons (function company-lsp) company-backends))) (require (quote ccls)) (remhash (quote clangd) lsp-clients) (lsp))()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook c-mode-common-hook c-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook c-mode-common-hook c-mode-hook))
  run-mode-hooks(c-mode-hook)
  c-mode()
  set-auto-mode-0(c-mode nil)
  set-auto-mode()
  normal-mode(t)
  after-find-file(nil nil)
  find-file-noselect-1(#<buffer stddef.h> "/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/stddef.h" t nil "/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/stddef.h" (2640408 66310))
  find-file-noselect("/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/stddef.h" t nil nil)
  semantic-find-file-noselect("/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/stddef.h" t)
  semanticdb-create-table-for-file-not-in-buffer("/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/stddef.h")
  semanticdb-file-table-object("/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/stddef.h")
  semanticdb-find-load-unloaded-default("/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/stddef.h")
  semanticdb-find-load-unloaded("/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/stddef.h")
  semanticdb-find-table-for-include-default(("stddef.h" include (:system-flag t) (dependency-file "/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/stddef.h" :filename "/usr/include/wchar.h") [1157 1176]) #<semanticdb-table semanticdb-table (6 tags), DIRTY>)
  semanticdb-find-table-for-include-c-mode(("stddef.h" include (:system-flag t) (dependency-file "/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/stddef.h" :filename "/usr/include/wchar.h") [1157 1176]) #<semanticdb-table semanticdb-table (6 tags), DIRTY>)
  semanticdb-find-table-for-include(("stddef.h" include (:system-flag t) (dependency-file "/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/include/stddef.h" :filename "/usr/include/wchar.h") [1157 1176]) #<semanticdb-table semanticdb-table (6 tags), DIRTY>)
  semanticdb-find-translate-path-includes--internal(nil)
  semanticdb-find-translate-path-includes-default(nil)
  semanticdb-find-translate-path-default(nil nil)
  semanticdb-find-translate-path(nil nil)
  semanticdb-find-tags-collector(#f(compiled-function (table tags) #<bytecode 0x1b1961d>) nil nil)
  semanticdb-find-tags-by-class(using)
  semantic-ctxt-scoped-types-c++-mode(nil)
  semantic-ctxt-scoped-types()
  semantic-analyze-scoped-types-default(112)
  semantic-analyze-scoped-types(112)
  semantic-calculate-scope(112)
  semantic-analyze-current-context-default(112)
  semantic-analyze-current-context()
  company-semantic(candidates "")
  company--multi-backend-adapter-candidates((company-semantic company-dabbrev-code company-gtags company-etags company-keywords) "" nil)
  company--multi-backend-adapter((company-semantic company-dabbrev-code company-gtags company-etags company-keywords) candidates "")
  apply(company--multi-backend-adapter (company-semantic company-dabbrev-code company-gtags company-etags company-keywords) (candidates ""))
  company-call-backend-raw(candidates "")
  company--fetch-candidates("")
  company-calculate-candidates("" nil)
  company--begin-new()
  company--perform()
  company-auto-begin()
  company-idle-begin(#<buffer semantic.cpp> #<window 3 on *Backtrace*> 67 112)
  apply(company-idle-begin (#<buffer semantic.cpp> #<window 3 on *Backtrace*> 67 112))
  timer-event-handler([t 23758 27816 814117 nil company-idle-begin (#<buffer semantic.cpp> #<window 3 on *Backtrace*> 67 112) nil 132000])

@yyoncho
Copy link
Contributor

yyoncho commented May 5, 2019

@bet4it yes, my guess was correct - semantic should not use find-file-noselect but find-file-literally since it runs the major mode hooks.

@agzam
Copy link
Contributor

agzam commented May 6, 2019

This PR makes me happy beyond limits. Thank you @bet4it !

@captainnova
Copy link

yes, my guess was correct - semantic should not use find-file-noselect but find-file-literally since it runs the major mode hooks.

Hi @yyoncho, thanks for finding that. Has it already been reported to the core emacs developers, since semantic is now in builtin? Unfortunately semantic is still causing problems in emacs 27.2.

@corngood
Copy link
Contributor

semantic-find-file-noselect doesn't seem to have been changed in emacs. I'm having a similar problem with undo-tree now:

Wrote /home/david/.undo-tree/.!nix!store!2dv93bbc06c7zg866qid73j3r36zz3jx-gcc-10.3.0!include!c++!10.3.0!bits!memoryfwd.h.~undo-tree~
Parsing new (LL)...done
Wrote /home/david/.undo-tree/.!nix!store!2dv93bbc06c7zg866qid73j3r36zz3jx-gcc-10.3.0!include!c++!10.3.0!new.~undo-tree~
Parsing alloc_traits.h (LL)...done
Wrote /home/david/.undo-tree/.!nix!store!2dv93bbc06c7zg866qid73j3r36zz3jx-gcc-10.3.0!include!c++!10.3.0!ext!alloc_traits.h.~undo-tree~
Wrote /home/david/.undo-tree/.!nix!store!2dv93bbc06c7zg866qid73j3r36zz3jx-gcc-10.3.0!include!c++!10.3.0!debug!assertions.h.~undo-tree~
Wrote /home/david/.undo-tree/.!nix!store!2dv93bbc06c7zg866qid73j3r36zz3jx-gcc-10.3.0!include!c++!10.3.0!bits!exception_defines.h.~undo-tree~
Parsing ptr_traits.h (LL)...done
Wrote /home/david/.undo-tree/.!nix!store!2dv93bbc06c7zg866qid73j3r36zz3jx-gcc-10.3.0!include!c++!10.3.0!bits!ptr_traits.h.~undo-tree~
Parsing type_traits (LL)...done
Wrote /home/david/.undo-tree/.!nix!store!2dv93bbc06c7zg866qid73j3r36zz3jx-gcc-10.3.0!include!c++!10.3.0!type_traits.~undo-tree~

It's also very slow parsing these files. I'm not sure how much that has to do with undo-tree, vs other hooks/modes, but it brought my attention to it.

I'll try to do some investigation soon, but if anyone has any progress/ideas to report, I'm interested.

semantic-find-file-noselect seems like a mess of hacks to blacklist things that don't cooperate, but I'm not sure why it was implemented that way.

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

Successfully merging this pull request may close these issues.

When enable semantic in emacs-lisp buffer, the completion is very slow
7 participants