11import type tslib from 'typescript/lib/tsserverlibrary'
22import postfixesAtPosition from '../completions/postfixesAtPosition'
3- import { TriggerCharacterCommand , triggerCharacterCommands } from '../ipcTypes'
3+ import { NodeAtPositionResponse , TriggerCharacterCommand , triggerCharacterCommands } from '../ipcTypes'
4+ import { findChildContainingPosition } from '../utils'
45
5- export default ( info : tslib . server . PluginCreateInfo , fileName : string , position : number , specialCommand : TriggerCharacterCommand , configuration : any ) => {
6+ export default (
7+ info : tslib . server . PluginCreateInfo ,
8+ fileName : string ,
9+ position : number ,
10+ specialCommand : TriggerCharacterCommand ,
11+ configuration : any ,
12+ ) : void | {
13+ entries : [ ]
14+ typescriptEssentialsResponse : any
15+ } => {
616 if ( specialCommand === 'check-configuration' ) {
717 return {
818 entries : [ ] ,
@@ -12,6 +22,19 @@ export default (info: tslib.server.PluginCreateInfo, fileName: string, position:
1222 if ( triggerCharacterCommands . includes ( specialCommand ) && ! configuration ) {
1323 throw new Error ( 'no-ts-essential-plugin-configuration' )
1424 }
25+ if ( specialCommand === 'nodeAtPosition' ) {
26+ const node = findChildContainingPosition ( ts , info . languageService . getProgram ( ) ! . getSourceFile ( fileName ) ! , position )
27+ return {
28+ entries : [ ] ,
29+ typescriptEssentialsResponse : ! node
30+ ? undefined
31+ : ( {
32+ kindName : ts . SyntaxKind [ node . kind ] ,
33+ start : node . getStart ( ) ,
34+ end : node . getEnd ( ) ,
35+ } as NodeAtPositionResponse ) ,
36+ }
37+ }
1538 if ( specialCommand === 'getPostfixes' ) {
1639 const scriptSnapshot = info . project . getScriptSnapshot ( fileName )
1740 if ( ! scriptSnapshot ) return
0 commit comments