-
Notifications
You must be signed in to change notification settings - Fork 656
Concurrent LSP with cancelation #869
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
af44b26
Asyncify
andrewbranch 5ed46bf
Shut down correctly
andrewbranch 43ac686
Parallelize requests and give each access to its own checker via pool
andrewbranch 3ef2f90
Remove canceled checkers from the pool
andrewbranch afc5138
Thread context through everything correctly
andrewbranch 92f3ea2
Use checkerPool.Files
andrewbranch 6492843
More threading context, fixing bugs
andrewbranch 71d03be
Add context.TODO with comment in sketchy place
andrewbranch 450ad86
Format
andrewbranch e89cecd
Lint
andrewbranch 42c4fa4
go mod tidy
andrewbranch 48898b0
Log checker stats, fix double program update
andrewbranch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package compiler | ||
|
||
import ( | ||
"context" | ||
"iter" | ||
"slices" | ||
"sync" | ||
|
||
"github.com/microsoft/typescript-go/internal/ast" | ||
"github.com/microsoft/typescript-go/internal/checker" | ||
"github.com/microsoft/typescript-go/internal/core" | ||
) | ||
|
||
type CheckerPool interface { | ||
GetChecker(ctx context.Context) (*checker.Checker, func()) | ||
GetCheckerForFile(ctx context.Context, file *ast.SourceFile) (*checker.Checker, func()) | ||
GetAllCheckers(ctx context.Context) ([]*checker.Checker, func()) | ||
Files(checker *checker.Checker) iter.Seq[*ast.SourceFile] | ||
} | ||
|
||
type checkerPool struct { | ||
checkerCount int | ||
program *Program | ||
|
||
createCheckersOnce sync.Once | ||
checkers []*checker.Checker | ||
fileAssociations map[*ast.SourceFile]*checker.Checker | ||
} | ||
|
||
var _ CheckerPool = (*checkerPool)(nil) | ||
|
||
func newCheckerPool(checkerCount int, program *Program) *checkerPool { | ||
pool := &checkerPool{ | ||
program: program, | ||
checkerCount: checkerCount, | ||
checkers: make([]*checker.Checker, checkerCount), | ||
} | ||
|
||
return pool | ||
} | ||
|
||
func (p *checkerPool) GetCheckerForFile(ctx context.Context, file *ast.SourceFile) (*checker.Checker, func()) { | ||
p.createCheckers() | ||
checker := p.fileAssociations[file] | ||
return checker, noop | ||
} | ||
|
||
func (p *checkerPool) GetChecker(ctx context.Context) (*checker.Checker, func()) { | ||
p.createCheckers() | ||
checker := p.checkers[0] | ||
return checker, noop | ||
} | ||
|
||
func (p *checkerPool) createCheckers() { | ||
p.createCheckersOnce.Do(func() { | ||
wg := core.NewWorkGroup(p.program.singleThreaded()) | ||
for i := range p.checkerCount { | ||
wg.Queue(func() { | ||
p.checkers[i] = checker.NewChecker(p.program) | ||
}) | ||
} | ||
|
||
wg.RunAndWait() | ||
|
||
p.fileAssociations = make(map[*ast.SourceFile]*checker.Checker, len(p.program.files)) | ||
for i, file := range p.program.files { | ||
p.fileAssociations[file] = p.checkers[i%p.checkerCount] | ||
} | ||
}) | ||
} | ||
|
||
func (p *checkerPool) GetAllCheckers(ctx context.Context) ([]*checker.Checker, func()) { | ||
p.createCheckers() | ||
return p.checkers, noop | ||
} | ||
|
||
func (p *checkerPool) Files(checker *checker.Checker) iter.Seq[*ast.SourceFile] { | ||
checkerIndex := slices.Index(p.checkers, checker) | ||
return func(yield func(*ast.SourceFile) bool) { | ||
for i, file := range p.program.files { | ||
if i%p.checkerCount == checkerIndex { | ||
if !yield(file) { | ||
return | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
func noop() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is good for now but in theory the questions are asked only on open files so assign only for those ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant in editor scenario not cli
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation is only used in the CLI. In the editor this map is created with no capacity hint.