microsoft / microsoft/vscode-mssql
[Bug]: Project IntelliSense doesn't resolve cross-project database references (literal name or SqlCmdVariable)
- Dominant language
- TypeScript
- Stars
- 1.9k
- Forks
- 610
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 97
Description
### Description
In a multi-project SQL Database Projects workspace, when Project A references Project B via `ProjectReference` (with a `DatabaseSqlCmdVariable`), live IntelliSense (completions, hover, diagnostics) inside Project A fails to resolve objects in Project B, both when referenced by the database's literal name and when referenced via the `$(SqlCmdVariable)` syntax. The actual build (`dotnet build`) resolves these references correctly in both cases, so this appears specific to the live language service, not the compiler.
### Steps to Reproduce
Environment:
- Two SQL Database Projects, `ProjectA` and `ProjectB`, in the same workspace
- `ProjectA.sqlproj` has a `ProjectReference` to `ProjectB.sqlproj` with a `DatabaseSqlCmdVariable`:
```xml
ProjectB
{...}
True
False
ProjectB
```
```xml
ProjectB
$(SqlCmdVar__1)
```
- `ProjectB` has a table `dbo.SomeTable`
1. In a `ProjectA` `.sql` file, write a query against `ProjectA`'s own objects (works correctly):
```sql
SELECT * FROM [ProjectA].dbo.SomeLocalTable -- self-database, literal name: IntelliSense works
SELECT * FROM SomeLocalTable -- unqualified, self-project: IntelliSense works
```
2. In the same file, write a query against `ProjectB`'s object using the literal database name:
```sql
SELECT * FROM ProjectB.dbo.SomeTable
```
Result: no completions offered for `SomeTable`; no error shown either, it's simply not resolved.
3. In the same file, write the same query using the `$(SqlCmdVariable)` syntax that's the idiomatic way to express this in a SQL Database Project:
```sql
SELECT * FROM [$(ProjectB)].dbo.SomeTable
```
Result: no completions offered.
4. Run `dotnet build` on `ProjectA.sqlproj`, both forms above build successfully with 0 errors, confirming the references are valid and correctly resolvable; only the live editor experience is affected.
### Expected Behavior
Live IntelliSense (completions/hover/diagnostics) should resolve objects across a `ProjectReference` the same way the build does, both via the literal database name and via `$(SqlCmdVariable)` syntax.
### Affected Area
- [ ] Connection dialog (SQL Server | Azure browse/Fabric browse)
- [ ] Query editor
- [ ] Query results panel
- [ ] Object Explorer
- [ ] GitHub Copilot integration
- [ ] Preview/Edit data
- [ ] Table Designer
- [ ] Schema Designer
- [ ] Schema Compare
- [ ] Local SQL Server Container provisioning
- [ ] SQL database in Fabric provisioning
- [ ] DACPAC/BACPAC export/import
- [x] SQL Database projects
- [ ] Query Plan Visualizer
- [ ] Other (please describe below)
### If you selected "Other", please describe the affected area
_No response_
### Environment Information
- VS Code Version: 1.136.0
- SQL Database Projects extension: 1.7.0
- MSSQL extension: 1.45.1
- Operating System: Windows 11
### Confirmation
- [x] I have searched existing issues and couldn't find a match
- [x] I want to work on this issue
Contributor guide
No contributing guide indexed for this repository
Research direction
No implementation files or tests are named. Reproduce the two-project workspace with the ProjectReference and SqlCmdVariable, then compare live IntelliSense behavior with the successful dotnet build. Done means completions, hover, and diagnostics resolve ProjectB objects through both the literal database name and $(ProjectB) syntax.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql, typescript
- Domain
- databases, developer-experience
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100