0ad/binaries/data/mods/mod/tools/dap/managers/sources.js
Dunedan 93ce94655d
Use @stylistic/brace-style for eslint
Up to now `eslint-plugin-brace-rules` was used to enforce a common brace
style for JavaScript code. This plugin was however updated the last time
over 9 years ago and will be incompatible with ESLint v10, as that
[removes `context.getSourceCode()`][1], the plugin relies on.

To keep the eslint config working with ESLint v10, this replaces
`eslint-plugin-brace-rules` with the [`@stylistic/brace-style`][2] rule
from `@stylistic/eslint-plugin`, a package we already use.

While `@stylistic/brace-style` doesn't offer an option to format braces
in exactly the same way as before, the "allman" style seems to be the
one closest to the existing code.

[1]: https://eslint.org/blog/2025/11/eslint-v10.0.0-alpha.0-released/#removed-deprecated-rule-context-members
[2]: https://eslint.style/rules/brace-style
2026-01-12 21:33:52 +01:00

100 lines
2.8 KiB
JavaScript

import { Plugin } from 'tools/dap/plugin.js';
class SourcesManager extends Plugin
{
constructor(jsDebugger, dapHandler)
{
super('SourcesManager', 'manager');
this.jsDebugger = jsDebugger;
this.logger.debug('Setting up SourcesManager');
jsDebugger.on('onNewScript', ({ script, global }) =>
{
if (!jsDebugger.debuggerAttached)
return;
this.logger.debug(`New script loaded: ${script.url}`);
const url = script.url;
let index = this.jsDebugger.sourcesReferences.findIndex((src) => src.path === url);
if (index === -1)
{
this.jsDebugger.sourcesReferences.push({
'path': url,
'source': script.source
});
index = this.jsDebugger.sourcesReferences.length - 1;
}
jsDebugger.pushEvent('loadedSource', {
'reason': 'new',
'source': {
'path': url,
'sourceReference': index + 1
}
}, this.name);
}, this.name);
jsDebugger.on('onDebuggerDetached', () =>
{
this.logger.debug('Debugger detached');
this.jsDebugger.sourcesReferences = [];
}, this.name);
jsDebugger.on('onDebuggerAttached', () =>
{
this.logger.debug('Debugger attached');
this.jsDebugger.sourcesReferences = [];
this.jsDebugger.instance.findSources().forEach((source) =>
{
const url = source.url;
if (this.jsDebugger.sourcesReferences.some((src) => src.path === url))
return;
this.jsDebugger.sourcesReferences.push({
'path': url,
'source': source,
});
});
}, this.name);
dapHandler.registerCommand('loadedSources', (req) =>
{
if (!jsDebugger.debuggerAttached)
{
this.logger.error('Debugger not attached, cannot handle loadedSources command');
return dapHandler.errorResponse(req, 'Debugger not attached');
}
this.logger.info('Handling loadedSources command');
const sources = this.jsDebugger.sourcesReferences.map((src, index) => ({
'sourceReference': index + 1,
'path': src.path,
'origin': 'Pyrogenesis'
}));
return dapHandler.successResponse(req, { 'sources': sources });
});
dapHandler.registerCommand('source', (req) =>
{
if (!jsDebugger.debuggerAttached)
{
this.logger.error('Debugger not attached, cannot handle source command');
return dapHandler.errorResponse(req, 'Debugger not attached');
}
const sourceRef = req.arguments.sourceReference;
if (sourceRef < 1 || sourceRef > this.jsDebugger.sourcesReferences.length)
{
this.logger.error(`Invalid source reference: ${sourceRef}`);
return dapHandler.errorResponse(req, 'Invalid source reference');
}
const source = this.jsDebugger.sourcesReferences[sourceRef - 1];
this.logger.info(`Handling source command for reference: ${sourceRef}`);
return dapHandler.successResponse(req, {
'content': source.source.text
});
});
}
}
export default SourcesManager;