Skip to content

Use document index to infer a name for a newly created client-side class or routine#1718

Open
isc-bsaviano wants to merge 1 commit intointersystems-community:masterfrom
isc-bsaviano:fix-1715
Open

Use document index to infer a name for a newly created client-side class or routine#1718
isc-bsaviano wants to merge 1 commit intointersystems-community:masterfrom
isc-bsaviano:fix-1715

Conversation

@isc-bsaviano
Copy link
Contributor

This PR fixes #1715 by implementing a new mechanism for inferring the name of a newly created client-side class or routine. The previous mechanism used the objectscript.export settings and was buggy, so I removed it. However, feedback from some users has indicated that this feature was really helpful. This is my attempt to bring it back in a more reliable way.

// Make sure the file extension is lowercased in the path before matching
const startOfDocName = (docUri.path.slice(0, -3) + docUri.path.slice(-3).toLowerCase()).lastIndexOf(
docNamePath
);
Copy link
Collaborator

@isc-klu isc-klu Feb 18, 2026

Choose a reason for hiding this comment

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

It looks like docNamePath and startOfDocName don’t depend on the outer loop (L457). Since their values stay the same for all i, recomputing them each time adds unnecessary work and makes the logic a bit harder to follow.

It might be clearer—and more efficient—to compute all of the “leading path segments that don’t contribute to the document name” once up front (and possibly cache that across inferDocName calls if it makes sense).

With that in place, the structure of the function could look something like:

export function inferDocName(uri: vscode.Uri): string | undefined {
  // check ext
  ...
  // compute "leadings"
  const leadings = new Set(index.uris.map(leading))
  // find the first leading
  for (const leading of leadings) {
    if uri.path.startsWith(leading) {
      return result = uri.path.slice(leading.length).replaceAll("/", ".") + fileExt;
    }
  }
}

function leading(docUri: vscode.URI): string {
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion KC!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New classes no longer getting class name based on path

2 participants

Comments