11import * as vscode from "vscode" ;
22import * as nls from 'vscode-nls' ;
3- import { AutoLispExt } from './extension' ;
4- import { openWebHelp } from './help/openWebHelp' ;
3+ import { AutoLispExt } from './context' ;
54import { generateDocumentationSnippet , getDefunArguments , getDefunAtPosition } from './help/userDocumentation' ;
65import { showErrorMessage } from './project/projectCommands' ;
76import { AutoLispExtProvideDefinition } from './providers/gotoProvider' ;
87import { AutoLispExtProvideReferences } from './providers/referenceProvider' ;
98import { AutoLispExtPrepareRename , AutoLispExtProvideRenameEdits } from './providers/renameProvider' ;
109import { SymbolManager } from './symbols' ;
10+ import { AutoLispExtProvideHover } from "./providers/hoverProvider" ;
11+ import { DocumentServices } from './services/documentServices' ;
1112
1213const localize = nls . loadMessageBundle ( ) ;
1314
1415export function registerCommands ( context : vscode . ExtensionContext ) {
1516
16- // Associated with the right click "Open Online Help" menu item
1717 context . subscriptions . push ( vscode . commands . registerCommand ( 'autolisp.openWebHelp' , async ( ) => {
18+ // Note: this function is directly referenced by the package.json contributes (commands & menus) section.
19+ // Associated with the right click "Open Online Help" menu item.
1820 try {
19- await openWebHelp ( ) ;
21+ const editor : vscode . TextEditor = vscode . window . activeTextEditor ;
22+ let selected : string = editor . document . getText ( editor . selection ) ;
23+ if ( selected === "" ) {
24+ await vscode . commands . executeCommand ( 'editor.action.addSelectionToNextFindMatch' ) ;
25+ selected = editor . document . getText ( editor . selection ) ;
26+ }
27+ let urlPath : string = AutoLispExt . WebHelpLibrary . getWebHelpUrlBySymbolName ( selected , editor . document . fileName ) ;
28+ if ( urlPath . trim ( ) !== "" ) {
29+ vscode . env . openExternal ( vscode . Uri . parse ( urlPath ) ) ;
30+ }
2031 }
2132 catch ( err ) {
2233 if ( err ) {
@@ -50,9 +61,12 @@ export function registerCommands(context: vscode.ExtensionContext){
5061 const vsDoc = vscode . window . activeTextEditor . document ;
5162 const lf = vsDoc . eol === vscode . EndOfLine . LF ? '\n' : '\r\n' ;
5263 const doc = AutoLispExt . Documents . getDocument ( vsDoc ) ;
64+ if ( ! doc . isLSP ) {
65+ return ;
66+ }
5367
5468 // find the root LispContainer of the current cursor position
55- const exp = doc . atomsForest . find ( p => p . contains ( pos ) ) ;
69+ const exp = doc . documentContainer . atoms . find ( p => p . contains ( pos ) ) ;
5670
5771 // Locate the Defun to decorate
5872 const def = await getDefunAtPosition ( exp , pos ) ;
@@ -73,7 +87,7 @@ export function registerCommands(context: vscode.ExtensionContext){
7387 }
7488 } ) ) ;
7589
76- AutoLispExt . Subscriptions . push ( vscode . languages . registerDefinitionProvider ( [ 'autolisp' , 'lisp' ] , {
90+ AutoLispExt . Subscriptions . push ( vscode . languages . registerDefinitionProvider ( [ DocumentServices . Selectors . LSP , 'lisp' ] , {
7791 provideDefinition : function ( document : vscode . TextDocument , position : vscode . Position , token : vscode . CancellationToken )
7892 : vscode . ProviderResult < vscode . Definition | vscode . LocationLink [ ] > {
7993 // Purpose: locate potential source definitions of the underlying symbol
@@ -91,7 +105,7 @@ export function registerCommands(context: vscode.ExtensionContext){
91105 } ) ) ;
92106
93107 const msgRenameFail = localize ( "autolispext.providers.rename.failed" , "The symbol was invalid for renaming operations" ) ;
94- AutoLispExt . Subscriptions . push ( vscode . languages . registerRenameProvider ( [ 'autolisp' , 'lisp' ] , {
108+ AutoLispExt . Subscriptions . push ( vscode . languages . registerRenameProvider ( [ DocumentServices . Selectors . LSP , 'lisp' ] , {
95109 prepareRename : function ( document : vscode . TextDocument , position : vscode . Position , token : vscode . CancellationToken )
96110 : vscode . ProviderResult < vscode . Range | { range : vscode . Range ; placeholder : string ; } >
97111 {
@@ -133,7 +147,7 @@ export function registerCommands(context: vscode.ExtensionContext){
133147 } ) ) ;
134148
135149
136- AutoLispExt . Subscriptions . push ( vscode . languages . registerReferenceProvider ( [ 'autolisp' , 'lisp' ] , {
150+ AutoLispExt . Subscriptions . push ( vscode . languages . registerReferenceProvider ( [ DocumentServices . Selectors . LSP , 'lisp' ] , {
137151 provideReferences : function ( document : vscode . TextDocument , position : vscode . Position , context : vscode . ReferenceContext , token : vscode . CancellationToken )
138152 : vscode . ProviderResult < vscode . Location [ ] >
139153 {
@@ -152,4 +166,16 @@ export function registerCommands(context: vscode.ExtensionContext){
152166 }
153167 } ) ) ;
154168
169+ AutoLispExt . Subscriptions . push ( vscode . languages . registerHoverProvider ( [ DocumentServices . Selectors . LSP , DocumentServices . Selectors . DCL ] , {
170+ provideHover ( document : vscode . TextDocument , position : vscode . Position , token : vscode . CancellationToken ) : vscode . ProviderResult < vscode . Hover > {
171+ try {
172+ // offload all meaningful work to something that can be tested.
173+ const roDoc = AutoLispExt . Documents . getDocument ( document ) ;
174+ return AutoLispExtProvideHover ( roDoc , position ) ;
175+ } catch ( err ) {
176+ return ; // No localized error since VSCode has a default "no results" response
177+ }
178+ }
179+ } ) ) ;
180+
155181}
0 commit comments