Skip to content

Commit

Permalink
- centralize settings & add gifs
Browse files Browse the repository at this point in the history
  • Loading branch information
lunarwtr committed Mar 19, 2022
1 parent 0fb26c3 commit cdd3236
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 43 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to the "vscode-lotro-api" extension will be documented in th

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [1.0.6] - 2022-03-19
### Added
- Improvement: Added more snippets for lua files
- Improvement: Hyperlinks to hosted lua documentation
- Improvement: Usage GIFs of features
- Improvement: Centralized settings to workspace

## [1.0.5] - 2022-03-16
### Added
- Fix: file association now fixed for new .plugin & .plugincompendium files
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Adds IntelliSense features for Lord of the Rings Online API to VS Code. This ext
### Features

* IntelliSense for Lord of the Rings Online LUA API (v32.0.4)
![](https://github.com/lunarwtr/vscode-lotro-api/raw/main/img/api.gif)
* IntelliSense for LotRO `.plugin` and `.plugincompendium` file xml
![](https://github.com/lunarwtr/vscode-lotro-api/raw/main/img/plugin.gif)
* Code snippets to make coding Plugins easier
* Undocumented objects, methods and events.

Expand Down
Binary file added img/api.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/plugin.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lotro-api",
"displayName": "LotRO API",
"description": "Lord of the Rings Online API",
"version": "1.0.5",
"version": "1.0.6",
"publisher": "lunarwtr",
"repository": {
"type": "git",
Expand Down
65 changes: 23 additions & 42 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ interface XMLSchemaAssocation {
// this method is called when your extension is activated
export function activate(context: vscode.ExtensionContext) {
console.log("activate lunarwtr.lotro-api", context.extension.id);
setExternalLibrary("Turbine", true);

const extensionPath = vscode.extensions.getExtension(context.extension.id)?.extensionPath;
const config = vscode.workspace.getConfiguration("Lua");
Expand All @@ -20,23 +19,36 @@ export function activate(context: vscode.ExtensionContext) {
}
config.update("runtime.version", "Lua 5.1");
config.update("runtime.pathStrict", false);
config.update("runtime.plugin", path.join(extensionPath!, 'Lua', 'Plugin', 'plugin.lua'));
const searchPaths: string[] | undefined = config.get("runtime.path");
if (searchPaths) {
if (searchPaths.indexOf('?/__init__.lua') === -1) {
searchPaths.push('?/__init__.lua');
}
config.update("runtime.path",searchPaths);
}


const xmlConfig = vscode.workspace.getConfiguration("xml");
let schemasAssoc: XMLSchemaAssocation[] | undefined = xmlConfig.get("fileAssociations");
if (schemasAssoc) {
schemasAssoc = schemasAssoc.filter(a => !/\.plugin(compendium)?$/.test(a.pattern));
schemasAssoc.push({ pattern: '**/*.plugin', systemId: path.join(extensionPath!, 'xsds', 'lotroplugin.xsd')});
schemasAssoc.push({ pattern: '**/*.plugincompendium', systemId: path.join(extensionPath!, 'xsds', 'plugincompendium.xsd')});
xmlConfig.update("fileAssociations", schemasAssoc);
if (extensionPath) {
// define plugin location
config.update("runtime.plugin", path.join(extensionPath!, 'Lua', 'Plugin', 'plugin.lua'));
// define API library location
const library: string[] | undefined = config.get("workspace.library");
if (library) {
const filteredLib = library.filter(a => !/vscode-lotro-api/.test(a) && a.indexOf(context.extension.id) === -1);
if (library.length > 0 && filteredLib.length !== library.length) {
// early version settings were placed in global settings.. update them
config.update("workspace.library", filteredLib, true);
}
filteredLib.push(path.join(extensionPath!, 'Lua', 'EmmyLua', 'Turbine'));
config.update("workspace.library", filteredLib);
}
// define plugin association and schema locations
const xmlConfig = vscode.workspace.getConfiguration("xml");
let schemasAssoc: XMLSchemaAssocation[] | undefined = xmlConfig.get("fileAssociations");
if (schemasAssoc) {
schemasAssoc = schemasAssoc.filter(a => !/\.plugin(compendium)?$/.test(a.pattern));
schemasAssoc.push({ pattern: '**/*.plugin', systemId: path.join(extensionPath!, 'xsds', 'lotroplugin.xsd')});
schemasAssoc.push({ pattern: '**/*.plugincompendium', systemId: path.join(extensionPath!, 'xsds', 'plugincompendium.xsd')});
xmlConfig.update("fileAssociations", schemasAssoc);
}
}
const filesConfig = vscode.workspace.getConfiguration("files");
let associations: {[id: string] : string} | undefined = filesConfig.get("associations");
Expand All @@ -50,35 +62,4 @@ export function activate(context: vscode.ExtensionContext) {
// this method is called when your extension is deactivated
export function deactivate() {
console.log("deactivate lunarwtr.lotro-api");
setExternalLibrary("Turbine", false);
}

function setExternalLibrary(folder: string, enable: boolean) {
const extensionId = "lunarwtr.lotro-api"; // this id is case sensitive
const extensionPath = vscode.extensions.getExtension(extensionId)?.extensionPath;
const folderPath = path.join(extensionPath!, 'Lua', 'EmmyLua', folder);
const config = vscode.workspace.getConfiguration("Lua");
const library: string[] | undefined = config.get("workspace.library");
if (library && extensionPath) {
// remove any older versions of our path e.g. "publisher.name-0.0.1"
for (let i = library.length-1; i >= 0; i--) {
const el = library[i];
const isSelfExtension = el.indexOf(extensionId) > -1;
const isCurrentVersion = el.indexOf(extensionPath) > -1;
if (isSelfExtension && !isCurrentVersion) {
library.splice(i, 1);
}
}
const index = library.indexOf(folderPath);
if (enable) {
if (index === -1) {
library.push(folderPath);
}
} else {
if (index > -1) {
library.splice(index, 1);
}
}
config.update("workspace.library", library, true);
}
}

0 comments on commit cdd3236

Please sign in to comment.