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
- Connect to a SQL Server database.
- 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
- In a fresh query editor, run or paste:
SELECT *
FROM Tasks.Tasks;
- Put the cursor on the first
Tasks and invoke Peek Definition or Go to Definition.
- 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
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
Taskscontains a table also namedTasks(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
Tasksand invoke Peek Definition or Go to Definition.Tasksand invoke Peek Definition or Go to Definition again.Expected Behavior
Definition lookup should be context-aware:
Tasksshould resolve to the schema definitionTasksshould resolve to the table definitionActual 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
If you selected "Other", please describe the affected area
Language service / definition resolution
Environment Information
Confirmation