Improved completion to support the correct table name for autocompletion and formatting
This commit is contained in:
@@ -14,7 +14,6 @@ from myfasthtml.core.formatting.dsl.completion.contexts import (
|
||||
detect_scope,
|
||||
detect_context,
|
||||
)
|
||||
from myfasthtml.core.formatting.dsl.completion.suggestions import get_suggestions
|
||||
from myfasthtml.core.formatting.dsl.completion.FormattingCompletionEngine import (
|
||||
FormattingCompletionEngine,
|
||||
get_completions,
|
||||
@@ -545,9 +544,10 @@ def test_context_none_in_comment():
|
||||
|
||||
def test_suggestions_scope_keyword(provider):
|
||||
"""Test suggestions for SCOPE_KEYWORD context."""
|
||||
engine = FormattingCompletionEngine(provider, "app.orders")
|
||||
scope = DetectedScope()
|
||||
|
||||
suggestions = get_suggestions(Context.SCOPE_KEYWORD, scope, provider)
|
||||
suggestions = engine.get_suggestions(Context.SCOPE_KEYWORD, scope, "")
|
||||
labels = [s.label for s in suggestions]
|
||||
|
||||
assert "column" in labels
|
||||
@@ -557,9 +557,10 @@ def test_suggestions_scope_keyword(provider):
|
||||
|
||||
def test_suggestions_style_preset(provider):
|
||||
"""Test suggestions for STYLE_PRESET context."""
|
||||
engine = FormattingCompletionEngine(provider, "app.orders")
|
||||
scope = DetectedScope(scope_type="column", column_name="amount")
|
||||
|
||||
suggestions = get_suggestions(Context.STYLE_PRESET, scope, provider)
|
||||
suggestions = engine.get_suggestions(Context.STYLE_PRESET, scope, "")
|
||||
labels = [s.label for s in suggestions]
|
||||
|
||||
assert "primary" in labels
|
||||
@@ -570,9 +571,10 @@ def test_suggestions_style_preset(provider):
|
||||
|
||||
def test_suggestions_format_type(provider):
|
||||
"""Test suggestions for FORMAT_TYPE context."""
|
||||
engine = FormattingCompletionEngine(provider, "app.orders")
|
||||
scope = DetectedScope(scope_type="column", column_name="amount")
|
||||
|
||||
suggestions = get_suggestions(Context.FORMAT_TYPE, scope, provider)
|
||||
suggestions = engine.get_suggestions(Context.FORMAT_TYPE, scope, "")
|
||||
labels = [s.label for s in suggestions]
|
||||
|
||||
assert "number" in labels
|
||||
@@ -584,9 +586,10 @@ def test_suggestions_format_type(provider):
|
||||
|
||||
def test_suggestions_operators(provider):
|
||||
"""Test suggestions for OPERATOR context."""
|
||||
engine = FormattingCompletionEngine(provider, "app.orders")
|
||||
scope = DetectedScope(scope_type="column", column_name="amount")
|
||||
|
||||
suggestions = get_suggestions(Context.OPERATOR, scope, provider)
|
||||
suggestions = engine.get_suggestions(Context.OPERATOR, scope, "")
|
||||
labels = [s.label for s in suggestions]
|
||||
|
||||
assert "==" in labels
|
||||
@@ -598,9 +601,10 @@ def test_suggestions_operators(provider):
|
||||
|
||||
def test_suggestions_boolean_value(provider):
|
||||
"""Test suggestions for BOOLEAN_VALUE context."""
|
||||
engine = FormattingCompletionEngine(provider, "app.orders")
|
||||
scope = DetectedScope(scope_type="column", column_name="amount")
|
||||
|
||||
suggestions = get_suggestions(Context.BOOLEAN_VALUE, scope, provider)
|
||||
suggestions = engine.get_suggestions(Context.BOOLEAN_VALUE, scope, "")
|
||||
labels = [s.label for s in suggestions]
|
||||
|
||||
assert "True" in labels
|
||||
@@ -609,9 +613,10 @@ def test_suggestions_boolean_value(provider):
|
||||
|
||||
def test_suggestions_color_value(provider):
|
||||
"""Test suggestions for COLOR_VALUE context."""
|
||||
engine = FormattingCompletionEngine(provider, "app.orders")
|
||||
scope = DetectedScope(scope_type="column", column_name="amount")
|
||||
|
||||
suggestions = get_suggestions(Context.COLOR_VALUE, scope, provider)
|
||||
suggestions = engine.get_suggestions(Context.COLOR_VALUE, scope, "")
|
||||
labels = [s.label for s in suggestions]
|
||||
|
||||
assert "red" in labels
|
||||
@@ -621,9 +626,10 @@ def test_suggestions_color_value(provider):
|
||||
|
||||
def test_suggestions_column_values(provider):
|
||||
"""Test suggestions for OPERATOR_VALUE context with column scope."""
|
||||
engine = FormattingCompletionEngine(provider, "app.orders")
|
||||
scope = DetectedScope(scope_type="column", column_name="status")
|
||||
|
||||
suggestions = get_suggestions(Context.OPERATOR_VALUE, scope, provider)
|
||||
suggestions = engine.get_suggestions(Context.OPERATOR_VALUE, scope, "")
|
||||
labels = [s.label for s in suggestions]
|
||||
|
||||
# Base suggestions
|
||||
@@ -639,9 +645,10 @@ def test_suggestions_column_values(provider):
|
||||
|
||||
def test_suggestions_rule_start(provider):
|
||||
"""Test suggestions for RULE_START context."""
|
||||
engine = FormattingCompletionEngine(provider, "app.orders")
|
||||
scope = DetectedScope(scope_type="column", column_name="amount")
|
||||
|
||||
suggestions = get_suggestions(Context.RULE_START, scope, provider)
|
||||
suggestions = engine.get_suggestions(Context.RULE_START, scope, "")
|
||||
labels = [s.label for s in suggestions]
|
||||
|
||||
assert "style(" in labels
|
||||
@@ -651,9 +658,10 @@ def test_suggestions_rule_start(provider):
|
||||
|
||||
def test_suggestions_none_context(provider):
|
||||
"""Test that NONE context returns empty suggestions."""
|
||||
engine = FormattingCompletionEngine(provider, "app.orders")
|
||||
scope = DetectedScope()
|
||||
|
||||
suggestions = get_suggestions(Context.NONE, scope, provider)
|
||||
suggestions = engine.get_suggestions(Context.NONE, scope, "")
|
||||
|
||||
assert suggestions == []
|
||||
|
||||
@@ -668,7 +676,7 @@ def test_i_can_get_completions_for_style_preset(provider):
|
||||
text = 'column amount:\n style("'
|
||||
cursor = Position(line=1, ch=11)
|
||||
|
||||
result = get_completions(text, cursor, provider)
|
||||
result = get_completions(text, cursor, provider, "app.orders")
|
||||
|
||||
assert not result.is_empty
|
||||
labels = [s.label for s in result.suggestions]
|
||||
@@ -681,7 +689,7 @@ def test_i_can_get_completions_filters_by_prefix(provider):
|
||||
text = 'column amount:\n style("err'
|
||||
cursor = Position(line=1, ch=14)
|
||||
|
||||
result = get_completions(text, cursor, provider)
|
||||
result = get_completions(text, cursor, provider, "app.orders")
|
||||
|
||||
labels = [s.label for s in result.suggestions]
|
||||
assert "error" in labels
|
||||
@@ -693,7 +701,7 @@ def test_i_can_get_completions_returns_correct_positions(provider):
|
||||
text = 'column amount:\n style("err'
|
||||
cursor = Position(line=1, ch=14) # After "err"
|
||||
|
||||
result = get_completions(text, cursor, provider)
|
||||
result = get_completions(text, cursor, provider, "app.orders")
|
||||
|
||||
# from_pos should be at start of "err"
|
||||
assert result.from_pos.line == 1
|
||||
@@ -709,7 +717,7 @@ def test_i_can_get_completions_at_scope_start(provider):
|
||||
text = ""
|
||||
cursor = Position(line=0, ch=0)
|
||||
|
||||
result = get_completions(text, cursor, provider)
|
||||
result = get_completions(text, cursor, provider, "app.orders")
|
||||
|
||||
labels = [s.label for s in result.suggestions]
|
||||
assert "column" in labels
|
||||
@@ -722,7 +730,7 @@ def test_i_can_get_completions_for_column_names(provider):
|
||||
text = "column "
|
||||
cursor = Position(line=0, ch=7)
|
||||
|
||||
result = get_completions(text, cursor, provider)
|
||||
result = get_completions(text, cursor, provider, "app.orders")
|
||||
|
||||
labels = [s.label for s in result.suggestions]
|
||||
assert "id" in labels
|
||||
@@ -735,21 +743,22 @@ def test_i_can_get_completions_in_comment_returns_empty(provider):
|
||||
text = "column amount:\n # comment"
|
||||
cursor = Position(line=1, ch=15)
|
||||
|
||||
result = get_completions(text, cursor, provider)
|
||||
result = get_completions(text, cursor, provider, "app.orders")
|
||||
|
||||
assert result.is_empty
|
||||
|
||||
|
||||
def test_i_can_create_formatting_completion_engine(provider):
|
||||
"""Test that FormattingCompletionEngine can be instantiated."""
|
||||
engine = FormattingCompletionEngine(provider)
|
||||
engine = FormattingCompletionEngine(provider, "app.orders")
|
||||
|
||||
assert engine.provider == provider
|
||||
assert engine.table_name == "app.orders"
|
||||
|
||||
|
||||
def test_i_can_use_engine_detect_scope(provider):
|
||||
"""Test engine's detect_scope method."""
|
||||
engine = FormattingCompletionEngine(provider)
|
||||
engine = FormattingCompletionEngine(provider, "app.orders")
|
||||
text = "column amount:\n style()"
|
||||
|
||||
scope = engine.detect_scope(text, current_line=1)
|
||||
@@ -760,7 +769,7 @@ def test_i_can_use_engine_detect_scope(provider):
|
||||
|
||||
def test_i_can_use_engine_detect_context(provider):
|
||||
"""Test engine's detect_context method."""
|
||||
engine = FormattingCompletionEngine(provider)
|
||||
engine = FormattingCompletionEngine(provider, "app.orders")
|
||||
text = "column amount:\n style("
|
||||
cursor = Position(line=1, ch=10)
|
||||
scope = DetectedScope(scope_type="column", column_name="amount")
|
||||
|
||||
Reference in New Issue
Block a user