Skip to content

Commit 457af5f

Browse files
committed
Update to aglint 4.0.0-alpha.8
- Add adblock.enableAglintDebug configuration option (default: false) - Add adblock.enableAglintCache configuration option (default: true) - Implement LRU cache for linting results with cache key based on URI, AGLint version, document version, and config hash - Extract AGLint-related state into AglintContext class - Add ESLint rule to restrict direct imports from @adguard/aglint in server code - Update AGLint to v4.0.0-alpha.8 - Remove
1 parent fb434cb commit 457af5f

10 files changed

Lines changed: 363 additions & 114 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ This extension provides the following configuration options:
103103
| Option | Description | Default value | Possible values |
104104
| ------ | ----------- | ------------- | --------------- |
105105
| `adblock.enableAglint` | Enable or disable AGLint integration. If disabled, only syntax highlighting and other language features will be available. | `true` | `true`, `false` |
106+
| `adblock.enableAglintDebug` | Enable or disable AGLint debug logging. | `false` | `true`, `false` |
107+
| `adblock.enableAglintCache` | Enable or disable caching of linting results for better performance. | `true` | `true`, `false` |
106108
<!--markdownlint-enable MD013-->
107109

108110
### GitHub Linguist support

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@
6565
"type": "boolean",
6666
"default": true,
6767
"description": "Enable or disable AGLint integration. If disabled, only syntax highlighting and other language features will be available."
68+
},
69+
"adblock.enableAglintDebug": {
70+
"scope": "resource",
71+
"type": "boolean",
72+
"default": false,
73+
"description": "Enable or disable AGLint debug logging."
74+
},
75+
"adblock.enableAglintCache": {
76+
"scope": "resource",
77+
"type": "boolean",
78+
"default": true,
79+
"description": "Enable or disable caching of linting results for better performance."
6880
}
6981
}
7082
}
@@ -139,7 +151,6 @@
139151
"yaml": "^2.2.2"
140152
},
141153
"pnpm": {
142-
"neverBuiltDependencies": [],
143-
"overrides": {}
154+
"neverBuiltDependencies": []
144155
}
145156
}

pnpm-lock.yaml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ packages:
44
- test/static/aglint
55

66
catalog:
7-
'@adguard/aglint': ^4.0.0-alpha.7
7+
'@adguard/aglint': ^4.0.0-alpha.8

server/.eslintrc.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
extends: '../.eslintrc.cjs',
3+
rules: {
4+
'no-restricted-imports': 'off',
5+
'@typescript-eslint/no-restricted-imports': [
6+
'error',
7+
{
8+
patterns: [
9+
{
10+
group: ['@adguard/aglint', '@adguard/aglint/*'],
11+
allowTypeImports: true,
12+
},
13+
],
14+
},
15+
],
16+
},
17+
};
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import type {
2+
Debug,
3+
FileSystemAdapter,
4+
LinterTree,
5+
PathAdapter,
6+
} from '@adguard/aglint/cli';
7+
import type { Connection, TextDocuments } from 'vscode-languageserver/node';
8+
import type { TextDocument } from 'vscode-languageserver-textdocument';
9+
10+
import { LSPFileSystemAdapter } from '../adapters/fs';
11+
import type { LoadedAglint } from '../utils/aglint-loader';
12+
import { loadAglintModule } from '../utils/aglint-loader';
13+
14+
/**
15+
* Encapsulates all AGLint-related state and dependencies.
16+
*/
17+
export class AglintContext {
18+
/**
19+
* Loaded AGLint module.
20+
*/
21+
public aglint: LoadedAglint;
22+
23+
/**
24+
* Debug instance.
25+
*/
26+
public debuggerInstance: Debug;
27+
28+
/**
29+
* File system adapter.
30+
*/
31+
public fsAdapter: FileSystemAdapter;
32+
33+
/**
34+
* Path adapter.
35+
*/
36+
public pathAdapter: PathAdapter;
37+
38+
/**
39+
* Linter tree.
40+
*/
41+
public linterTree: LinterTree;
42+
43+
/**
44+
* Creates a new AGLint context.
45+
*
46+
* @param aglint Loaded AGLint module.
47+
* @param debuggerInstance Debug instance.
48+
* @param fsAdapter File system adapter.
49+
* @param pathAdapter Path adapter.
50+
* @param linterTree Linter tree.
51+
*/
52+
constructor(
53+
aglint: LoadedAglint,
54+
debuggerInstance: Debug,
55+
fsAdapter: FileSystemAdapter,
56+
pathAdapter: PathAdapter,
57+
linterTree: LinterTree,
58+
) {
59+
this.aglint = aglint;
60+
this.debuggerInstance = debuggerInstance;
61+
this.fsAdapter = fsAdapter;
62+
this.pathAdapter = pathAdapter;
63+
this.linterTree = linterTree;
64+
}
65+
66+
/**
67+
* Create and initialize a new AGLint context.
68+
*
69+
* @param connection Language server connection.
70+
* @param documents Text document manager.
71+
* @param root Workspace root path.
72+
* @param enableDebug Whether to enable debug logging.
73+
*
74+
* @returns Initialized AGLint context or undefined if initialization failed.
75+
*/
76+
public static async create(
77+
connection: Connection,
78+
documents: TextDocuments<TextDocument>,
79+
root: string,
80+
enableDebug: boolean,
81+
): Promise<AglintContext | undefined> {
82+
const aglint = await loadAglintModule(connection, root);
83+
84+
if (!aglint) {
85+
connection.console.error('AGLint module could not be loaded');
86+
return undefined;
87+
}
88+
89+
connection.console.info(`AGLint module loaded (version: ${aglint.version})`);
90+
91+
const pathAdapter = new aglint.cli.NodePathAdapter();
92+
const fsAdapter = new LSPFileSystemAdapter(documents);
93+
94+
const debuggerInstance = new aglint.cli.Debug({
95+
enabled: enableDebug,
96+
printTimestamps: false,
97+
printElapsed: false,
98+
colors: false,
99+
logger: (message) => connection.console.info(`[AGLint debug] ${message}`),
100+
});
101+
102+
const configResolver = new aglint.cli.ConfigResolver(
103+
fsAdapter,
104+
pathAdapter,
105+
{
106+
presetsRoot: aglint.presetsRoot,
107+
baseConfig: {},
108+
},
109+
debuggerInstance.module('config-resolver'),
110+
);
111+
112+
const linterTree = new aglint.cli.LinterTree(
113+
fsAdapter,
114+
pathAdapter,
115+
{
116+
configFileNames: aglint.cli.CONFIG_FILE_NAMES,
117+
ignoreFileName: aglint.cli.IGNORE_FILE_NAME,
118+
root,
119+
},
120+
{
121+
resolve: (p) => configResolver.resolve(p),
122+
isRoot: (p) => configResolver.isRoot(p),
123+
invalidate: (p) => configResolver.invalidate(p),
124+
},
125+
debuggerInstance.module('linter-tree'),
126+
);
127+
128+
return new AglintContext(aglint, debuggerInstance, fsAdapter, pathAdapter, linterTree);
129+
}
130+
}

0 commit comments

Comments
 (0)