MCPcopy Index your code
hub / github.com/anomalyco/opencode / open

Function open

packages/opencode/src/lsp/client.ts:554–621  ·  view source on GitHub ↗
(request: { path: string })

Source from the content-addressed store, hash-verified

552 },
553 notify: {
554 async open(request: { path: string }) {
555 request.path = Filesystem.normalizePath(
556 path.isAbsolute(request.path) ? request.path : path.resolve(input.directory, request.path),
557 )
558 const text = await Filesystem.readText(request.path)
559 const extension = path.extname(request.path)
560 const languageId = LANGUAGE_EXTENSIONS[extension] ?? "plaintext"
561
562 const document = files[request.path]
563 if (document !== undefined) {
564 // Do not wipe diagnostics on didChange. Some servers (e.g. clangd) only
565 // re-emit diagnostics when the content actually changes, so clearing
566 // here would lose errors for no-op touchFile calls. Let the server's
567 // next push/pull overwrite naturally.
568 await connection.sendNotification("workspace/didChangeWatchedFiles", {
569 changes: [
570 {
571 uri: pathToFileURL(request.path).href,
572 type: FILE_CHANGE_CHANGED,
573 },
574 ],
575 })
576
577 const next = document.version + 1
578 files[request.path] = { version: next, text }
579 await connection.sendNotification("textDocument/didChange", {
580 textDocument: {
581 uri: pathToFileURL(request.path).href,
582 version: next,
583 },
584 contentChanges:
585 syncKind === TEXT_DOCUMENT_SYNC_INCREMENTAL
586 ? [
587 {
588 range: {
589 start: { line: 0, character: 0 },
590 end: endPosition(document.text),
591 },
592 text,
593 },
594 ]
595 : [{ text }],
596 })
597 return next
598 }
599
600 await connection.sendNotification("workspace/didChangeWatchedFiles", {
601 changes: [
602 {
603 uri: pathToFileURL(request.path).href,
604 type: FILE_CHANGE_CREATED,
605 },
606 ],
607 })
608
609 pushDiagnostics.delete(request.path)
610 pullDiagnostics.delete(request.path)
611 await connection.sendNotification("textDocument/didOpen", {

Callers 7

readAttachmentFunction · 0.50
LanguagePickerFunction · 0.50
RoleDropdownFunction · 0.50
CollapsibleSectionFunction · 0.50
authorizeFunction · 0.50
authorizeFunction · 0.50
index.tsFile · 0.50

Calls 2

endPositionFunction · 0.85
deleteMethod · 0.45

Tested by

no test coverage detected