Docfile - A declarative autocomplete plugin

Docfile

Declarative autocomplete plujgin.

With the release of the new RegisterAutocompleteCallback function, I think its time to ship something like this.

Get documentation for any library, function or object

Given it has a .docfile module, Docfile can provide typing for many libraries almost straight away when the Auto-register new .DOCFILE objects action is enabled

#]

Its also insanely easy to install docfile modules that aren’t in libraries by simply clicking on the module and pressing Register DOCFILE

Docfile can override any token with a given match, as seen above where I’m overriding a table as a constructor (lol)

Docfile is declarative

Docfile scripts are 100% declarative which makes them quick and easy to write and ship with your codebase.

Docfile Documentation

Every docfile must return the following struct:

{
  MacroName: string -- used internally to pair modules and callback to documentation
  TargetFIleName: string -- string pattern to match against, ie: %.spec$ matches against scripts ending in .spec
  Patterns: {
    { --used to write overwrite rules
      MatchMode: string -- what key to match against in the response body
      Value: string -- value to match against key
      Overrides: {[string]: any} -- values to override if match is found
    }
  }
  ChildPatterns: { --same as patterns but used for matching sub-objects
    { --denotes a group that needs to be matched
      {Pattern} -- see pattern
    }
  },
  Injects: ([string]: any} -- extra members to add to the autocomplete, only used if no child matches are found
}

An example of this struct is as follows, this is based on the Tabby framework

deadly dangerous secret configs...

AllowImpureShapeInChildPatterns

Setting this to true will make the internal child pattern searcher not respect the size of the response body when matching. This is designed for debugging autocompletes

Injects

WIP, still figuring out design specs around this

Get docfile:

Sourcecode:

12 Likes

I’m sorry, why are you using off brand Comic Sans MS to program? My eyes are currently burning.

Other than that, very cool plugin! I’ll be sure to check it out.

Because its better than comic sans MS

Comic Mono is the best font I’ve used in a while, its something I’ve found is the best font for me over what I previously used, Fira Code (which dont get me wrong, thats a good font as well).

Font choice is personal preference, if you dont like it, it doesn’t mean somone also doesn’t like it. Its the same principle as editor themes.

This is awesome!

Question, how did you manage to get the replacement text to function properly?
Working on my own verison of a plugin atm but I can’t get past the textEdit.

It’s nearly complete the only issue is that when the snippet of code is replaced where the autocomplete is detected.

local FocusedScript = ScriptEditorService:FindScriptDocument(Request.textDocument.script)

local SelectStartPosition = FocusedScript:GetSelectionStart()
local SelectEndPosition = FocusedScript:GetSelectionEnd()

table.insert(Response.items, {
	label = "snip",
	kind = Enum.CompletionItemKind.File,
	details = "",
	preselect = true,
	codeSample = "",
	textEdit = {
		newText = "snip",
		replace = {
			start = {line = SelectStartPosition, character = SelectStartPosition},
			["end"] = {line = SelectEndPosition, character = SelectEndPosition}
		}
	}
})

Thank you for your time.

it doesn’t implement any autocomplete macros (unless you use the scary Injects key), the plugin is designed to match against keywords (MatchMode) with a value and then override it from the overrides table

I dont actually know how replace works lol

Yeah it’s a struggle.
You’d think there would be info on the doc website aswell.
(Also kinda annoyed there is no GetAutocompleteCallback method so you sometimes have to blindly call DeregisterAutocompleteCallback and deal with an error or not.)

Source code? Source code!
(Tabby isn’t ready to ship so i had to make it a seperate upload lol)