vscode-clangd icon indicating copy to clipboard operation
vscode-clangd copied to clipboard

Suggestion for improved allCommitCharacters workaround

Open mroch opened this issue 2 years ago • 2 comments

See this code:

https://github.com/clangd/vscode-clangd/blob/cee0726d4616d500a5989c28cbcb6a8ab08bef9f/src/clangd-context.ts#L118-L123

However, that codepath is skipped if serverCompletionRanking is disabled:

https://github.com/clangd/vscode-clangd/blob/cee0726d4616d500a5989c28cbcb6a8ab08bef9f/src/clangd-context.ts#L110-L111

and it prevents setting commitCharacters on individual responses if you do have a valid use case in the future.

an alternative is to remove allCommitCharacters from the server capabilities with something like this:

class AllCommitCharactersFixFeature implements StaticFeature {
  preInitialize(capabilities: ServerCapabilities<unknown>): void {
    const completionProvider = capabilities?.completionProvider;
    if (completionProvider?.allCommitCharacters != null) {
      delete completionProvider.allCommitCharacters;
    }
  }

  getState(): FeatureState {
    return {kind: 'static'};
  }

  fillClientCapabilities(): void {
    // nothing to do
  }

  initialize(): void {
    // nothing to do
  }

  dispose(): void {
    // nothing to do
  }
}

...

client.registerFeature(new AllCommitCharactersFixFeature());

you could even look for the specific list set by older versions, so future versions could still use allCommitCharacters.

mroch avatar Aug 09 '23 03:08 mroch

Just to make sure I understand: is there a motivation for the proposed change beyond enabling potential future changes?

HighCommander4 avatar Aug 09 '23 03:08 HighCommander4

I think it's broken (skipped) if you disable serverCompletionRanking, but otherwise no, not really necessary. Just a suggestion

mroch avatar Aug 09 '23 03:08 mroch