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

feat(new features): adds features, read pr for details #9

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3d8ebe4
bad code
sadan4 Aug 15, 2024
e1f9400
create draft commit
sadan4 Aug 18, 2024
50b6dae
add formatter
sadan4 Aug 19, 2024
940e9a3
add module diffing
sadan4 Aug 20, 2024
add041a
start work on webview
sadan4 Aug 21, 2024
d824542
non-ui part of client side reporter done
sadan4 Aug 21, 2024
0a850d1
delete unneeded files
sadan4 Aug 21, 2024
e74de09
things
sadan4 Aug 21, 2024
6b41f9a
webview works
sadan4 Aug 22, 2024
cf9be30
oops
sadan4 Aug 22, 2024
17c8e54
start working on webview commands
sadan4 Aug 24, 2024
d22471f
Add the stuff
cheesesamwich Aug 26, 2024
2f880f0
remove dummy data
sadan4 Aug 26, 2024
d46a10f
Merge pull request #1 from cheesesamwich/main
sadan4 Aug 26, 2024
e6e4cb9
add types to webview, fix csp, fix some bad logic, change a bit of th…
sadan4 Aug 27, 2024
8363424
add broken finds to it
sadan4 Aug 27, 2024
39482a6
how in gods name did this get comitted
sadan4 Aug 27, 2024
afd1195
guh
sadan4 Aug 28, 2024
22eeab1
guh
sadan4 Aug 28, 2024
7e6c5d3
guh guh
sadan4 Aug 30, 2024
dbcfe59
remove setting
sadan4 Aug 30, 2024
cf88029
guh
sadan4 Aug 30, 2024
141e94e
use esbuild for webview
sadan4 Aug 30, 2024
01491be
i love esbuild
sadan4 Aug 30, 2024
9d71423
oops
sadan4 Aug 30, 2024
8a3870f
general cleanup
sadan4 Aug 30, 2024
f22d11c
update gitingorte
sadan4 Aug 30, 2024
3ad7c5a
add postinstall script
sadan4 Aug 30, 2024
2965f29
cleanup build for webview fix the hide button
sadan4 Aug 31, 2024
36f4d21
add/update eslint
sadan4 Sep 2, 2024
9eb99c1
update eslint
sadan4 Sep 2, 2024
b0939bd
add LSP for webpack modules
sadan4 Sep 25, 2024
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
39 changes: 37 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,39 @@
"typecheck": "tsc --noEmit"
},
"contributes": {
"configuration": {
"title": "Vencord Companion configuration",
"properties": {
"vencord-companion.delModulesOnExit": {
"default": false,
"type": "boolean",
"description": "delete extracted modules on exit"
},
"vencord-companion.moduleSavePath": {
"type": "string",
"description": "The path to save extracted modules, only automatically works if delModulesOnExit is false",
"default": null
}
}
},
"commands": [
{
"command": "vencord-companion.diffModuleSearch",
"title": "Diff Module Search"
},
{
"command": "vencord-companion.diffModule",
"title": "Diff Module"
},
{
"command": "vencord-companion.extract",
"title": "Extract"
},
{
"command": "vencord-companion.extractSearch",
"title": "Extract With Search"
}
],
"snippets": [
{
"language": "typescript",
Expand All @@ -52,6 +85,7 @@
"onLanguage:typescriptreact"
],
"dependencies": {
"prettier": "^3.3.3",
"typescript": "^4.9.5",
"ws": "^8.12.1"
},
Expand Down Expand Up @@ -79,5 +113,6 @@
"sponsor": {
"url": "https://github.com/sponsors/Vendicated"
},
"homepage": "https://github.com/Vencord/Companion"
}
"homepage": "https://github.com/Vencord/Companion",
"packageManager": "[email protected]+sha512.9df9cf27c91715646c7d675d1c9c8e41f6fce88246f1318c1aa6a1ed1aeb3c4f032fcdf4ba63cc69c4fe6d634279176b5358727d8f2cc1e65b65f43ce2f8bfb0"
}
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

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

19 changes: 15 additions & 4 deletions src/PatchCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,24 @@ export class PatchCodeLensProvider implements CodeLensProvider {
if (!data) continue;

const range = new Range(document.positionAt(patch.properties.pos), document.positionAt(patch.properties.end));
const lens = new CodeLens(range, {
lenses.push(new CodeLens(range, {
title: "View Module",
command: "vencord-companion.extractSearch",
arguments: [data.find],
tooltip: "View Module"
}))
lenses.push(new CodeLens(range, {
title: "Diff Module",
command: "vencord-companion.diffModuleSearch",
arguments: [data.find],
tooltip: "Diff Module"
}))
lenses.push(new CodeLens(range, {
title: "Test Patch",
command: "vencord-companion.testPatch",
arguments: [data],
tooltip: "Test Patch",
});
lenses.push(lens);
tooltip: "Test Patch"
}));
}
return lenses;
}
Expand Down
12 changes: 12 additions & 0 deletions src/WebpackCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ export const WebpackCodeLensProvider: CodeLensProvider = {
const args = node.arguments.map(a => tryParseStringLiteral(a) ?? tryParseRegularExpressionLiteral(a) ?? tryParseFunction(document, a));

const range = new Range(document.positionAt(node.getStart()), document.positionAt(node.getEnd()));
lenses.push(new CodeLens(range, {
title: "View Module",
command: "vencord-companion.extractFind",
arguments: [{
type: "extractFind",
data: {
args: args.filter(isNotNull),
type
}
}],
tooltip: "View Module"
}))
lenses.push(new CodeLens(range, {
title: "Test Find",
command: "vencord-companion.testFind",
Expand Down
174 changes: 171 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { commands, ExtensionContext, languages, window as vscWindow } from "vscode";
import { commands, ExtensionContext, languages, QuickPickItem, window as vscWindow, window, workspace } from "vscode";
import { PatchCodeLensProvider } from "./PatchCodeLensProvider";
import { FindData, PatchData } from "./shared";
import { ExtractSendData, FindData, PatchData } from "./shared";
import { WebpackCodeLensProvider } from "./WebpackCodeLensProvider";
import { sendToSockets, startWebSocketServer, stopWebSocketServer } from "./webSocketServer";
import { moduleCache, sendToSockets, startWebSocketServer, stopWebSocketServer } from "./webSocketServer";
import generateFinds from "./findGenerator";

export function activate(context: ExtensionContext) {
startWebSocketServer();
Expand All @@ -16,6 +17,173 @@ export function activate(context: ExtensionContext) {
languages.registerCodeLensProvider({ language: "typescript" }, WebpackCodeLensProvider),
languages.registerCodeLensProvider({ language: "typescriptreact" }, WebpackCodeLensProvider),

workspace.registerTextDocumentContentProvider("vencord-companion", {
async provideTextDocumentContent(uri) {
console.log(uri)
//FIXME: full uri shows up in title bar
const newLocal = Buffer.from(uri.path.substring(1, uri.path.lastIndexOf(".")), "base64url");
return newLocal.toString()
},
}),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a really bad way to create a diff between two strings, but I tried for like a few hours and I couldn't figure out any other way


commands.registerCommand("vencord-companion.generateFinds", async (args) => {
console.log(generateFinds());
}),
commands.registerCommand("vencord-companion.diffModule", async args => {
if (args)
return sendToSockets({
type: "search",
data: {
extractType: "id",
idOrSearch: args
}
})
const quickPick = window.createQuickPick();
quickPick.placeholder = "module ID";
quickPick.canSelectMany = false;
const items: QuickPickItem[] = [{ label: "", alwaysShow: false }, { label: "", kind: -1 }, ...(moduleCache.map(m => { return { label: m }; }))];
quickPick.items = items;
quickPick.onDidChangeValue(() => {
if (!moduleCache.includes(quickPick.value)) {
items[0].label = quickPick.value;
items[0].alwaysShow = true;

} else {
items[0].alwaysShow = false;
}
quickPick.items = items
})
quickPick.show()
quickPick.onDidAccept(async () => {
const modId = quickPick.value;
quickPick.dispose();
if (!modId || isNaN(+modId))
return vscWindow.showErrorMessage("No Module ID provided")
try {
await sendToSockets({
type: "search",
data: {
extractType: "id",
idOrSearch: +modId
},
})
} catch (error) {
vscWindow.showErrorMessage(String(error))
}
})


}),
commands.registerCommand("vencord-companion.diffModuleSearch", async (args:string) => {
if (args)
return sendToSockets({
type: "diff",
data: {
extractType: "search",
idOrSearch: args
}
})
const input = await window.showInputBox();
if (!input)
return window.showErrorMessage("No Input Provided")
try {
await sendToSockets({
type: "diff",
data: {
extractType: "search",
idOrSearch: input
}
})
} catch (error) {
vscWindow.showErrorMessage(String(error))
}
}),
commands.registerCommand("vencord-companion.extractFind", async (args: {
type: string,
data: {
args: string[],
type: string
}
}) => {
if (!args)
return vscWindow.showErrorMessage("No Data Provided");
await sendToSockets({
type: "extract",
data: {
extractType: "find",
findType: args.data.type,
findArgs: args.data.args
}
})
}),
commands.registerCommand("vencord-companion.extract", async (args: number) => {
if (args)
return sendToSockets({
type: "extract",
data: {
extractType: "id",
idOrSearch: args
}
})
const quickPick = window.createQuickPick();
quickPick.placeholder = "module ID";
quickPick.canSelectMany = false;
const items: QuickPickItem[] = [{ label: "", alwaysShow: false }, { label: "", kind: -1 }, ...(moduleCache.map(m => { return { label: m }; }))];
quickPick.items = items;
quickPick.onDidChangeValue(() => {
if (!moduleCache.includes(quickPick.value)) {
items[0].label = quickPick.value;
items[0].alwaysShow = true;

} else {
items[0].alwaysShow = false;
}
quickPick.items = items
})
quickPick.show()
quickPick.onDidAccept(async () => {
const modId = quickPick.value;
quickPick.dispose();
if (!modId || isNaN(+modId))
return vscWindow.showErrorMessage("No Module ID provided")
try {
await sendToSockets({
type: "extract",
data: {
extractType: "id",
idOrSearch: +modId
} as ExtractSendData,
})
} catch (error) {
vscWindow.showErrorMessage(String(error))
}
})

}),
commands.registerCommand("vencord-companion.extractSearch", async (args: string) => {
if (args)
return sendToSockets({
type: "extract",
data: {
extractType: "search",
idOrSearch: args
}
})
const input = await window.showInputBox();
if (!input)
return window.showErrorMessage("No Input Provided")
try {
await sendToSockets({
type: "extract",
data: {
extractType: "search",
idOrSearch: input
}
})
} catch (error) {
vscWindow.showErrorMessage(String(error))
}
}),
commands.registerCommand("vencord-companion.testPatch", async (patch: PatchData) => {
try {
await sendToSockets({ type: "testPatch", data: patch });
Expand Down
13 changes: 13 additions & 0 deletions src/format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { format } from "prettier/standalone"
//@ts-ignore for some fucking reason, the d.ts file shows no exports when the mjs file clearly has them
import estree from "prettier/plugins/estree"
//@ts-ignore d.ts file strikes again, shows no default export. usage follows their own docs
import babel from "prettier/plugins/babel"

export default async function (text: string) {
return await format(text, {
parser: "babel",
plugins: [babel, estree],
tabWidth: 4
})
}
10 changes: 10 additions & 0 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export interface FunctionNode {
value: string;
}

export interface ExtractSendData {
extractType: string
idOrSearch: string | number,
}
export interface ExtraceRecieveData {
moduleNumber: number,
type: string,
data: string,
find?: boolean
}
export interface PatchData {
find: string | null;
replacement: {
Expand Down
Loading