<div dir="ltr"><div dir="ltr">Thanks for the detailed responses! <div>I definitely agree that Clangd should provide more than just indentation. Your examples perfectly illustrate what kind of live formatting should be done.</div><div><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr">On Fri, 7 Sep 2018 at 06:25, Sam McCall <<a href="mailto:sammccall@google.com" target="_blank">sammccall@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">We've had some discussion in the past about the right way for clang-format to support live-formatting cases.<div><br></div><div>IIRC clang-format doesn't have any current logic specific to this, instead having "format these ranges". That mode works well for formatting only changed lines and similar cases, but it may or may not be the right model for format-as-you-type. </div></div></blockquote><div><br></div><div>Right. After some experiments I started leaning towards it being not the right model. Ideally we'd have something better, just like you describe below.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>In particular I don't think this model will ever give you useful autoindent, because if you were *checking in the code* instead of continuing to type, you'd want the leading spaces gone.</div><div>So we'd probably need to either:</div><div> - add a new "as-you-type" mode or entrypoint in clang-format's core, and carefully decide what new features it needs and how they should interact with clang-format's existing model, or</div><div> - hack something together outside of clang-format's core (possibly reusing its parser)</div></div></blockquote><div><br></div><div>One other hand-wavy solution that I considered: insert a fake cursor token into the token stream which will be have the effect of reindenting the line correctly, e.g.</div><div><br></div><div><div>1. Reformatting braces.</div><div>before:</div><div>if (foo) {^}</div><div><br></div><div>after;</div><div>if (foo) {</div><div>  ^ // clang-format will treat the cursor as a special token, and thus won't format the 'if' as if its body was empty.</div><div>}</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>My sense is that the first is likely to give better results, e.g. in the reformatting braces cases the cursor/indentation and braces may interact. </div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Either way it might make sense to provide the result as a clang-format API, rather than building the logic inside clangd directly.</div></div></blockquote><div><br></div><div>Agreed.</div><div><br></div><div>Better live formatting is definitely something that we need down the line, but I'm not planning to work on it as of yet. I'll keep this on my list of potential things to do in Clangd for now, but I won't mind if someone else picks it up. I'll update the list if I'll have more ideas/thoughts/proposals for this problem.</div><div><br></div><div>Cheers,</div><div>Alex</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br><div class="gmail_quote"><div dir="ltr">On Thu, Sep 6, 2018 at 8:27 PM Alex L via clangd-dev <<a href="mailto:clangd-dev@lists.llvm.org" target="_blank">clangd-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I would like to implement clang-format aware newline indentation in Clangd. It looks like Clangd only supports '}' trigger character for the 'onTypeFormatting' request. Would it make sense to extend it to support the newline character, and to insert appropriate indentation instead of reformatting the range in that case?</div><div><br></div><div>Cheers,</div><div>Alex</div></div>
_______________________________________________<br>
clangd-dev mailing list<br>
<a href="mailto:clangd-dev@lists.llvm.org" target="_blank">clangd-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev</a><br>
</blockquote></div>
</blockquote></div></div></div></div></div>