Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextDocument.Folders is always empty for additional files #65589

Closed
etvorun opened this issue Nov 23, 2022 · 6 comments · Fixed by #71061
Closed

TextDocument.Folders is always empty for additional files #65589

etvorun opened this issue Nov 23, 2022 · 6 comments · Fixed by #71061
Assignees
Labels
Milestone

Comments

@etvorun
Copy link
Contributor

etvorun commented Nov 23, 2022

Version Used: 4.300.22.22804

Steps to Reproduce:

  1. Unzip attached file.
  2. Open MauiApp4\MauiApp4.sln
  3. Use Solution Explorer to open (and debug Roslyn internals) MyControl.xaml, LinkedControl.xaml and dark.xaml from SharedMaui project.
    MauiRepro.zip

Expected Behavior: TextDocument.Folders contains folders matching folder structure in solution explorer

Actual Behavior: TextDocument.Folders always contains 0 items

Note: *.cs files have valid Folders for plain and linked items; empty for *.cs files from SharedMaui project.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 23, 2022
@etvorun
Copy link
Contributor Author

etvorun commented Nov 23, 2022

This is related to #44131. Most likely due to the fact that IWorkspaceProjectContext.AddAdditionalFile does not accept folders (unlike IWorkspaceProjectContext.AddSourceFile).

XAML intellisense needs to know project relative paths. For example, in order to display completion for <Button Background='...' it needs to walk merged resource dictionaries like <ResourceDictionary Source='views/resources/Styles.xaml'> or <ResourceDictionary Source='/MyLib;component/controls/colors.xaml'>. Thus we need to do two things:

  • [optional]: find Project for MyLib
  • find additional document based on project relative path \controls\colors.xaml. Actual document can be a linked file or come from shared project

@etvorun
Copy link
Contributor Author

etvorun commented Jan 17, 2023

@jasonmalinowski can you please take a look :)

@jasonmalinowski
Copy link
Member

I think this recently came up too in the replacement for IWorkspaceProjectContext that we were working on with @tmeschter -- we weren't doing link file support (or something equivalent) for additional files since we didn't really have any idea somebody would have a need for them.

That said, I'm still confused on the scenario here @etvorun -- the existing XAML compiler also consumes link directives to handle things like this at the MSBuild layer? Because Roslyn doesn't use these folders other than when doing a few refactorings and placing new files on disk. It's not something we use to impact our semantics at all.

@ryzngard ryzngard added Need More Info The issue needs more information to proceed. and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 18, 2023
@ryzngard ryzngard added this to the 17.6 milestone Jan 18, 2023
@ghost ghost closed this as completed Jan 28, 2023
@ghost
Copy link

ghost commented Jan 28, 2023

Closing this issue as we've seen no reply to the request for more information. If you are able to get the requested information, please add it to the issue and we will retriage it.

@dibarbet dibarbet removed the Need More Info The issue needs more information to proceed. label Mar 3, 2023
@etvorun
Copy link
Contributor Author

etvorun commented Mar 3, 2023

@jasonmalinowski
Example:
/Views/MyPage.xaml

<Page>
  <Page.Resources>
    <ResourceDictonary>
      <ResourceDictonary.MergedDictionaries>
        <ResourceDictonary Source='Styles.xaml'/> <!-- relative to document -->
        <ResourceDictonary Source='/Styles.xaml'>  <!-- relative to project root -->
        <ResourceDictonary Source='/Resources/Styles.xaml'>  <!-- relative to project root -->
        <ResourceDictonary Source='/MyLib;component/Resources/Styles.xaml'>  <!-- relative to referenced project which builds MyLib.dll -->
      </ResourceDictonary.MergedDictionaries>
    </ResourceDictonary>
  </Page.Resources>
  <Button Style='{StaticResource }'/>
<Page>

To show intellisense when editing {StaticResource } we need to examine content of *.xaml files listed in MergedDictionaries sections. That requires finding AdditionalDocument based on project relative path, i.e. it is a function of TextDocument.Folders + TextDocument.Name. If TextDocument.Folders are always empty then it would break XAML intellisense.

@dibarbet
Copy link
Member

@arkalyanms for scheduling - XAML needs this for their LSP implementation

@arunchndr arunchndr modified the milestones: 17.6, 17.9 P2 Oct 27, 2023
jasonmalinowski added a commit to jasonmalinowski/roslyn that referenced this issue Dec 2, 2023
Our workspace model always allowed this at the document level, we just
never had a request for it until recently for some XAML support. This
adds support for legacy project systems in VS and the base C# extension
project system. Changes will need to be made in other repos for the
CPS-based project systems to consume the APIs being added here.

Partially fixes dotnet#65589
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants