Skip to content

Commit

Permalink
feat: include context lines by default in the HTTP response (#394)
Browse files Browse the repository at this point in the history
* feat: include context lines by default in the HTTP response

* feat: set default context to 3
  • Loading branch information
kantord authored Nov 9, 2023
1 parent 9b87ed2 commit 3b15b3c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions seagoat/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def seagoat(
query,
server_address,
max_results,
context_above or 0,
context_below or 0,
context_above if context_above is not None else 3,
context_below if context_below is not None else 3,
)

results = rewrite_full_paths_to_use_local_path(repo_path, results)
Expand Down
4 changes: 2 additions & 2 deletions seagoat/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def create_app(repo_path):
@app.route("/query/<query>")
def query_codebase(query):
limit_clue = request.args.get("limitClue", "500")
context_above = request.args.get("contextAbove", 0)
context_below = request.args.get("contextBelow", 0)
context_above = request.args.get("contextAbove", 3)
context_below = request.args.get("contextBelow", 3)

try:
limit_clue = int(limit_clue)
Expand Down
6 changes: 4 additions & 2 deletions tests/__snapshots__/test_cli.ambr
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# serializer version: 1
# name: test_connecting_to_remote_server
list([
'bat normalized_repo_path/file4.js --file-name file4.js --paging never --line-range 1:1',
'bat normalized_repo_path/file4.md --file-name file4.md --paging never --line-range 1:1',
'bat normalized_repo_path/file4.js --file-name file4.js --paging never --line-range 0:1',
'bat normalized_repo_path/file4.md --file-name file4.md --paging never --line-range 0:1',
])
# ---
# name: test_integration_test_no_results
''
# ---
# name: test_integration_test_without_color
'''
file4.js:0:// This is a second updated example JavaScript file
file4.js:1:// This is a second updated example JavaScript file
file4.md:0:// This is a second updated example JavaScript file
file4.md:1:// This is a second updated example JavaScript file

'''
Expand Down
11 changes: 11 additions & 0 deletions tests/__snapshots__/test_server.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
'blocks': list([
dict({
'lineTypeCount': dict({
'context': 3,
'result': 3,
}),
'lines': list([
dict({
'line': 0,
'lineText': "HTML is for markup, but it's complicated. Markdown is simpler.",
'resultTypes': list([
'context',
]),
'score': 0.0,
}),
dict({
'line': 1,
'lineText': '# Markdown file',
'resultTypes': list([
'context',
'result',
]),
'score': 0.6,
Expand All @@ -21,6 +31,7 @@
'line': 2,
'lineText': 'This is an example Markdown file. Updated. ',
'resultTypes': list([
'context',
'result',
]),
'score': 0.6,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def test_forwards_context_below_to_server(


@pytest.mark.usefixtures("mock_accuracy_warning")
@pytest.mark.parametrize("context", [1, 2, 10])
@pytest.mark.parametrize("context", [0, 1, 2, 10])
def test_forwards_context_to_server(context, get_request_args_from_cli_call):
request_args1 = get_request_args_from_cli_call(["--context", str(context)])
assert request_args1["params"]["contextAbove"] == context
Expand Down

0 comments on commit 3b15b3c

Please sign in to comment.