Skip to content

Commit 31e58bf

Browse files
committed
Tweak workspace watching rules
1 parent 4acad53 commit 31e58bf

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

internal/lsp/server.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/microsoft/typescript-go/internal/project"
2424
"github.com/microsoft/typescript-go/internal/project/ata"
2525
"github.com/microsoft/typescript-go/internal/project/logging"
26+
"github.com/microsoft/typescript-go/internal/tspath"
2627
"github.com/microsoft/typescript-go/internal/vfs"
2728
"golang.org/x/sync/errgroup"
2829
"golang.org/x/text/language"
@@ -639,9 +640,27 @@ func (s *Server) handleInitialized(ctx context.Context, params *lsproto.Initiali
639640
s.watchEnabled = true
640641
}
641642

643+
cwd := s.cwd
644+
if s.initializeParams.Capabilities != nil &&
645+
s.initializeParams.Capabilities.Workspace != nil &&
646+
s.initializeParams.Capabilities.Workspace.WorkspaceFolders != nil &&
647+
ptrIsTrue(s.initializeParams.Capabilities.Workspace.WorkspaceFolders) &&
648+
s.initializeParams.WorkspaceFolders != nil &&
649+
s.initializeParams.WorkspaceFolders.WorkspaceFolders != nil &&
650+
len(*s.initializeParams.WorkspaceFolders.WorkspaceFolders) == 1 {
651+
cwd = lsproto.DocumentUri((*s.initializeParams.WorkspaceFolders.WorkspaceFolders)[0].Uri).FileName()
652+
} else if s.initializeParams.RootUri.DocumentUri != nil {
653+
cwd = s.initializeParams.RootUri.DocumentUri.FileName()
654+
} else if s.initializeParams.RootPath != nil && s.initializeParams.RootPath.String != nil {
655+
cwd = *s.initializeParams.RootPath.String
656+
}
657+
if !tspath.PathIsAbsolute(cwd) {
658+
cwd = s.cwd
659+
}
660+
642661
s.session = project.NewSession(&project.SessionInit{
643662
Options: &project.SessionOptions{
644-
CurrentDirectory: s.cwd,
663+
CurrentDirectory: cwd,
645664
DefaultLibraryPath: s.defaultLibraryPath,
646665
TypingsLocation: s.typingsLocation,
647666
PositionEncoding: s.positionEncoding,

internal/project/configfileregistrybuilder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ func (c *configFileRegistryBuilder) updateRootFilesWatch(fileName string, entry
203203
globs = append(globs, fmt.Sprintf("%s/%s", tsconfigDir, recursiveFileGlobPattern))
204204
}
205205
for _, fileName := range entry.commandLine.ExtendedSourceFiles() {
206+
if includeWorkspace && tspath.ContainsPath(c.sessionOptions.CurrentDirectory, fileName, comparePathsOptions) {
207+
continue
208+
}
206209
globs = append(globs, fileName)
207210
}
208211
if len(externalFiles) > 0 {

internal/project/watch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func canWatchDirectoryOrFile(pathComponents []string) bool {
388388
return false
389389
}
390390
perceivedOsRootLength := perceivedOsRootLengthForWatching(pathComponents, length)
391-
return length > perceivedOsRootLength+1
391+
return length > perceivedOsRootLength
392392
}
393393

394394
func isDosStyleNextPart(part string) bool {

0 commit comments

Comments
 (0)