Skip to content

Add language keyword candidates to auto-completion#1070

Open
saberoueslati wants to merge 2 commits into
dail8859:masterfrom
saberoueslati:feature/839-keyword-autocomplete
Open

Add language keyword candidates to auto-completion#1070
saberoueslati wants to merge 2 commits into
dail8859:masterfrom
saberoueslati:feature/839-keyword-autocomplete

Conversation

@saberoueslati

Copy link
Copy Markdown
Contributor

Description

Fixes #839

NotepadNext's auto-completion only suggests words already present in the document. This PR adds language keyword candidates to the completion list so keywords appear as suggestions even before they have been typed in the file. The change is gated by the existing Auto Completion preference and requires no new settings.


Changes

src/ScintillaNext.h

  • Added #include <QStringList> and a public QStringList languageKeywords member to hold the active language's keyword list alongside the existing languageName and languageSingleLineComment fields.

src/scripts/init.lua

  • Added GetLanguageKeywords(languageName) helper that reads languages[languageName].keywords, splits each space-separated keyword string into individual tokens, deduplicates them, recurses into additionalLanguages (matching SetLanguage's behaviour), and returns a sorted array. Returns {} for languages with no keyword definitions (e.g. plain Text).

src/NotepadNextApplication.cpp

  • Added one line at the end of setEditorLanguage() — calls GetLanguageKeywords(languageName) through the Lua state and stores the result in editor->languageKeywords. The field is unconditionally reassigned on every language change, so switching to Text or any other keyword-less language clears it automatically.

src/decorators/AutoCompletion.cpp

  • Extended showAutoCompletion() to iterate editor->languageKeywords after the document scan, inserting any keyword that starts with the current prefix into the existing QSet<QByteArray> candidate set. Deduplication is handled for free by the set. The 3-character minimum, SCFIND_MATCHCASE case-sensitivity, SC_ORDER_PERFORMSORT ordering, and the single Editor/AutoCompletion preference toggle are all preserved.

Video of manual test below :

Screencast.from.2026-06-02.21-34-24.webm

@dail8859 dail8859 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think the best implementation for now would be to move the languageKeywords to be stored in the AutoCompletion class and not in the editor since the AutoCompletion is the only place that uses it for now.

My thought is:

  • On AutoCompletion creation (or on the ScintillaNext::lexerChanged signal) call app->GetLanguageKeywords(lang) and store the returned value in a private list in AutoCompletion
  • app->GetLanguageKeywords(editor->languageName) would simply wrap the call to getLuaState()->executeAndReturn<QStringList>("return GetLanguageKeywords(languageName)");

That way the keywords don't live in the editor and the application is responsible for pulling lexer information.

@saberoueslati

Copy link
Copy Markdown
Contributor Author

@dail8859 I'll take care of it, I'll ping you as soon as I'm finished with it.

@saberoueslati

Copy link
Copy Markdown
Contributor Author

@dail8859 I made the changes as you requested

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.

Auto-completion does not include keywords

2 participants