MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / getEffectiveRange

Method getEffectiveRange

src/integrations/editor/EditorUtils.ts:65–96  ·  view source on GitHub ↗

* Computes the effective range of text from the given document based on the user's selection. * If the selection is non-empty, returns that directly. * Otherwise, if the current line is non-empty, expands the range to include the adjacent lines. * * @param document - The text document to ext

(
		document: vscode.TextDocument,
		range: vscode.Range | vscode.Selection,
	)

Source from the content-addressed store, hash-verified

63 * @returns An EffectiveRange object containing the effective range and its text, or null if no valid text is found.
64 */
65 static getEffectiveRange(
66 document: vscode.TextDocument,
67 range: vscode.Range | vscode.Selection,
68 ): EffectiveRange | null {
69 try {
70 const selectedText = document.getText(range)
71 if (selectedText) {
72 return { range, text: selectedText }
73 }
74
75 const currentLine = document.lineAt(range.start.line)
76 if (!currentLine.text.trim()) {
77 return null
78 }
79
80 const startLineIndex = Math.max(0, currentLine.lineNumber - 1)
81 const endLineIndex = Math.min(document.lineCount - 1, currentLine.lineNumber + 1)
82
83 const effectiveRange = new vscode.Range(
84 new vscode.Position(startLineIndex, 0),
85 new vscode.Position(endLineIndex, document.lineAt(endLineIndex).text.length),
86 )
87
88 return {
89 range: effectiveRange,
90 text: document.getText(effectiveRange),
91 }
92 } catch (error) {
93 console.error("Error getting effective range:", error)
94 return null
95 }
96 }
97
98 /**
99 * Retrieves the file path of a given text document.

Callers 3

getEditorContextMethod · 0.95
provideCodeActionsMethod · 0.80

Calls 3

getTextMethod · 0.65
lineAtMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected