mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-04-24 16:00:53 +08:00
feat(vscode): Load activeAppRoot from api.
$1h
This commit is contained in:
parent
433d5ba769
commit
7f3204ec04
packages/ides/vscode
pnpm-lock.yaml@ -22,6 +22,16 @@
|
||||
}
|
||||
},
|
||||
"contributes": {
|
||||
"configuration": {
|
||||
"title": "Lowdefy Developer Tools",
|
||||
"properties": {
|
||||
"lowdefyDevTools.localServerPort": {
|
||||
"type": "number",
|
||||
"default": 3000,
|
||||
"description": "Specifies the local server port of the running Lowdefy dev server."
|
||||
}
|
||||
}
|
||||
},
|
||||
"viewsContainers": {
|
||||
"activitybar": [
|
||||
{
|
||||
@ -98,6 +108,7 @@
|
||||
"@types/js-yaml": "4.0.9",
|
||||
"@types/mocha": "10.0.1",
|
||||
"@types/node": "16.x",
|
||||
"@types/node-fetch": "2.6.11",
|
||||
"@types/vscode": "1.74.0",
|
||||
"@typescript-eslint/eslint-plugin": "5.45.0",
|
||||
"@typescript-eslint/parser": "5.45.0",
|
||||
@ -108,5 +119,8 @@
|
||||
"nodemon": "3.1.0",
|
||||
"typescript": "4.9.3",
|
||||
"vsce": "2.15.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-fetch": "2.7.0"
|
||||
}
|
||||
}
|
||||
|
@ -11,22 +11,32 @@ export class RefLinkProvider implements vscode.DocumentLinkProvider {
|
||||
document: vscode.TextDocument,
|
||||
token: vscode.CancellationToken
|
||||
): Promise<vscode.DocumentLink[] | undefined> {
|
||||
const text = document.getText();
|
||||
const regexRef = /\s*(_ref|path):\s+(\S+)\n/g;
|
||||
let links: vscode.DocumentLink[] = [];
|
||||
let match;
|
||||
const activeAppRoot: vscode.Uri | undefined = this.context.workspaceState.get('activeAppRoot');
|
||||
if (!activeAppRoot) {
|
||||
return links;
|
||||
const activeAppRoot = this.context.workspaceState.get<string>('activeAppRoot');
|
||||
const activeAppRootUri = vscode.Uri.file(activeAppRoot || '');
|
||||
if (!activeAppRootUri.path) {
|
||||
console.error('Active App Root path is not defined or invalid.');
|
||||
return links; // Exit if no valid URI path
|
||||
}
|
||||
|
||||
const text = document.getText();
|
||||
let match;
|
||||
const regexRef = /[ -]*(_ref|path):\s+(\S+)\n/gm;
|
||||
while ((match = regexRef.exec(text)) !== null) {
|
||||
const filePath = match[2];
|
||||
const start = document.positionAt(match.index + match[0].indexOf(filePath));
|
||||
const end = start.translate(0, filePath.length);
|
||||
const range = new vscode.Range(start, end);
|
||||
|
||||
const uri = vscode.Uri.joinPath(activeAppRoot, filePath);
|
||||
links.push(new vscode.DocumentLink(range, uri));
|
||||
try {
|
||||
const uri = vscode.Uri.joinPath(activeAppRootUri, filePath);
|
||||
links.push(new vscode.DocumentLink(range, uri));
|
||||
} catch (err) {
|
||||
console.error(
|
||||
`failed to define file path uri: ${filePath} activeAppRoot: ${activeAppRoot}`,
|
||||
err
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return links;
|
||||
}
|
||||
|
@ -1,25 +1,26 @@
|
||||
import * as vscode from 'vscode';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
export default async function getLowdefyProjectRoots(
|
||||
context: vscode.ExtensionContext
|
||||
): Promise<void> {
|
||||
const files = await vscode.workspace.findFiles('**/lowdefy.{yaml,yml}');
|
||||
const config = vscode.workspace.getConfiguration('lowdefyDeTools');
|
||||
const port = config.get<number>('localServerPort') || 3000;
|
||||
const url = `http://localhost:${port}/api/dev-tools`;
|
||||
|
||||
if (files.length > 0) {
|
||||
// Remove the final 'lowdefy.yaml' segment from paths to get paths to app config directories
|
||||
const paths = files.map((uri) => {
|
||||
const pathSegments = uri.path.split('/');
|
||||
pathSegments.pop();
|
||||
return uri.with({ path: pathSegments.join('/') });
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
context.workspaceState.update('appRoots', paths),
|
||||
context.workspaceState.update('activeAppRoot', paths[0]),
|
||||
]);
|
||||
// setContext can be used to set context keys that can be read in when clauses
|
||||
// https://code.visualstudio.com/api/references/when-clause-contexts#add-a-custom-when-clause-context
|
||||
// vscode.commands.executeCommand('setContext', 'lowdefy.appRoots', paths);
|
||||
// vscode.commands.executeCommand('setContext', 'lowdefy.activeAppRoot', paths[0]);
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Lowdefy development server not running at ${url}, please start the development server or check the port in the extension settings.`
|
||||
);
|
||||
}
|
||||
const devServerContext = await response.json();
|
||||
|
||||
await Promise.all([
|
||||
context.workspaceState.update('activeAppRoot', devServerContext?.directories?.config),
|
||||
]);
|
||||
// setContext can be used to set context keys that can be read in when clauses
|
||||
// https://code.visualstudio.com/api/references/when-clause-contexts#add-a-custom-when-clause-context
|
||||
// vscode.commands.executeCommand('setContext', 'lowdefy.appRoots', paths);
|
||||
// vscode.commands.executeCommand('setContext', 'lowdefy.activeAppRoot', paths[0]);
|
||||
}
|
||||
|
28
pnpm-lock.yaml
generated
28
pnpm-lock.yaml
generated
@ -400,6 +400,10 @@ importers:
|
||||
version: 28.1.3
|
||||
|
||||
packages/ides/vscode:
|
||||
dependencies:
|
||||
node-fetch:
|
||||
specifier: 2.7.0
|
||||
version: 2.7.0
|
||||
devDependencies:
|
||||
'@types/glob':
|
||||
specifier: 8.0.0
|
||||
@ -413,6 +417,9 @@ importers:
|
||||
'@types/node':
|
||||
specifier: 16.x
|
||||
version: 16.18.96
|
||||
'@types/node-fetch':
|
||||
specifier: 2.6.11
|
||||
version: 2.6.11
|
||||
'@types/vscode':
|
||||
specifier: 1.74.0
|
||||
version: 1.74.0
|
||||
@ -5586,6 +5593,13 @@ packages:
|
||||
resolution: {integrity: sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==}
|
||||
dev: false
|
||||
|
||||
/@types/node-fetch@2.6.11:
|
||||
resolution: {integrity: sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==}
|
||||
dependencies:
|
||||
'@types/node': 16.18.96
|
||||
form-data: 4.0.0
|
||||
dev: true
|
||||
|
||||
/@types/node@12.20.55:
|
||||
resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==}
|
||||
dev: true
|
||||
@ -8917,7 +8931,7 @@ packages:
|
||||
extend: 3.0.2
|
||||
https-proxy-agent: 5.0.1
|
||||
is-stream: 2.0.1
|
||||
node-fetch: 2.6.7
|
||||
node-fetch: 2.7.0
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
- supports-color
|
||||
@ -11929,18 +11943,6 @@ packages:
|
||||
/node-addon-api@4.3.0:
|
||||
resolution: {integrity: sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==}
|
||||
|
||||
/node-fetch@2.6.7:
|
||||
resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==}
|
||||
engines: {node: 4.x || >=6.0.0}
|
||||
peerDependencies:
|
||||
encoding: ^0.1.0
|
||||
peerDependenciesMeta:
|
||||
encoding:
|
||||
optional: true
|
||||
dependencies:
|
||||
whatwg-url: 5.0.0
|
||||
dev: false
|
||||
|
||||
/node-fetch@2.7.0:
|
||||
resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==}
|
||||
engines: {node: 4.x || >=6.0.0}
|
||||
|
Loading…
x
Reference in New Issue
Block a user