MCPcopy Index your code
hub / github.com/continuedev/continue / addEntireFileToContext

Function addEntireFileToContext

extensions/vscode/src/util/addCode.ts:108–149  ·  view source on GitHub ↗
(
  uri: vscode.Uri,
  webviewProtocol: VsCodeWebviewProtocol | undefined,
  ideUtils: VsCodeIdeUtils,
)

Source from the content-addressed store, hash-verified

106}
107
108export async function addEntireFileToContext(
109 uri: vscode.Uri,
110 webviewProtocol: VsCodeWebviewProtocol | undefined,
111 ideUtils: VsCodeIdeUtils,
112) {
113 // If a directory, add all files in the directory
114 const stat = await ideUtils.stat(uri);
115 if (stat?.type === vscode.FileType.Directory) {
116 const files = (await ideUtils.readDirectory(uri))!; //files can't be null if we reached this point
117 for (const [filename, type] of files) {
118 if (type === vscode.FileType.File) {
119 addEntireFileToContext(
120 vscode.Uri.joinPath(uri, filename),
121 webviewProtocol,
122 ideUtils,
123 );
124 }
125 }
126 return;
127 }
128
129 // Get the contents of the file
130 const contents = (await vscode.workspace.fs.readFile(uri)).toString();
131 const rangeInFileWithContents = {
132 filepath: uri.toString(),
133 contents: contents,
134 range: {
135 start: {
136 line: 0,
137 character: 0,
138 },
139 end: {
140 line: contents.split(os.EOL).length - 1,
141 character: 0,
142 },
143 },
144 };
145
146 webviewProtocol?.request("highlightedCode", {
147 rangeInFileWithContents,
148 });
149}
150
151export function isEmptyFile(document: vscode.TextDocument) {
152 return document.lineCount === 1 && document.lineAt(0).range.isEmpty;

Callers 1

getCommandsMapFunction · 0.90

Calls 4

statMethod · 0.80
readDirectoryMethod · 0.80
readFileMethod · 0.65
requestMethod · 0.65

Tested by

no test coverage detected