Skip to content

Is there a replacement for FileCodeModel and CodeElements? #308

Answered by LesterSmith
trihugger asked this question in Q&A
Discussion options

You must be logged in to vote

It appears that you can still get to the FileCodeModel from the DTE object like the following code, even in VS2022
var codeElts = dte.ActiveDocument.ProjectItem.FileCodeModel.CodeElements;

I am able to get the DTE object in VS2022 from the InitializeAsync method of a VSPackage without adding an Editor Adornment item (which causes unwanted effects if you are not trying to change the appearance of the editor). I created a VSIX project with a command and then added a Package. To get the DTE object, I added the following code to the InitializeAsync method of the Package.

        // switch to main thread to get the DTE object
        await this.JoinableTaskFactory.SwitchToMainThreadAsync();

 …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by trihugger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants