cquery semantic highlighting意见

代码:emacs-cquery/cquery-semantic-highlighting.el at master · cquery-project/emacs-cquery · GitHub

先给各种事物定义脸面(捂脸)

(defcustom cquery-sem-function-faces [font-lock-function-name-face] "Faces for functions." :type '(repeat face) :group 'cquery)

(defcustom cquery-sem-macro-faces [font-lock-variable-name-face] "Faces for macros." :type '(repeat face) :group 'cquery)

(defcustom cquery-sem-namespace-faces [font-lock-constant-face] "Faces for namespaces." :type '(repeat face) :group 'cquery)

(defcustom cquery-sem-type-faces [font-lock-type-face] "Faces used to mark types." :type '(repeat face) :group 'cquery)

(defcustom cquery-sem-variable-faces [font-lock-variable-name-face] "Faces for variables." :type '(repeat face) :group 'cquery)

然后给它们定义颜色

(defcustom cquery-sem-function-colors '("#e5b124" "#927754" "#eb992c" "#e2bf8f" "#d67c17" "#88651e" "#e4b953" "#a36526" "#b28927" "#d69855") "Default colors for `cquery-sem-function-faces'." :type '(repeat color) :group 'cquery)

(defcustom cquery-sem-macro-colors '("#e79528" "#c5373d" "#e8a272" "#d84f2b" "#a67245" "#e27a33" "#9b4a31" "#b66a1e" "#e27a71" "#cf6d49") "Default colors for `cquery-sem-macro-faces'." :type '(repeat color) :group 'cquery)

(defcustom cquery-sem-namespace-colors '("#429921" "#58c1a4" "#5ec648" "#36815b" "#83c65d" "#417b2f" "#43cc71" "#7eb769" "#58bf89" "#3e9f4a") "Default colors for `cquery-sem-namespace-faces'." :type '(repeat color) :group 'cquery)

用宏根据 colors 生成 faces。对于 freestanding/member function/variable 这样的变种,采用斜体区分。 global/local variable可以用粗体区分。

各位怎么看

vscode-cquery 的做法感觉可怕了,什么 underline bold 都定义一遍 vscode-cquery/package.json at master · cquery-project/vscode-cquery · GitHub 大多数人不会定制的。

这种活是defface的工作吧, 用变量处理不太好吧?

1 个赞

这个功能我默认是关掉的…个人目前对这个功能需求并不大, 这个定制的麻烦程度感觉大于收益了, 而且这个颜色还要自己填如#429921这样的东西, 我感觉实在是太恐怖了. 我甚至想把高亮当前symbol的这个特性取消, 苦于不会. 而且之前在用的时候感觉, cquery的某些特性在某种情况下可能还是有bug, 不一定什么时候就出现一个预料之外的效果, 比如某个变量配色不对, 或者是出现了意想不到的高亮. 总体来说影响不大, 但是看起来感觉反而很不舒服.

颜色已经写进去了,不需要定制。开启应该只要两行配置

(setq cquery-sem-highlight-method 'overlay)     ;; 'font-lock 不知道如何
(cquery-use-default-rainbow-sem-highlight)

高亮当前symbol

(setq lsp-highlight-symbol-at-point nil)。你还错过了Read/Write 区分,随便现在只对builtin type区分。

https://camo.githubusercontent.com/75ee028bc2422ec721417554c1227b8fca02ce62/68747470733a2f2f707470622e70772f52742d772e676966

某个变量配色不对, 或者是出现了意想不到的高亮

偶尔我需要revert-buffer,总体还行

(setq cquery-sem-highlight-method 'overlay)     ;; 'font-lock 不知道如何
(cquery-use-default-rainbow-sem-highlight)

这个我在抄你的配置的时候打开过, 用了之后从功能上来说感觉作用不大. 而默认的配色方案看起来有些不舒服, 可能是由于不习惯. 因为我需要亮色的主题, 目前使用的是solarized-light. 因为我主要写C, 可能不太接触C++. 之前用的时候在类似

while ((func(args...)) != NULL) {
  // do something
}

的代码中,func和args配色都是不对的, 不知道现在正常了没有. 后来就没再尝试了.

至于 read/write 的区分, 乍一看的时候感觉很厉害, 仔细想想又感觉好像作用不是特别大. 也许我现在没有这一类的强烈需求…

为什么要定义新的face? 这些好像emacs内部都存在啊? 直接用已存在的不行吗?

每种物体需要10种颜色

我现在写 C 也得这样了:

看到这样花花绿绿的我真的觉得… 挺乱的…

我一般用斜体区分虚函数

不对的通常就是因为 func(args...) 没有索引成功,所在scope后面的部分都会没有semantic highlighting

我现在用

(setq cquery-sem-highlight-method 'font-lock)
(cquery-use-default-rainbow-sem-highlight)

了。对于一些类型,比如下面例子中的TargetInfo,font-lock的face覆盖了`font-lock-face (列表中前面的覆盖后面的)

template <class ELFT> <kbd>TargetInfo</kbd> *getMipsTargetInfo();

text properties为

(face font-lock-type-face fontified t font-lock-face cquery-sem-type-face-2)

我的写法 https://github.com/cquery-project/emacs-cquery/blob/master/cquery-semantic-highlighting.el#L280 是:

              (pcase cquery-sem-highlight-method
                ('font-lock
                 (dolist (x overlays)
                   (set-text-properties (car x) (cadr x) `(face nil font-lock-face ,(caddr x)))))

问题:这样写还是无法把 font-lock设置的face覆盖掉吗?