Skip to content

Commit b1bee94

Browse files
committed
chore: add support for projectFileName for documentHighlights
1 parent f354062 commit b1bee94

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/utils/server.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -865,17 +865,20 @@ function createTSServerInstance() {
865865
return sendCommand(command);
866866
}
867867

868+
868869
/**
869870
* Sends a 'documentHighlights' request to the TypeScript Server. This command is used to
870-
* obtain highlights of all occurrences of a symbol within a specified set of files. It is
871-
* particularly useful for identifying and navigating to instances of a variable, function name,
872-
* or other identifiers across multiple files.
871+
* obtain highlights of all occurrences of a symbol within a specified set of files, optionally
872+
* within the context of a specific project. It is useful for identifying and navigating to
873+
* instances of a variable, function name, or other identifiers across multiple files.
873874
*
874875
* @param {string} filePath - The path to the TypeScript file where the symbol occurs.
875876
* @param {number} line - The line number where the symbol is located.
876877
* @param {number} offset - The character offset (position) in the line where the symbol is located.
877878
* @param {string[]} filesToSearch - The list of file paths to search for document highlights.
878-
* The search for symbol occurrences is conducted within these files.
879+
* @param {string} [projectFileName] - Optional. The name of the project file (absolute pathname required)
880+
* that contains the TypeScript file. Providing this helps to
881+
* accurately resolve symbols in the context of the given project.
879882
*
880883
* @returns {Promise<Object[]>} A promise that resolves with an array of document highlight objects.
881884
* Each object represents a file with highlight instances and includes:
@@ -887,29 +890,28 @@ function createTSServerInstance() {
887890
*
888891
* Example usage:
889892
* ```
890-
* documentHighlights('path/to/file.ts', 10, 5, ['path/to/file1.ts', 'path/to/file2.ts'])
893+
* documentHighlights('path/to/file.ts', 10, 5, ['path/to/file1.ts', 'path/to/file2.ts'], 'path/to/project.tsconfig.json')
891894
* .then(highlights => {
892895
* console.log('Document highlights:', highlights);
893896
* });
894897
* ```
895898
* This function is essential for features like symbol search in development environments,
896899
* where highlighting symbol occurrences enhances code understanding and navigation.
897900
*/
898-
//TODO: fix this for js use case
899-
function documentHighlights(filePath, line, offset, filesToSearch) {
901+
function documentHighlights(filePath, line, offset, filesToSearch, projectFileName = "") {
900902
const command = {
901903
command: "documentHighlights",
902904
arguments: {
903905
file: filePath,
904906
line: line,
905907
offset: offset,
906-
filesToSearch: filesToSearch
908+
filesToSearch: filesToSearch,
909+
projectFileName: projectFileName
907910
}
908911
};
909912
return sendCommand(command);
910913
}
911914

912-
913915
/**
914916
* Terminates the TypeScript Server process.
915917
* Warning: Use this function with caution. Prefer using the exitServer function for a graceful shutdown.

0 commit comments

Comments
 (0)