Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions server/src/languageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,20 @@ export interface FormattingOptions extends LSPFormattingOptions {
insertFinalNewline?: boolean;
}

export interface HoverContentContributor {
/**
* Gets the contents that will be contributed to a new section of the Hover message
* @param workflowDocument The workflow document
* @param position The hover position
*/
onHoverContent(workflowDocument: WorkflowDocument, position: Position): string;
}

export interface WorkflowLanguageService {
format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[];
parseWorkflowDocument(document: TextDocument): WorkflowDocument;
doValidation(workflowDocument: WorkflowDocument): Promise<Diagnostic[]>;
doHover(workflowDocument: WorkflowDocument, position: Position): Promise<Hover | null>;
}

export abstract class ServerContext {
Expand Down
47 changes: 47 additions & 0 deletions server/src/providers/hover/debugHoverContentContributor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ASTNode, PropertyASTNode, WorkflowDocument, Position, HoverContentContributor } from "../../languageTypes";
import { ArrayASTNode, BooleanASTNode, NullASTNode, NumberASTNode, StringASTNode } from "vscode-json-languageservice";

/**
* This is a debugging helper Hover Provider to see metadata about the JSON parsing.
*/
export class DebugHoverContentContributor implements HoverContentContributor {
public onHoverContent(workflowDocument: WorkflowDocument, position: Position): string {
const node = workflowDocument.getNodeAtPosition(position);
return node ? this.printNode(node) : "";
}

private printNode(node: ASTNode): string {
const contentLines = [`**${node.type}**`];
if (node.type === "object") {
for (const property of node.properties) {
contentLines.push(this.printNodeProperty(property));
}
} else if (node.type === "array") {
contentLines.push(this.printArrayNode(node));
} else if (node.type === "property") {
contentLines.push(this.printNodeProperty(node));
} else {
contentLines.push(this.printNodeValue(node));
}
return contentLines.join("\n\n");
}

private printNodeProperty(property: PropertyASTNode): string {
return `[${property.valueNode?.type}]\`${property.keyNode.value}\`: ${
property.valueNode?.value || "hover children for details"
}`;
}

private printArrayNode(node: ArrayASTNode): string {
const nodeStr = `${node.items.length} items (${node.offset}, ${node.offset + node.length})\n`;
const itemsStr: string[] = [];
node.items.forEach((item) => {
itemsStr.push(` - [${item.type}] (${item.offset}, ${item.offset + item.length})\n`);
});
return nodeStr.concat(...itemsStr);
}

private printNodeValue(node: StringASTNode | NumberASTNode | BooleanASTNode | NullASTNode): string {
return `\`${node.value}\`: (${node.offset}, ${node.offset + node.length})`;
}
}
52 changes: 52 additions & 0 deletions server/src/providers/hover/hoverProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Hover, HoverParams, MarkupKind, MarkupContent, HoverContentContributor } from "../../languageTypes";
import { GalaxyWorkflowLanguageServer } from "../../server";
import { Provider } from "../provider";

export class HoverProvider extends Provider {
private contributors: HoverContentContributor[];

public static register(
server: GalaxyWorkflowLanguageServer,
contributors?: HoverContentContributor[]
): HoverProvider {
return new HoverProvider(server, contributors);
}

constructor(server: GalaxyWorkflowLanguageServer, contributors?: HoverContentContributor[]) {
super(server);
this.contributors = contributors ?? [];
this.connection.onHover((params) => this.onHover(params));
}

private async onHover(params: HoverParams): Promise<Hover | null> {
const workflowDocument = this.workflowDocuments.get(params.textDocument.uri);
if (!workflowDocument) {
return null;
}
const hover = await this.languageService.doHover(workflowDocument, params.position);
if (!hover) {
return null;
}
const contentSections: string[] = [
this.hoverHasEmptyContent(hover) ? `No documentation available` : `${hover.contents}`,
];
this.contributors.forEach((contentContributor) => {
const contributedContent = contentContributor.onHoverContent(workflowDocument, params.position);
contentSections.push(contributedContent);
});
this.setHoverContentSections(hover, contentSections);
return hover;
}

private setHoverContentSections(hover: Hover, contentSections: string[]) {
const markdownContent: MarkupContent = {
kind: MarkupKind.Markdown,
value: contentSections.join("\n\n---\n\n"),
};
hover.contents = markdownContent;
}

private hoverHasEmptyContent(hover: Hover): boolean {
return hover.contents.toString() === "";
}
}
76 changes: 0 additions & 76 deletions server/src/providers/hoverProvider.ts

This file was deleted.

7 changes: 5 additions & 2 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { WorkflowLanguageService, TextDocument, WorkflowDocument } from "./langu
import { WorkflowDocuments } from "./models/workflowDocuments";
import { SymbolsProvider } from "./providers/symbolsProvider";
import { FormattingProvider } from "./providers/formattingProvider";
import { HoverProvider } from "./providers/hoverProvider";
import { HoverProvider } from "./providers/hover/hoverProvider";
import { DebugHoverContentContributor } from "./providers/hover/debugHoverContentContributor";

export class GalaxyWorkflowLanguageServer {
public readonly languageService: WorkflowLanguageService;
Expand Down Expand Up @@ -53,7 +54,9 @@ export class GalaxyWorkflowLanguageServer {

private registerProviders() {
FormattingProvider.register(this);
HoverProvider.register(this);
HoverProvider.register(this, [
// new DebugHoverContentContributor(), //TODO remove this contributor before release
]);
SymbolsProvider.register(this);
}

Expand Down
2 changes: 1 addition & 1 deletion workflow-languages/schemas/native.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"properties": {
"a_galaxy_workflow": {
"type": "string",
"title": "## Galaxy Workflow indicator",
"title": "Galaxy Workflow indicator",
"markdownDescription": "Indicates that this JSON document is a **Galaxy Workflow**",
"default": "true",
"enum": [
Expand Down