Skip to content

Commit

Permalink
feat: Allow selection of documentation pages
Browse files Browse the repository at this point in the history
  • Loading branch information
rvost committed Oct 11, 2023
1 parent 8129332 commit c69f924
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 30 deletions.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
"category": "DayZ CE"
}
],
"menus": {
"commandPalette": [
{
"command": "dayz-ce-schema.showDocumentation",
"when": "editorIsOpen"
}
]
},
"jsonValidation": [
{
"fileMatch": [
Expand Down
152 changes: 122 additions & 30 deletions src/documentationProvider.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,158 @@
import * as vscode from "vscode";
import { minimatch } from "minimatch";

const associations = [
type DocumentationLink = { title: string, url: string };

type DocumentationAssociation = {
pattern: string,
links: DocumentationLink[]
};

const associations: DocumentationAssociation[] = [
{
pattern: "**/cfgeffectarea.json",
url: "https://community.bistudio.com/wiki/DayZ:Contaminated_Areas_Configuration"
links: [
{
title: "Wiki Page: Contaminated Areas Configuration",
url: "https://community.bistudio.com/wiki/DayZ:Contaminated_Areas_Configuration"
}
]
},
{
pattern: "**/cfggameplay.json",
url: "https://community.bistudio.com/wiki/DayZ:Gameplay_Settings"
links: [
{
title: "Wiki Page: Gameplay Settings",
url: "https://community.bistudio.com/wiki/DayZ:Gameplay_Settings"
}
]
},
{
pattern: "**/cfgundergroundtriggers.json",
url: "https://community.bistudio.com/wiki/DayZ:Underground_Areas_Configuration"
links: [
{
title: "Wiki Page: Underground Areas Configuration",
url: "https://community.bistudio.com/wiki/DayZ:Underground_Areas_Configuration"
}
]
},
{
pattern: "**/cfgeconomycore.xml",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding"
links: [
{
title: "Wiki Page: Central Economy Configuration",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_Configuration#cfgEconomyCore.xml"
},
{
title: "Wiki Page: Central Economy mission files modding",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding"
}
]
},
{
pattern: "**/cfgweather.xml",
url: "https://community.bistudio.com/wiki/DayZ:Weather_Configuration"
links: [
{
title: "Wiki Page: Weather Configuration",
url: "https://community.bistudio.com/wiki/DayZ:Weather_Configuration"
}
]
},
{
pattern: "**/db/globals.xml",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_Configuration#db.5Cglobals.xml"
links: [
{
title: "Wiki Page: Central Economy Configuration",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_Configuration#db.5Cglobals.xml"
}
]
},
{
pattern: "**/db/economy.xml",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding#File_specifics"
},
{
pattern: "**/db/events.xml",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding#File_specifics"
},
pattern: "**/db/economy.xml",
links: [
{
title: "Wiki Page: Central Economy mission files modding",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding#File_specifics"
}
]
},
{
pattern: "**/db/messages.xml",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding#File_specifics"
},
pattern: "**/db/events.xml",
links: [
{
title: "Wiki Page: Central Economy mission files modding",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding#File_specifics"
}
]
},
{
pattern: "**/types*.xml",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding#File_specifics"
},
pattern: "**/db/messages.xml",
links: [
{
title: "Wiki Page: Central Economy mission files modding",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding#File_specifics"
}
]
},
{
pattern: "**/cfgspawnabletypes.xml",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding#File_specifics"
},
]
pattern: "**/types*.xml",
links: [
{
title: "Wiki Page: Central Economy mission files modding",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding#File_specifics"
},
{
title: "DayZ Forum thread: types.xml explanation",
url: "https://forums.dayz.com/topic/247502-typesxml-need-explanation/"
}
]
},
{
pattern: "**/cfgspawnabletypes.xml",
links: [
{
title: "Wiki Page: Central Economy mission files modding",
url: "https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding#File_specifics"
}
]
},
];

function toQuickPickItem(link: DocumentationLink) {
return {
label: link.title,
detail: link.url,
url: link.url
}
}

export const documentationCommand = "dayz-ce-schema.showDocumentation";

export function documentationHandler() {
export async function documentationHandler() {
const activeFileName = vscode.window.activeTextEditor?.document?.fileName;
if (!activeFileName) {
return;
}

let a = associations.find(a => minimatch(activeFileName, a.pattern, { nocase: true }))
if (a?.url) {
vscode.env.openExternal(vscode.Uri.parse(a.url));
}
else{
let matches = associations
.filter(a => minimatch(activeFileName, a.pattern, { nocase: true }))
.flatMap(a => a.links);

if (!matches) {
vscode.window.showInformationMessage("No documentation available for this file");
return;
}

if (matches.length == 1) {
vscode.env.openExternal(vscode.Uri.parse(matches[0].url));
return;
}
else {
const items = matches.map(toQuickPickItem);
const item = await vscode.window.showQuickPick(items, {placeHolder: "Pick page to open"});

if (item) {
vscode.env.openExternal(vscode.Uri.parse(item.url));
}
}
}

0 comments on commit c69f924

Please sign in to comment.