Skip to content

Open startup file upon selection - #8

Merged
kzu merged 1 commit into
mainfrom
open-file
Nov 18, 2020
Merged

kzu merged 1 commit into
mainfrom
open-file

Conversation

@kzu

@kzu kzu commented Nov 18, 2020

Copy link
Copy Markdown
Member

SmallSharpAutoOpen

A new build task project allows us to open the startup file
after the build finishes (this proved to be the most reliable
way that didn't cause editor instabilities).

The behavior can be turned off by setting the MSBuild property
OpenStartupFile to false.

The logic seems convoluted, but it's really the only way. The
Roslyn stuff runs out of process from VS and therefore cannot
interact with it in any (normal) way. We take inspiration from
the xunit.vsix project (see https://github.com/kzu/xunit.vsix/blob/master/src/Xunit.Vsix/RunningObjects.cs)
to basically lookup via COM the running DTE for the active window
(since you have just changed the startup profile, this will almost
surely be the process we're interested in) and just run a DTE
File.Open command against it. This has the benefit of focusing
the tab if it's already opened but not focused, btw.

We keep the last opened file in a flag file too, so as not to
force open a file that you have explicitly closed after the
initial auto-open, to avoid being too annoying.

This flag file is not added to the FileWrites because we don't
want a rebuild to cause files to re-open unnecessarily.

A new build task project allows us to open the startup file
after the build finishes (this proved to be the most reliable
way that didn't cause editor instabilities).

The behavior can be turned off by setting the MSBuild property
`OpenStartupFile` to false.

The logic seems convoluted, but it's really the only way. The
Roslyn stuff runs out of process from VS and therefore cannot
interact with it in any (normal) way. We take inspiration from
the xunit.vsix project (see https://github.com/kzu/xunit.vsix/blob/master/src/Xunit.Vsix/RunningObjects.cs)
to basically lookup via COM the running DTE for the active window
(since you have just changed the startup profile, this will almost
surely be the process we're interested in) and just run a DTE
`File.Open` command against it. This has the benefit of focusing
the tab if it's already opened but not focused, btw.

We keep the last opened file in a flag file too, so as not to
force open a file that you have explicitly closed after the
initial auto-open, to avoid being too annoying.

This flag file is *not* added to the FileWrites because we don't
want a rebuild to cause files to re-open unnecessarily.
@kzu
kzu merged commit a253abd into main Nov 18, 2020
@kzu
kzu deleted the open-file branch November 18, 2020 22:00
@devlooped devlooped locked and limited conversation to collaborators Jan 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant