Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

On type formatting #126

Merged
merged 45 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4f3434b
Working line formatter based on VS Code implementation, without tests
jakebailey Sep 11, 2018
c52b83d
fix namespace change, rename file
jakebailey Sep 11, 2018
d8d1a74
move LineFormatter, add basic OnTypeFormatting tests, add LineFormatt…
jakebailey Sep 12, 2018
410b13f
mostly complete line formatter
jakebailey Sep 14, 2018
1a4c2db
rewrite formatter from scratch, fully passes existing tests with slig…
jakebailey Sep 17, 2018
cdbc45a
cleanup argument/lambda inside logic, remove leftover debugging state…
jakebailey Sep 17, 2018
32bae79
fix various formatting issues from vscode-python
jakebailey Sep 18, 2018
659075b
fix half-comment
jakebailey Sep 18, 2018
5ad26bc
add a few more unary operator tests for slicing
jakebailey Sep 18, 2018
17656b9
tweak test names, ellipsis test
jakebailey Sep 18, 2018
ca86bd3
test cleanups
jakebailey Sep 18, 2018
a506a8c
test unary ops inside function args
jakebailey Sep 18, 2018
c3ce7b9
test a few edge cases
jakebailey Sep 18, 2018
b956846
test against PEP448 unpacking, cleanup testing helpers, naming tweaks
jakebailey Sep 18, 2018
e5989df
remove stray comment
jakebailey Sep 18, 2018
ab1798d
simplify checking token kinds
jakebailey Sep 18, 2018
770aa4e
catch bad trigger character for OnTypeFormatting call
jakebailey Sep 18, 2018
b19ad65
instead of reading one extra line arbitrarily, tokenize ahead to the …
jakebailey Sep 18, 2018
eab9e6a
more consistent ArgumentNullException usage
jakebailey Sep 18, 2018
65842a2
remove async stuff from test cases
jakebailey Sep 18, 2018
a9f82ba
remove _reader member, document LineFormatter class/constructor
jakebailey Sep 18, 2018
a9d219b
documentation fixes
jakebailey Sep 18, 2018
9027d4b
check lines first, as most tokens won't span multiple lines
jakebailey Sep 18, 2018
5c00a04
fix multiline string assignment and function defaults/named args
jakebailey Sep 19, 2018
6630e87
simplify multiline string logic
jakebailey Sep 19, 2018
1fab534
directly test line continuations, fix commas inside brackets
jakebailey Sep 19, 2018
cae62a5
a few code analyzer fixes
jakebailey Sep 19, 2018
54556e3
simplify multiline string logic
jakebailey Sep 20, 2018
0892c5b
re-add soft space after multiline string
jakebailey Sep 20, 2018
73c6ff9
remove exception for unknown tokens, handle older python 2 features (…
jakebailey Sep 20, 2018
3c6a024
shuffle token get, fix AddToken typo
jakebailey Sep 20, 2018
e182904
explain non-comprehensive language server formatting tests
jakebailey Sep 24, 2018
37d1348
add context, dispose of server
jakebailey Sep 24, 2018
ee32c09
accessor formatting
jakebailey Sep 24, 2018
edaca3f
use Check class
jakebailey Sep 24, 2018
4df670f
fix failing test
jakebailey Sep 24, 2018
2e604ae
use DataRow/DataTestMethod style tests to show results for each
jakebailey Sep 24, 2018
4177069
fix missing DataTestMethod
jakebailey Sep 24, 2018
d2a6423
add a single string of whitespace instead of many single spaces
jakebailey Sep 24, 2018
96f3652
remove string specialization
jakebailey Sep 24, 2018
87d3392
move filtering into TokenizeLine
jakebailey Sep 24, 2018
94c18a0
simplify grammar file unchanged line checks
jakebailey Sep 24, 2018
f1cec62
remove test helpers, use server extension
jakebailey Sep 24, 2018
874a620
remove TextBuilder in favor of StringBuilder extension
jakebailey Sep 25, 2018
699b130
Merge remote-tracking branch 'upstream/master' into on-type-formatting
jakebailey Sep 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,21 @@ public static StringBuilder TrimEnd(this StringBuilder sb) {
}
return sb;
}

public static StringBuilder EnsureEndsWithSpace(this StringBuilder sb, int count = 1, bool allowLeading = false) {
if (sb.Length == 0 && !allowLeading) {
return sb;
}

for (var i = sb.Length - 1; i >= 0 && char.IsWhiteSpace(sb[i]); i--) {
count--;
}

if (count > 0) {
sb.Append(new string(' ', count));
}

return sb;
}
}
}
36 changes: 36 additions & 0 deletions src/Analysis/Engine/Test/LanguageServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,42 @@ public async Task ParseAndAnalysisDiagnostics() {
);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is getting huge. Can we create LanguageServer folder and then separate FormattingTests file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like me to do that in this PR, or a subsequent one? It might be more straightforward to make a PR to move all of the tests at once, since a lot of the "CreateServer" logic is shared between the tests.

[TestMethod, Priority(0)]
public async Task OnTypeFormatting() {
using (var s = await CreateServer()) {
var uri = await AddModule(s, "def foo ( ) :\n x = a + b\n x+= 1");

// Extended tests for line formatting are in LineFormatterTests.
// These just verify that the language server formats and returns something correct.
var edits = await s.SendDocumentOnTypeFormatting(uri, new SourceLocation(2, 1), "\n");
edits.Should().OnlyContain(new TextEdit {
newText = "def foo():",
range = new Range {
start = new SourceLocation(1, 1),
end = new SourceLocation(1, 15)
}
});

edits = await s.SendDocumentOnTypeFormatting(uri, new SourceLocation(3, 1), "\n");
edits.Should().OnlyContain(new TextEdit {
newText = "x = a + b",
range = new Range {
start = new SourceLocation(2, 5),
end = new SourceLocation(2, 14)
}
});

edits = await s.SendDocumentOnTypeFormatting(uri, new SourceLocation(4, 1), "\n");
edits.Should().OnlyContain(new TextEdit {
newText = "x += 1",
range = new Range {
start = new SourceLocation(3, 5),
end = new SourceLocation(3, 10)
}
});
}
}

class GetAllExtensionProvider : ILanguageServerExtensionProvider {
public Task<ILanguageServerExtension> CreateAsync(IPythonLanguageServer server, IReadOnlyDictionary<string, object> properties, CancellationToken cancellationToken) {
return Task.FromResult<ILanguageServerExtension>(new GetAllExtension((Server)server, properties));
Expand Down
Loading