Multi-language keyword autocompletion for the Webmin file editor

============================================================
CodeMirror Autocomplete for Virtualmin File Editor
Installation Guide

OVERVIEW

Adds keyword autocompletion to the Virtualmin File Editor for
20+ languages (PHP, Python, JS, CSS, HTML, SQL, Bash, Apache,
Nginx, systemd, Docker, YAML, JSON, Ruby, Go, and more).

Zero extra dependencies — uses the CodeMirror already bundled
with the Authentic Theme.

STEP 1 — Create the script file

Save the script to:

/usr/share/webmin/unauthenticated/js/intellisense.js

Command:

sudo nano /usr/share/webmin/unauthenticated/js/intellisense.js

Paste the full script (attached / linked below), save (Ctrl+O,
Enter) and exit (Ctrl+X).

Verify it exists:

ls -la /usr/share/webmin/unauthenticated/js/intellisense.js

STEP 2 — Edit the File Manager page

Open the File Manager CGI script:

sudo nano /usr/share/webmin/filemin/index.cgi

Press Ctrl+W, type “ui_print_footer” and hit Enter. You want
the LAST occurrence near the bottom of the file.

Just ABOVE that line, add:

print qq{<script src="/unauthenticated/js/intellisense.js"></script>\n};

So the result looks like:

print qq{<script src="/unauthenticated/js/intellisense.js"></script>\n};
&ui_print_footer(undef, undef, 1);

Save (Ctrl+O, Enter) and exit (Ctrl+X).

STEP 3 — Edit the standalone file editor page

Do exactly the same thing in the edit_file script:

sudo nano /usr/share/webmin/filemin/edit_file.cgi

Find the last “ui_print_footer”, add the same line above it:

print qq{<script src="/unauthenticated/js/intellisense.js"></script>\n};

Save and exit.

STEP 4 — Verify it works

  1. Open any file in the Virtualmin File Editor

  2. Press F12 to open your browser Developer Tools

  3. Go to the Console tab

  4. You should see:

    :white_check_mark: Autocomplete v2 active — php (377 keywords) [auto]

    (The language and keyword count will vary by file type.)

  5. Type at least 2 characters and pause — suggestions appear.
    Or press Ctrl+Space at any time to trigger manually.

If you do NOT see the message, do a hard refresh:

Ctrl+Shift+R  (Windows/Linux — Chrome, Edge, Firefox)
Cmd+Shift+R   (Mac)

NO RESTART REQUIRED

No need to restart Webmin. The script is loaded by the browser
on the next page load. It’s cached after the first load so
there’s no ongoing performance hit.

USAGE QUICK REFERENCE

Ctrl+Space Manually trigger autocomplete
Arrow keys Navigate suggestions
Enter / Tab Accept highlighted suggestion
Escape Dismiss the popup

Suggestions appear automatically after:
- Typing 2+ characters and pausing 300ms
- Typing $, ., >, :, or \ (instant trigger)

Snippets — type a short abbreviation then Ctrl+Space:
PHP: ife → if/else block, func → function, class → class
Apache: vhost → VirtualHost block, dir → Directory block
Nginx: server → server block, php → PHP location block
HTML: doc → full HTML5 document

TROUBLESHOOTING

Console says “unknown” language:
→ Make sure you have the latest script with the
CodeMirror mode fallback. Re-download from the source.

No popup appears at all:
→ Check Console for errors. If “CodeMirror hint addon
not available”, your Authentic Theme may be too old.

Works but feels slow on large files:
→ In the script, find the AUTO block and increase
“debounceMs” to 500 or lower “maxFileSize”.

Changes to the script don’t take effect:
→ Hard-refresh the page (Ctrl+Shift+R). If that fails,
open DevTools → Network tab → check “Disable cache”
→ then refresh.
intellisense.zip (16.2 KB)

============================================================
CodeMirror Autocomplete v2.2.0 — Changelog

WHAT’S NEW

intellisensev2.2.0.zip (22.2 KB)

  1. DESCRIPTIONS IN THE DROPDOWN
    PHP functions now show a one-liner explanation next to the
    function name so you don’t have to guess what it does.

    Examples:
    strpos — Find the position of the first occurrence
    array_map — Apply a callback to the elements of arrays
    mysqli_connect — Open a new connection to the MySQL server
    json_encode — Returns the JSON representation of a value

    130+ PHP functions have descriptions. Items without one
    display as before — just the name.

  2. CONTEXT-AWARE FILTERING
    The autocomplete now notices what “family” of functions
    you’re typing and prioritises them.

    Type “array_” → array_map, array_filter, array_keys…
    Type “mysqli_” → mysqli_connect, mysqli_query, mysqli_fetch…
    Type “str_” → str_replace, strpos, str_contains…
    Type “preg_” → preg_match, preg_replace, preg_split…
    Type “file_” → file_get_contents, file_put_contents…
    Type “curl_” → curl_init, curl_setopt, curl_exec…
    Type “json_” → json_encode, json_decode…
    Type “$” → $_SERVER, $_GET, $_POST, $_SESSION…

    This works for any keyword prefix across any language, not
    just PHP. Other matches still appear below the prioritised
    ones — nothing is hidden.

  3. FOUR NEW LANGUAGES

    Markdown (.md, .markdown, .mdx)
    Headings, bold/italic, links, images, tables, lists,
    checkboxes, HTML details/summary, special characters.

    C / C++ (.c, .cpp, .cc, .cxx, .h, .hpp, .hh, .hxx)
    130+ keywords including C standard library functions
    (printf, malloc, memcpy, fopen, strlen…), C++ STL
    (vector, string, map, shared_ptr, cout, endl…), and
    preprocessor directives (#include, #define, #pragma…).

    Lua (.lua)
    150+ keywords covering core language, string library,
    table library, math, I/O, OS, debug, coroutines, and
    package/module functions.

    Makefile (Makefile, *.mk)
    100+ automatic variables ($@, $<, $^), built-in targets
    (.PHONY, .SUFFIXES), functions (wildcard, patsubst, shell,
    foreach…), and directives (ifeq, ifneq, define, include).

    htaccess (.htaccess, htaccess)
    Uses Apache completions — already had the directives,
    now the file triggers them automatically.

UPGRADE INSTRUCTIONS

Replace the file at:
/usr/share/webmin/unauthenticated/js/intellisense.js

with the v2.2.0 script (attached / linked below).

No CGI edits needed — the include line from v2.0/v2.1 remains
the same. Hard-refresh (Ctrl+Shift+R) the File Editor and
you’ll see the new version in the console:

:white_check_mark: Autocomplete v2 active — php (377 keywords, 130 described) [auto]

Does include the ability to add context to a php function that resides in the same file such as geany does ?

Not yet still getting there :soon_arrow:

Yes you can edit the file and add additional functions

What started as a single JavaScript file grew into a proper multi-language coding assistant with lint diagnostics right in your Webmin file editor.

Intellesense.zip (53.0 KB)

What’s New Since v2.x

Feature v2.x (Old) v3.4.1 (New)
Architecture One monolithic 875-line JS file with all data embedded Lightweight engine (596 lines) + 20 JSON language packs loaded on demand
Lint diagnostics None Built-in — lines highlight orange (warning) or red (error) with hover tooltips explaining the issue
File switching Broke when switching between tabs Fully fixed — detects file changes and reloads the correct language instantly
Type-aware completions Basic keyword matching $db-> shows PDO/mysqli methods, $this-> shows class properties/methods, new shows class names
Document word scanning None Parses your open file for variables, functions, classes and adds them to completions
Context-aware ranking Simple prefix match C++ scope (::), JS dot access, PHP arrow operators all trigger the right completions first
Trigger characters > fired spurious hints on every HTML tag close Fixed — > no longer a trigger; -> combos still work for PHP/C++
Install size 73KB always loaded ~55KB engine + individual JSON files (2-22KB each, loaded only when needed)
  1. One JavaScript engine/unauthenticated/js/intellisense.js
  2. 20 JSON language packs/unauthenticated/js/intellisense/{php,html,css,python,javascript,sql,go,ruby,perl,lua,nginx,dockerfile,systemd,yaml,json,xml,toml,ini,markdown,makefile,postfix}.json
  3. Two one-line CGI edits (unchanged from v2.x) — add before the last &ui_print_footer in:
  • /usr/share/webmin/filemin/index.cgi
  • /usr/share/webmin/filemin/edit_file.cgi

PERL

print qq{<script src="/unauthenticated/js/intellisense.js"></script>\n};

When you open a file, the engine detects the language from the file extension/path, fetches only that language's JSON, and activates:

Keyword autocomplete — 2+ characters typed
Snippets — short triggers (ife, func, head, doc) expand to full code blocks with ${1:} tab-stop placeholders
Function signatures — e.g., strpos → strpos($haystack, $needle)
Argument completions — e.g., display: → flex | grid | block
Descriptions — hover-friendly explanations for PHP, Python, JS, CSS, SQL, Go, Lua functions
Lint rules — PHP (echo;, var_dump()), JS (== vs ===), SQL (DELETE FROM without WHERE), Python (print vs print()), and more
Type resolution — tracks $db = new PDO(...) then offers prepare(), query(), execute() on $db->

No restarts, no dependencies, no npm install. Just works™ with the existing CodeMirror 5 + show-hint addon already bundled in the Authentic Theme.
Feedback, bug reports, and JSON contributions welcome!

looking at php.json, I don’t quite get it this one for example

"ltrim": "Strip whitespace from the beginning",

isn’t exactly true as the php documentation gives the following

ltrim — Strip whitespace (or other characters) from the beginning of a string

as you can see from the function call there is an extra parameter that can be added to the function, so maybe add that to your description.
example from the php documentation

$text = "\t\tThese are a few words :) ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
$trimmed = ltrim($text); // does nothing as there is no white space to trim
$trimmed = ltrim($text, " \t."); // removes the tabs
$clean = ltrim($binary, "\x00..\x1F"); // removes binary

etc etc

Thanks man everyone can use and contribute to it. I just thought I would start something. Think it could be quite useful.

Will definitely add it.

I’ve been using php since inception (nearly) so if you want me to go through the php stuff I will, but where do I add my contributions ?

That said I’m not going to replace geany anytime soon as my coding work space is outside of webmin, I tend to just create a connection to the server and edit the files using geany

Here is a improved one

php.zip (9.4 KB)

I guess let me make a github repo then we can make contributes and so on there get more people to help if they want to.