Skip to content
Open
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
13 changes: 12 additions & 1 deletion spx-gui/src/components/editor/code-editor/lsp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../common'
import { XGoLanguageClient, type IConnection, ResponseError } from './spxls/client'
import type { Files as SpxlsFiles, RequestMessage, ResponseMessage, NotificationMessage } from './spxls'
import { xgoGetInputSlots, xgoRenameResources } from './spxls/commands'
import { xgoGetInputSlots, xgoGetProperties, xgoRenameResources } from './spxls/commands'
import {
type CompletionItem,
isDocumentLinkForResourceReference,
Expand Down Expand Up @@ -254,6 +254,17 @@ export class SpxLSPClient extends Disposable {
)
}

async workspaceExecuteCommandXGoGetProperties(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming Inconsistency: The method name workspaceExecuteCommandXGoGetProperty (singular) doesn't match the command namespace xgoGetProperties (plural) or the command string 'xgo.getProperties'.

This breaks the established pattern in the codebase:

  • xgoGetInputSlotsworkspaceExecuteCommandXGoGetInputSlots
  • xgoRenameResourcesworkspaceExecuteCommandXGoRenameResources
  • xgoGetPropertiesworkspaceExecuteCommandXGoGetProperty

Recommendation: Rename to workspaceExecuteCommandXGoGetProperties (plural) for consistency.

ctx: RequestContext,
...params: xgoGetProperties.Arguments
): Promise<xgoGetProperties.Result> {
return this.executeCommand<xgoGetProperties.Arguments, xgoGetProperties.Result>(
ctx,
xgoGetProperties.command,
...params
)
}

async textDocumentDocumentLink(
ctx: RequestContext,
params: lsp.DocumentLinkParams
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Convenience Method: Consider adding a higher-level getProperties wrapper method following the established pattern in this codebase.

Existing patterns:

  • getInputSlots (line 428) wraps workspaceExecuteCommandXGoGetInputSlots
  • getCompletionItems (line 421) wraps textDocumentCompletion
  • getResourceReferences (line 389) wraps textDocumentDocumentLink

Suggested implementation:

async getProperties(ctx: RequestContext, target: string): Promise<xgoGetProperties.XGoProperty[]> {
  const result = await this.workspaceExecuteCommandXGoGetProperties(ctx, { target })
  if (result == null) return []
  return result
}

This would provide a cleaner API and improve maintainability.

Expand Down
21 changes: 21 additions & 0 deletions spx-gui/src/components/editor/code-editor/lsp/spxls/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,24 @@ export namespace xgoGetInputSlots {
}
export type Result = XGoInputSlot[] | null
}

export namespace xgoGetProperties {
export const command = 'xgo.getProperties'
type XGoGetPropertiesParams = {
/** The target name, for example `Game` or a specific sprite name. */
target: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Input Validation: The target parameter lacks validation. Consider adding constraints to ensure it conforms to expected patterns (identifier rules or "Game" literal).

Security consideration: While the LSP runs in a sandboxed Web Worker, adding validation provides defense in depth if the WASM language server has vulnerabilities in string handling.

Recommendation:

  • Document the expected format and constraints explicitly
  • Consider runtime validation for identifiers
  • Add examples of valid vs invalid target values in the JSDoc

}
export type Arguments = [XGoGetPropertiesParams]
/** A property of a target type. */
export type XGoProperty = {
/** The property name. */
name: string
/** The property type as a string. */
type: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation Enhancement: Consider adding more detailed JSDoc for the type field:

  • What format does the type string use? (Go type syntax? Simplified names?)
  • Examples of common type values (e.g., "int", "string", "func()", etc.)

This would help developers understand what to expect from the API response.

/** The kind of property. */
kind: 'field' | 'method'
/** Optional documentation for the property. */
doc?: string
}
export type Result = XGoProperty[]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

For consistency with other commands like xgoGetInputSlots and to handle cases where the server might not find any properties or encounters an error, it's safer to allow null as a possible result. This prevents potential runtime errors if the server returns null and the client expects an array. Please also update the return type in SpxLSPClient.workspaceExecuteCommandXGoGetProperties accordingly.

Suggested change
export type Result = XGoProperty[]
export type Result = XGoProperty[] | null

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type Safety Issue: The Result type should include | null for consistency with other LSP commands.

Current: export type Result = XGoProperty[]
Compare with:

  • xgoGetInputSlots.Result = XGoInputSlot[] | null (line 31)
  • xgoRenameResources.Result = lsp.WorkspaceEdit | null (line 10)

Recommendation: Change to export type Result = XGoProperty[] | null to ensure proper type safety if the LSP server returns null.

}
Comment on lines +34 to +53
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xgoGetProperties.Result is non-nullable (XGoProperty[]), but other xgo.* executeCommand results in this module are modeled as nullable (e.g., xgoRenameResources.Result, xgoGetInputSlots.Result). Since LSP workspace/executeCommand can legitimately return null, consider making this XGoProperty[] | null (and handling null at call sites) to match the established pattern and avoid potential runtime null handling bugs.

Copilot uses AI. Check for mistakes.