Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correctly pick whole file context #85

Merged
merged 1 commit into from
Mar 5, 2025

Conversation

p12tic
Copy link
Contributor

@p12tic p12tic commented Mar 3, 2025

Currently the current line is duplicated in both "before" and "after" context. This is due to DocumentContextReader::readWholeFileAfter() picking the current line part of which has been already included into the "before" context.

@Palm1r
Copy link
Owner

Palm1r commented Mar 3, 2025

It should, because the "suggestion" can be in the middle of string like here
Screenshot 2025-03-03 at 19 07 58

And indeed the problem with symbols after:

    "prompt": "QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);\n\n    QStringList colors{};\n    123",
    "suffix": "\n    QObject::connect(\n        &engine,\n        &QQmlApplicationEngine::objectCreationFailed,\n        &app,\n        []() { QCoreApplication::exit(-1); },\n        Qt::QueuedConnection);\n    engine.loadFromModule(\"TestRowlayout\", \"Main\");\n\n    return app.exec();\n}\n",

I lost here "456"
Do you want to fix that? Or I will take it?

@p12tic
Copy link
Contributor Author

p12tic commented Mar 3, 2025

Do you want to fix that? Or I will take it?

I can fix it. I did not know what is the expected behavior, in fact your approach was how I started fixing the bug :-) I think I have stash somewhere still.

@p12tic p12tic closed this Mar 4, 2025
@p12tic p12tic reopened this Mar 5, 2025
@p12tic p12tic force-pushed the fix-whole-file-context branch from 912e7a4 to cd56cd6 Compare March 5, 2025 17:16
@p12tic
Copy link
Contributor Author

p12tic commented Mar 5, 2025

@Palm1r Pushed fixes. This PR is very similar to your PR, except that I make getContextBetween() more generic so that it can pick characters from any two points in a file.

@p12tic
Copy link
Contributor Author

p12tic commented Mar 5, 2025

There are still semi-related problems, will fix these via separate PRs.

if (i == endLine) {
context += block.text().left(cursorPosition);
auto text = block.text();
if (i == startLine && startCursorPosition >= 0) {
Copy link
Owner

Choose a reason for hiding this comment

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

but seems startCursorPosition and endCursorPosition can be same

Copy link
Owner

Choose a reason for hiding this comment

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

just cursorPosition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because the function does not know which cursor cursorPosition refers to. It may be referring to the start line, or it can refer to end line.

Currently the current line is duplicated in both "before" and "after"
context. This is due to DocumentContextReader::readWholeFileAfter()
picking the current line part of which has been already included into
the "before" context.
@p12tic p12tic force-pushed the fix-whole-file-context branch from cd56cd6 to c6fca23 Compare March 5, 2025 17:44
@p12tic
Copy link
Contributor Author

p12tic commented Mar 5, 2025

I've added handling for way more edge cases, and also appropriate tests.

@Palm1r Palm1r merged commit f9f2a86 into Palm1r:main Mar 5, 2025
6 checks passed
@p12tic p12tic deleted the fix-whole-file-context branch March 5, 2025 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants