From 9f0a78ce85eae3169dcbeae361066c0ddd86625b Mon Sep 17 00:00:00 2001 From: Onno Vos Date: Fri, 9 Apr 2021 22:33:50 +0200 Subject: [PATCH] Skip formatting if . is on a commented out line --- apps/els_lsp/src/els_formatting_provider.erl | 23 ++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/apps/els_lsp/src/els_formatting_provider.erl b/apps/els_lsp/src/els_formatting_provider.erl index 3dd96d603..dfaaea19a 100644 --- a/apps/els_lsp/src/els_formatting_provider.erl +++ b/apps/els_lsp/src/els_formatting_provider.erl @@ -138,17 +138,18 @@ rangeformat_document(_Uri, _Document, _Range, _Options) -> , number(), number(), string(), formatting_options()) -> {ok, [text_edit()]}. ontypeformat_document(_Uri, Document, Line, Col, <<".">>, _Options) -> - case find_foldable_ranges(Document) of + case find_matching_range(Document, Line) of [] -> {ok, []}; - FoldableRanges -> - case find_matching_range(FoldableRanges, Line) of - [] -> + [MatchingRange] -> + {StartLine, _} = Id = els_poi:id(MatchingRange), + Text = els_dt_document:text(Document), + RangeText = els_text:range(Text, Id, {Line, Col}), + % Skip formatting if the . is on a commented line. + case string:trim(els_text:line(Text, Line - 1), both) of + <<"%", _/binary>> -> {ok, []}; - [MatchingRange] -> - {StartLine, _} = Id = els_poi:id(MatchingRange), - Text = els_dt_document:text(Document), - RangeText = els_text:range(Text, Id, {Line, Col}), + _ -> ParseF = fun(Dir) -> TmpFile = tmp_file(Dir), @@ -189,12 +190,12 @@ find_foldable_ranges(Document) -> end, Pois). --spec find_matching_range([poi()], number()) -> [poi()]. -find_matching_range(FoldableRanges, Line) -> +-spec find_matching_range(els_dt_document:item(), number()) -> [poi()]. +find_matching_range(Document, Line) -> lists:filter(fun(#{range := #{from := {FromLine, _}, to := {ToLine, _}}}) -> Line >= FromLine andalso Line =< ToLine end, - FoldableRanges). + find_foldable_ranges(Document)). -spec tmp_file(string()) -> any(). tmp_file(Dir) ->