@@ -865,17 +865,20 @@ function createTSServerInstance() {
865
865
return sendCommand ( command ) ;
866
866
}
867
867
868
+
868
869
/**
869
870
* 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.
873
874
*
874
875
* @param {string } filePath - The path to the TypeScript file where the symbol occurs.
875
876
* @param {number } line - The line number where the symbol is located.
876
877
* @param {number } offset - The character offset (position) in the line where the symbol is located.
877
878
* @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.
879
882
*
880
883
* @returns {Promise<Object[]> } A promise that resolves with an array of document highlight objects.
881
884
* Each object represents a file with highlight instances and includes:
@@ -887,29 +890,28 @@ function createTSServerInstance() {
887
890
*
888
891
* Example usage:
889
892
* ```
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' )
891
894
* .then(highlights => {
892
895
* console.log('Document highlights:', highlights);
893
896
* });
894
897
* ```
895
898
* This function is essential for features like symbol search in development environments,
896
899
* where highlighting symbol occurrences enhances code understanding and navigation.
897
900
*/
898
- //TODO: fix this for js use case
899
- function documentHighlights ( filePath , line , offset , filesToSearch ) {
901
+ function documentHighlights ( filePath , line , offset , filesToSearch , projectFileName = "" ) {
900
902
const command = {
901
903
command : "documentHighlights" ,
902
904
arguments : {
903
905
file : filePath ,
904
906
line : line ,
905
907
offset : offset ,
906
- filesToSearch : filesToSearch
908
+ filesToSearch : filesToSearch ,
909
+ projectFileName : projectFileName
907
910
}
908
911
} ;
909
912
return sendCommand ( command ) ;
910
913
}
911
914
912
-
913
915
/**
914
916
* Terminates the TypeScript Server process.
915
917
* Warning: Use this function with caution. Prefer using the exitServer function for a graceful shutdown.
0 commit comments