fannheyward / coc-rust-analyzer

rust-analyzer extension for coc.nvim
MIT License
1.13k stars 40 forks source link

inlay hint only at the end of the line so out of alignment #1084

Closed sou-chon closed 1 year ago

sou-chon commented 1 year ago

Hi I am loving the inlay hints but they only come at the end of the line instead of being inserted into the code itself so it's really hard to see which variable it's referring to (see screenshot). In the past the inlay hints comes with variable names like foo: i32. Is there an option where I can enable variable name display? or to allow the inlay hint be inserted into the code and not at the end of the line?

thanks

What's the output of :CocInfo

What's the output of :CocCommand rust-analyzer.serverVersion 0.3.1309-standalone

What's your coc-rust-analyzer version? You can get it from :CocList extensions 0.70.0

Screenshot 2022-12-10 at 23 56 30
fannheyward commented 1 year ago

In the past the inlay hints comes with variable names

Yes, this has been removed.

The previous implementation of inlay hint was not in LSP, rust-analyzer supported this in its protocol and coc-rust-analyzer supports this too, this was the past.

From LSP 3.17, inlay hint has been added to LSP, rust-analyzer changed to follow official LSP. But the official inlay hint protocol is a little different from rust-analyzer's own.

The old protocol, rust-analyzer returns a hint in this:

export namespace InlayHint {
  export const enum Kind {
    TypeHint = 'TypeHint',
    ParamHint = 'ParameterHint',
    ChainingHint = 'ChainingHint',
  }
  interface Common {
    range: lc.Range;
    label: string;
  }
  export type TypeHint = Common & { kind: Kind.TypeHint };
  export type ParamHint = Common & { kind: Kind.ParamHint };
  export type ChainingHint = Common & { kind: Kind.ChainingHint };
}

Note the Common.range, rust-analyzer told you the range text and its hint label. coc-rust-analyzer uses the range to substring the variable name to display.

The LSP:

export declare type InlayHint = {
    position: Position;
    label: string | InlayHintLabelPart[];
    kind?: InlayHintKind;
    textEdits?: TextEdit[];
    tooltip?: string | MarkupContent;
    paddingLeft?: boolean;
    paddingRight?: boolean;
    data?: LSPAny;
};

There's no range now, only a position that hint began. We can't get variable now.

allow the inlay hint be inserted into the code

Use vim, yes, nvim doesn't support this.

截屏2022-12-11 10 05 41