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

Implement AutocompleteMetadata and add autofills #28

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
- Improved documentation provided in autofill, and added relevant Developer Reference links.
- Added color picker support to Color3.fromHSV().
- Added support for ReflectionMetadata. This now downloads the file and injects descriptions to be used.
- Added support for the Lua Libraries available in Roblox (math, string, os, etc.).
- Added support for static methods and properties of Roblox Datatypes (Vector3, Color3, etc.).
- Fixed Instance.new popping up whenever you typed a "." (dot).

## [1.7.1]
- Service auto-importer will now suggest for non-idiomatic whitespace in service declarations.
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

212 changes: 212 additions & 0 deletions src/autocompleteDump.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
import * as request from "request-promise-native"
import * as vscode from "vscode"
import { parseStringPromise } from "xml2js"

const AUTOCOMPLETE_METADATA = "https://raw.githubusercontent.com/CloneTrooper1019/Roblox-Client-Tracker/roblox/AutocompleteMetadata.xml"

export interface AutocompleteParameter {
type: string,
name: string,
optional: boolean,
constraint?: string,
}

export interface AutocompleteReturn {
type: string,
name?: string,
}

export interface AutocompleteFunction {
name: string,
static: boolean,
description?: string,
parameters: AutocompleteParameter[],
returns: AutocompleteReturn[],
}

export interface AutocompleteProperty {
name: string,
static: boolean,
type: string,
description?: string,
}

export interface AutocompleteGroup {
name: string,
functions: AutocompleteFunction[],
properties: AutocompleteProperty[],
}

export interface AutocompleteDump {
LuaLibrary: AutocompleteGroup[],
ItemStruct: AutocompleteGroup[],
}

// Interfaces for the data provided in the XML parser
interface XMLPropertyPart {
_: string, // Description
$: {
name: string,
static?: string,
},
}

interface XMLOrderedPropertyPart extends XMLPropertyPart {
"#name": string, // Property type
}

interface XMLProperty {
$$: XMLOrderedPropertyPart[],
[name: string]: XMLPropertyPart[]
}

interface XMLFunctionReturnPart {
$?: {
name?: string,
}
}

interface XMLOrderedFunctionReturnPart extends XMLFunctionReturnPart {
"#name": string,
}

interface XMLFunctionParameterPart {
$: {
name: string,
constraint?: string,
optional?: string,
},
}

interface XMLOrderedFunctionParameterPart extends XMLFunctionParameterPart {
"#name": string,
}

interface XMLFunction {
$: {
name: string,
static: string,
},
returns: Array<{
$$: XMLOrderedFunctionReturnPart[],
[name: string]: XMLFunctionReturnPart[],
}>,
parameters: Array<{
$$: XMLOrderedFunctionParameterPart[],
[name: string]: XMLFunctionParameterPart[],
}>,
description: string[],
}

interface XMLGroup {
$: {
name: string,
},
Function?: XMLFunction[],
Properties?: XMLProperty[],
}

interface XMLTree {
StudioAutocomplete: {
LuaLibrary: XMLGroup[],
ItemStruct: XMLGroup[],
CoreLibrary: XMLGroup[]
ReservedWords: Array<{
$$: Array<{
$: {
name: string,
},
"#name": string,
}>,
Keyword: Array<{
$: {
name: string,
},
}>,
}>,
},
}

const formatFunction = (func: XMLFunction): AutocompleteFunction => {
const attributes = func.$
const parameters: AutocompleteParameter[] =
(func.parameters && func.parameters[0].$$) ? func.parameters[0].$$.map(paramObj => {
const type = paramObj["#name"]
const parameterAttributes = paramObj.$
return {
constraint: parameterAttributes.constraint,
name: parameterAttributes.name,
optional: parameterAttributes.optional === "true",
type,
}
}) : []

const returns = (func.returns && func.returns[0].$$) ? func.returns[0].$$.map(ret => {
const type = ret["#name"]
const returnAttributes = ret.$
return {
name: returnAttributes && returnAttributes.name,
type,
}
}) : []

return {
description: func.description && func.description[0],
name: attributes.name,
parameters,
returns,
static: attributes.static === "true",
}
}

const formatProperty = (property: XMLOrderedPropertyPart): AutocompleteProperty => {
const description = property._
JohnnyMorganz marked this conversation as resolved.
Show resolved Hide resolved
const type = property["#name"]
const attributes = property.$
return {
description,
name: attributes.name,
static: attributes.static === "true",
type,
}
}

const formatGroup = (group: XMLGroup): AutocompleteGroup => {
return {
functions: group.Function ? group.Function.map(formatFunction) : [],
name: group.$.name,
properties: (group.Properties && group.Properties[0].$$) ? group.Properties[0].$$.map(formatProperty) : [],
}
}

const formatter = (tree: XMLTree): AutocompleteDump => {
const root = tree.StudioAutocomplete
const LuaLibrary = root.LuaLibrary
const ItemStruct = root.ItemStruct

const updatedLibrary = LuaLibrary.map(formatGroup)
const updatedItemStruct = ItemStruct.map(formatGroup)

return {
ItemStruct: updatedItemStruct,
LuaLibrary: updatedLibrary,
}
}

const autocompleteMetadataPromise = (async () => {
const data = await request(AUTOCOMPLETE_METADATA).catch((err) => {
vscode.window.showErrorMessage("Error downloading Autocomplete Metadata dump", err.toString())
})

const output = await parseStringPromise(data, {
JohnnyMorganz marked this conversation as resolved.
Show resolved Hide resolved
explicitChildren: true,
preserveChildrenOrder: true,
trim: true,
})

return formatter(output)
})()

export function getAutocompleteDump(): Promise<AutocompleteDump> {
return autocompleteMetadataPromise
}
6 changes: 4 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import * as vscode from "vscode"
import { RobloxColorProvider } from "./color"
import { Companion } from "./companion"
import { EnumCompletionProvider } from "./enum"
import { InstanceCompletionProvider } from "./instance"
import { ItemStructCompletionProvider } from "./itemStruct"
import { LuaLibraryCompletionProvider } from "./luaLibrary"
import { RojoHandler } from "./rojo"
import { ServiceCompletionProvider } from "./services"
const SELECTOR = { scheme: "file", language: "lua" }
Expand Down Expand Up @@ -38,7 +39,8 @@ export async function activate(context: vscode.ExtensionContext) {

context.subscriptions.push(vscode.languages.registerColorProvider(SELECTOR, new RobloxColorProvider()))

context.subscriptions.push(vscode.languages.registerCompletionItemProvider(SELECTOR, new InstanceCompletionProvider(), "."))
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(SELECTOR, new EnumCompletionProvider(), "."))
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(SELECTOR, new ServiceCompletionProvider(), ".", ":"))
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(SELECTOR, new LuaLibraryCompletionProvider(), "."))
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(SELECTOR, new ItemStructCompletionProvider(), "."))
}
37 changes: 0 additions & 37 deletions src/instance.ts

This file was deleted.

Loading