This is an archive of the discontinued LLVM Phabricator instance.

[clangd][vscode] Add a flag to enable semantic highlighting in clangd
ClosedPublic

Authored by hokein on Sep 3 2019, 6:40 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

hokein created this revision.Sep 3 2019, 6:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 3 2019, 6:40 AM
ilya-biryukov added inline comments.Sep 3 2019, 7:06 AM
clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
113 ↗(On Diff #218445)

Why not avoid calling clangdClient.registerFeature instead?
Would allow to:

  • not change the SemanticHighlightingFeature class, keeping it simpler,
  • ensure we do not do any extra work if the feature is disabled.
hokein updated this revision to Diff 218452.Sep 3 2019, 7:21 AM
hokein marked 2 inline comments as done.

address the comment, don't register the feature.

clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
113 ↗(On Diff #218445)

good point, done.

ilya-biryukov added inline comments.Sep 3 2019, 7:57 AM
clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
113 ↗(On Diff #218445)

Should we update other uses of semanticHighlightingFeature too?

context.subscriptions.push(vscode.Disposable.from(semanticHighlightingFeature)) probably ensures we call dispose() when the clangdClient is getting removed, I guess we definitely don't need that.

Other uses as well:

  • no need to pass notification is highlighting is disabled.
  • no need to cleanup if highlighting is disabled.

Maybe assign null or undefined to semanticHighlightingFeature when the flag is false?
At each usage we can check whether the semanticHighlightingFeature is not null and only call relevant methods if that's the case.

hokein marked an inline comment as done.Sep 3 2019, 8:09 AM
hokein added inline comments.
clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
113 ↗(On Diff #218445)

I don't think it is worth updating all usages, it is no harm to keep them here even when the highlighting is disabled (the dispose is a no-op; we never receive notifications from clangd); and it would add more guard code which I'd avoid.

ilya-biryukov added inline comments.Sep 3 2019, 8:18 AM
clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
113 ↗(On Diff #218445)

How can we be sure that nothing bad is going to happen?
In particular, we are "binding" notification handling, but never registered a feature. How can we be sure we won't actually get any notifications?

If we don't create the object in the first place, we are confident nothing harmful can be done with it.

hokein marked an inline comment as done.Sep 4 2019, 7:23 AM
hokein added inline comments.
clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
113 ↗(On Diff #218445)

How can we be sure we won't actually get any notifications?

If we receive a notification, that means we have clangd bugs.

I understand you point here, an ideal solution is to avoid too many usages of SemanticHighlightingFeature in the client side, after D67165, it'd help simplify the patch here.

ilya-biryukov marked an inline comment as done.Sep 4 2019, 7:27 AM
ilya-biryukov added inline comments.
clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
113 ↗(On Diff #218445)

If we receive a notification, that means we have clangd bugs.

True, but that might happen. It'd be better to not break in that case.
D67165 is definitely moving in the right direction, thanks!

ilya-biryukov added inline comments.Sep 4 2019, 8:51 AM
clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
113 ↗(On Diff #218445)

It should be much simpler to not construct the semanticHighlightingFeature with D67165, right?

if (getConfig<boolean>('semanticHighlighting')) {
  const semanticHighlightingFeature =
      new semanticHighlighting.SemanticHighlightingFeature();
  context.subscriptions.push(
      vscode.Disposable.from(semanticHighlightingFeature));
  clangdClient.registerFeature(semanticHighlightingFeature);
}

Could we do that?

hokein updated this revision to Diff 218864.Sep 5 2019, 2:18 AM
hokein marked 2 inline comments as done.

rebase and simplify the code.

hokein added inline comments.Sep 5 2019, 2:20 AM
clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
113 ↗(On Diff #218445)

yes, exactly.

ilya-biryukov accepted this revision.Sep 5 2019, 2:22 AM

LGTM, thanks!

This revision is now accepted and ready to land.Sep 5 2019, 2:22 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 5 2019, 2:26 AM