Skip to content

[Bug]: Peek/Go to Definition doesn't work when schema and table share the same name #21854

@aasimkhan30

Description

@aasimkhan30

Description

Peek Definition / Go to Definition can resolve the wrong object when a schema and a table have the same name.

For example, if a schema named Tasks contains a table also named Tasks (Tasks.Tasks), definition lookup should resolve the schema name and table name separately based on cursor position. Instead, the wrong object can be returned.

Related Azure Data Studio issue:
microsoft/azuredatastudio#2181

Steps to Reproduce

  1. Connect to a SQL Server database.
  2. Run the following setup script:
CREATE SCHEMA Tasks;
GO

CREATE TABLE Tasks.Tasks
(
    TaskId int NOT NULL PRIMARY KEY,
    TaskName nvarchar(100) NOT NULL,
    CreatedAt datetime2 NOT NULL DEFAULT sysdatetime()
);
GO

INSERT INTO Tasks.Tasks (TaskId, TaskName)
VALUES
    (1, N'alpha'),
    (2, N'beta'),
    (3, N'gamma');
GO
  1. In a fresh query editor, run or paste:
SELECT *
FROM Tasks.Tasks;
  1. Put the cursor on the first Tasks and invoke Peek Definition or Go to Definition.
  2. Put the cursor on the second Tasks and invoke Peek Definition or Go to Definition again.

Expected Behavior

Definition lookup should be context-aware:

  • the first Tasks should resolve to the schema definition
  • the second Tasks should resolve to the table definition

Actual Behavior

Definition lookup resolves the wrong object when schema and table names are identical. In the ADS report, both lookups could incorrectly resolve to the schema definition.

Affected Area

  • Query editor
  • Other (please describe below)

If you selected "Other", please describe the affected area

Language service / definition resolution

Environment Information

  • VS Code Version:
  • MSSQL Extension Version:
  • Operating System:
  • SQL Server target/version:

Confirmation

  • I have searched existing issues and couldn't find a match

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions