Skip to main content
Glama
nrwl

Nx MCP Server

Official
by nrwl
named-input-link.ts1.78 kB
import { findProperty, getLanguageModelCache, } from '@nx-console/language-server-utils'; import { readFileSync } from 'fs'; import { join } from 'path'; import { ASTNode, JSONDocument, Range, TextDocument, } from 'vscode-json-languageservice'; import { URI } from 'vscode-uri'; import { createRange } from './create-range'; import { readNxJson } from '@nx-console/shared-npm'; let versionNumber = 0; export async function namedInputLink( workingPath: string, node: ASTNode, ): Promise<string | undefined> { const nxJson = await readNxJson(workingPath); const namedInput = Object.keys(nxJson.namedInputs ?? {}).find( (input) => input === node.value, ); if (!namedInput) { return; } const nxJsonPath = join(workingPath, 'nx.json'); const nxJsonContent = readFileSync(join(workingPath, 'nx.json'), 'utf8'); const languageModelCache = getLanguageModelCache(); const { document, jsonAst } = languageModelCache.retrieve( TextDocument.create(nxJsonPath, 'json', versionNumber, nxJsonContent), false, ); languageModelCache.dispose(); versionNumber++; const range = findNamedInputRange(document, jsonAst, namedInput); if (!range) { return; } return URI.from({ scheme: 'file', path: nxJsonPath, fragment: `${range.start.line + 1}`, }).toString(); } function findNamedInputRange( document: TextDocument, jsonAst: JSONDocument, namedInput: string, ): Range | undefined { if (!jsonAst.root) { return; } const namedInputNode = findProperty(jsonAst.root, 'namedInputs'); if (!namedInputNode) { return; } const namedInputProperty = findProperty(namedInputNode, namedInput); if (!namedInputProperty) { return; } return createRange(document, namedInputProperty); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nrwl/nx-console'

If you have feedback or need assistance with the MCP directory API, please join our Discord server