From f4841ba5332e274d4e0222cdccc26b32d99e616d Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:59:08 +0200 Subject: [PATCH] Refactor hoverService to use getNodeRange from nodeManager --- .../src/services/hoverService.ts | 6 +----- .../src/services/hover.ts | 6 +----- .../src/services/validation.ts | 12 +++--------- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/server/gx-workflow-ls-format2/src/services/hoverService.ts b/server/gx-workflow-ls-format2/src/services/hoverService.ts index f04cea7..ef0cfbc 100644 --- a/server/gx-workflow-ls-format2/src/services/hoverService.ts +++ b/server/gx-workflow-ls-format2/src/services/hoverService.ts @@ -33,11 +33,7 @@ export class GxFormat2HoverService { } } - const hoverRange = Range.create( - textDocument.positionAt(hoverRangeNode.offset), - textDocument.positionAt(hoverRangeNode.offset + hoverRangeNode.length) - ); - + const hoverRange = nodeManager.getNodeRange(hoverRangeNode); const location = nodeManager.getPathFromNode(hoverRangeNode); const schemaNode = this.schemaNodeResolver.resolveSchemaContext(location); const contents = this.getHoverMarkdownContentsForNode(schemaNode); diff --git a/server/packages/workflow-tests-language-service/src/services/hover.ts b/server/packages/workflow-tests-language-service/src/services/hover.ts index 9e9205a..6032d7f 100644 --- a/server/packages/workflow-tests-language-service/src/services/hover.ts +++ b/server/packages/workflow-tests-language-service/src/services/hover.ts @@ -47,11 +47,7 @@ export class WorkflowTestsHoverServiceImpl implements WorkflowTestsHoverService return Promise.resolve(null); } - const hoverRange = Range.create( - documentContext.textDocument.positionAt(hoverRangeNode.offset), - documentContext.textDocument.positionAt(hoverRangeNode.offset + hoverRangeNode.length) - ); - + const hoverRange = documentContext.nodeManager.getNodeRange(hoverRangeNode); if (this.parentPropertyMatchesKey(node, "job")) { const inputHover = await this.getHoverForWorkflowInput(documentContext, node, hoverRange); if (inputHover) { diff --git a/server/packages/workflow-tests-language-service/src/services/validation.ts b/server/packages/workflow-tests-language-service/src/services/validation.ts index d419836..2d1de15 100644 --- a/server/packages/workflow-tests-language-service/src/services/validation.ts +++ b/server/packages/workflow-tests-language-service/src/services/validation.ts @@ -1,4 +1,4 @@ -import { Diagnostic, DiagnosticSeverity, DocumentContext, Range } from "@gxwf/server-common/src/languageTypes"; +import { Diagnostic, DiagnosticSeverity, DocumentContext } from "@gxwf/server-common/src/languageTypes"; import { inject, injectable } from "inversify"; import { ResolvedSchema } from "../schema/jsonSchema"; import { WorkflowTestsSchemaProvider } from "../schema/provider"; @@ -37,16 +37,10 @@ export class WorkflowTestsValidationServiceImpl implements WorkflowTestsValidati const property = astRoot.type === "object" ? astRoot.properties[0] : undefined; if (property && property.keyNode.value === "$schema") { const node = property.valueNode || property; - const range = Range.create( - documentContext.textDocument.positionAt(node.offset), - documentContext.textDocument.positionAt(node.offset + node.length) - ); + const range = documentContext.nodeManager.getNodeRange(node); addProblem(Diagnostic.create(range, errorMessage, severity)); } else { - const range = Range.create( - documentContext.textDocument.positionAt(astRoot.offset), - documentContext.textDocument.positionAt(astRoot.offset + 1) - ); + const range = documentContext.nodeManager.getDefaultRange(); addProblem(Diagnostic.create(range, errorMessage, severity)); } }