@@ -14,7 +14,11 @@ import {
1414} from 'vscode-languageserver/node'
1515import { TextDocument } from 'vscode-languageserver-textdocument'
1616import { URI } from 'vscode-uri'
17- import { TextDocumentWrapper } from './TextDocumentWrapper'
17+ import {
18+ getTextDocumentLocation ,
19+ getUriLocation ,
20+ symbolAt
21+ } from './textDocument'
1822
1923export class LanguageServer {
2024 private documentsKnownToEditor ! : TextDocuments < TextDocument >
@@ -37,25 +41,9 @@ export class LanguageServer {
3741 connection . listen ( )
3842 }
3943
40- private getAllDocuments ( ) {
41- const openDocuments = this . documentsKnownToEditor . all ( )
42- return openDocuments . map ( doc => this . wrap ( doc ) )
43- }
44-
4544 private getDocument ( params : TextDocumentPositionParams | CodeActionParams ) {
4645 const uri = params . textDocument . uri
47-
48- const doc = this . documentsKnownToEditor . get ( uri )
49-
50- if ( ! doc ) {
51- return null
52- }
53-
54- return this . wrap ( doc )
55- }
56-
57- private wrap ( doc : TextDocument ) {
58- return new TextDocumentWrapper ( doc )
46+ return this . documentsKnownToEditor . get ( uri )
5947 }
6048
6149 private getKnownDocumentLocations ( symbolUnderCursor : DocumentSymbol ) {
@@ -65,17 +53,17 @@ export class LanguageServer {
6553
6654 const filePath = symbolUnderCursor . name
6755
68- const matchingFiles = this . getAllDocuments ( ) . filter ( doc =>
69- URI . parse ( doc . uri ) . fsPath . endsWith ( filePath )
70- )
56+ const matchingFiles = this . documentsKnownToEditor
57+ . all ( )
58+ . filter ( doc => URI . parse ( doc . uri ) . fsPath . endsWith ( filePath ) )
7159
72- return matchingFiles . map ( doc => doc . getLocation ( ) )
60+ return matchingFiles . map ( doc => getTextDocumentLocation ( doc ) )
7361 }
7462
7563 private async onDefinition ( params : DefinitionParams , connection : Connection ) {
7664 const document = this . getDocument ( params )
7765
78- const symbolUnderCursor = document ?. symbolAt ( params . position )
66+ const symbolUnderCursor = symbolAt ( document , params . position )
7967
8068 if ( ! ( document && symbolUnderCursor ) ) {
8169 return null
@@ -101,7 +89,7 @@ export class LanguageServer {
10189
10290 private async checkIfSymbolsAreFiles (
10391 connection : _Connection ,
104- document : TextDocumentWrapper ,
92+ document : TextDocument ,
10593 symbolUnderCursor : DocumentSymbol ,
10694 fileLocations : Location [ ]
10795 ) {
@@ -113,17 +101,12 @@ export class LanguageServer {
113101 contents : string
114102 } | null > ( 'readFileContents' , possiblePath )
115103 if ( file ) {
116- const location = this . getLocation ( possiblePath , file . contents )
104+ const location = getUriLocation ( possiblePath , file . contents )
117105 fileLocations . push ( location )
118106 }
119107 }
120108 }
121109
122- private getLocation ( path : string , contents : string ) {
123- const doc = this . wrap ( TextDocument . create ( path , 'plain/text' , 0 , contents ) )
124- return doc . getLocation ( )
125- }
126-
127110 private arrayOrSingleResponse < T > ( elements : T [ ] ) {
128111 if ( elements . length === 1 ) {
129112 return elements [ 0 ]
0 commit comments