MCPcopy Create free account
hub / github.com/docker/docker-language-server / tryReading

Method tryReading

internal/pkg/document/manager.go:123–148  ·  view source on GitHub ↗

Read returns the contents of the file for the given URI. If no file exists at the path or the URI is of an invalid type, an error is returned.

(ctx context.Context, u uri.URI, create bool)

Source from the content-addressed store, hash-verified

121// If no file exists at the path or the URI is of an invalid type, an error is
122// returned.
123func (m *Manager) tryReading(ctx context.Context, u uri.URI, create bool) (doc Document, err error) {
124 m.mu.Lock()
125 defer func() {
126 if err == nil {
127 // Always return a copy of the document
128 doc = doc.Copy()
129 }
130 m.mu.Unlock()
131 }()
132
133 // TODO(siegs): check staleness for files read from disk?
134 var found bool
135 if doc, found = m.docs[u]; !found {
136 _, err = m.readAndParse(ctx, u)
137 doc = m.docs[u]
138 if !create {
139 delete(m.docs, u)
140 }
141 }
142
143 if os.IsNotExist(err) {
144 err = os.ErrNotExist
145 }
146
147 return doc, err
148}
149
150// Queue enqueues the given function as something that should be run in
151// the near future. The URI will be used as a key so if another function

Callers 2

ReadMethod · 0.95
searchForIncludedFilesFunction · 0.80

Calls 2

readAndParseMethod · 0.95
CopyMethod · 0.65

Tested by

no test coverage detected