MCPcopy Create free account
hub / github.com/microsoft/typescript-go / warmAutoImportCache

Method warmAutoImportCache

internal/project/session.go:1761–1837  ·  view source on GitHub ↗
(ctx context.Context, change SnapshotChange, oldSnapshot, newSnapshot *Snapshot)

Source from the content-addressed store, hash-verified

1759}
1760
1761func (s *Session) warmAutoImportCache(ctx context.Context, change SnapshotChange, oldSnapshot, newSnapshot *Snapshot) {
1762 if change.fileChanges.Changed.Len() == 1 {
1763 var changedFile lsproto.DocumentUri
1764 for uri := range change.fileChanges.Changed.Keys() {
1765 changedFile = uri
1766 }
1767 if !newSnapshot.fs.isOpenFile(changedFile.FileName()) {
1768 return
1769 }
1770 prefs := newSnapshot.UserPreferences()
1771 if prefs.IncludeCompletionsForModuleExports.IsFalse() {
1772 return
1773 }
1774 project := newSnapshot.GetDefaultProject(changedFile)
1775 if project == nil {
1776 return
1777 }
1778 if newSnapshot.AutoImports.IsPreparedForImportingFile(
1779 changedFile.FileName(),
1780 project.configFilePath,
1781 prefs,
1782 ) {
1783 return
1784 }
1785
1786 // Cancel any previous auto-import warming and create a new cancellable context.
1787 // Only publish the new cancel func if the derived context is still active,
1788 // and make the stored cancel func a no-op once that warming task is done.
1789 s.warmAutoImportMu.Lock()
1790 if s.warmAutoImportCancel != nil {
1791 s.warmAutoImportCancel()
1792 }
1793 warmCtx, cancel := context.WithCancel(ctx)
1794 if warmCtx.Err() == nil {
1795 s.warmAutoImportCancel = func() {
1796 if warmCtx.Err() != nil {
1797 return
1798 }
1799 s.logger.Logf("Cancelling auto-import warming for file %s", changedFile.FileName())
1800 cancel()
1801 }
1802 }
1803 s.warmAutoImportMu.Unlock()
1804
1805 if warmCtx.Err() != nil {
1806 cancel()
1807 return
1808 }
1809 defer cancel()
1810
1811 // Clone the snapshot with auto-imports using warmCtx so the expensive
1812 // extraction work is cancelled if a file change arrives.
1813 if !newSnapshot.tryRef() {
1814 return
1815 }
1816 defer newSnapshot.Deref(s)
1817
1818 warmChange := SnapshotChange{

Callers 1

updateSnapshotMethod · 0.95

Calls 15

FileNameMethod · 0.95
adoptSnapshotChangeMethod · 0.95
IsFalseMethod · 0.80
tryRefMethod · 0.80
LenMethod · 0.65
GetDefaultProjectMethod · 0.65
LogfMethod · 0.65
CloneMethod · 0.65
KeysMethod · 0.45
isOpenFileMethod · 0.45
UserPreferencesMethod · 0.45

Tested by

no test coverage detected