Jump to content



Photo

Mouse Hover --> Call Tips [update: 03/18/2013]

calltips scite lua intellisense

  • Please log in to reply
96 replies to this topic

#1 jaberwocky6669

jaberwocky6669

    Dull light.

  • Active Members
  • PipPipPipPipPipPip
  • 2,082 posts

Posted 25 May 2012 - 04:20 AM

Months later I finally realized that I did not include an explanation of just what this does. SciTE has a feature called CallTips and also known as Intellisense. This feature pops up a small window with more information about the function that you are wanting to use. This window contains information such as the parameters of the function, information about the return values, etc. This small lua utility allows for these calltip windows to popup when the user hovers the mouse over a function name.

Doesn't work with relative include paths. If you have any input I'd love to hear from you.

I have an account on Second Life where I enjoy my time trying to crank out code in the Linden Scripting Language. The SL code editor has only one good feature and that is call tips when you hover the mouse over a function or constant. So, I tried to reproduce the same behavior in SciTE.

To use this just place the following lua file in the "...\AutoIt3\SciTE\LUA" directory.

MouseHover --> Calltips.lua

After you have done that then open SciTE and click 'Options' --> 'Open Lua Startup Script' and paste this line after the other lines (may require administrative rights):

LoadLuaFile("CallTipsOnMouseHover.lua")


Oh, and one more thing. This is optional but needed if you want to adjust the mouse hover time. Click 'Options' --> 'Open User Options File' and paste this in there somewhere. Set it to whatever works for you. 650 does well.
mousehover.calltips.dwelltime=650


Also 'ext.lua.reset' needs to be set to zero or the lua variables will be reset to default thus rendering the script useless.
ext.lua.reset=0


Then reload SciTE and enjoy! =D

Updates and changes:
Spoiler

Edited by jaberwocky6669, 18 March 2013 - 07:38 PM.

  • Sunaj and D4RKON3 like this







#2 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 25 May 2012 - 06:39 AM

This does not belong in AutoItTools. This belongs in it's own class. AutoItTools is for simple one-shot tools.

#3 jaberwocky6669

jaberwocky6669

    Dull light.

  • Active Members
  • PipPipPipPipPipPip
  • 2,082 posts

Posted 25 May 2012 - 02:05 PM

Done.

Are calltips loaded into SciTE's memory so that I don't have to read the HDD everytime?

Edited by LaCastiglione, 25 May 2012 - 02:12 PM.


#4 trancexx

trancexx

    Hm, I really shouldn't.

  • Active Members
  • PipPipPipPipPipPip
  • 5,194 posts

Posted 25 May 2012 - 05:56 PM

Can you add a timer or something to make the tip go away after some time if mouse isn't over a function?

eMyvnE


#5 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 25 May 2012 - 07:32 PM

Can you add a timer or something to make the tip go away after some time if mouse isn't over a function?


I think that's what the OnDwellEnd function is for.

Another thing I thought of though, I think there's a way to use the lexer to tell what kind of word you are hovering. You should restrict the calltips to words the lexer identifies as functions so you don't get random calltips from comments or strings, etc.

#6 jaberwocky6669

jaberwocky6669

    Dull light.

  • Active Members
  • PipPipPipPipPipPip
  • 2,082 posts

Posted 25 May 2012 - 07:58 PM

That is what onDwellEnd is for but it's either messed up or I am using it wrong (most likely). I'll look into the timer as an alternative.

I looked into that lexer and I can't make heads or tails of it. I kinda have an idea of what's going on. You find out what kind of word you're at in the file (variable, function, comment, etc) and then you give that information to the styler along with a start position which takes over from there.

Edited by LaCastiglione, 25 May 2012 - 08:02 PM.


#7 MvGulik

MvGulik

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 2,795 posts

Posted 25 May 2012 - 10:22 PM

Here's where the strangeness comes in: you have to switch buffers before it will work on first load.

That's the opposite of the initial behavior. (working on a file/buffer after a file open, but not after switching buffers).
Maybe you need to use both OnOpen() and OnSwitchFile().
Don't Fall in Love With Ideas"If you fall in love with an idea, you won't see the merits of alternative approaches -- and will probably miss an opportunity or two. One of life's great pleasures is letting go of a previously cherished idea. Then you're free to look for new ones. What part of your idea are you in love with? What would happen if you kissed it goodbye?"

#8 jaberwocky6669

jaberwocky6669

    Dull light.

  • Active Members
  • PipPipPipPipPipPip
  • 2,082 posts

Posted 25 May 2012 - 10:33 PM

I tried this but nothing doing:
Plain Text         
MouseHoverCallTips = EventClass:new(Common) function MouseHoverCallTips:OnOpen(path)     MouseHoverCallTips:initialize_mouse_dwell()     return true end function MouseHoverCallTips:OnSwitchFile(path)     MouseHoverCallTips:initialize_mouse_dwell()     return true end function MouseHoverCallTips:initialize_mouse_dwell()     local mousehover_calltips_dwelltime = tonumber(props["mousehover.calltips.dwelltime"])     if (mousehover_calltips_dwelltime == nil) then         mousehover_calltips_dwelltime = 700 -- default     end     scite.SendEditor(SCI_SETMOUSEDWELLTIME, mousehover_calltips_dwelltime)     return true end function MouseHoverCallTips:OnDwellStart(position, word)     if (word == "") then         return nil     end     local directory = props["SciteDefaultHome"] .. "apiau3.api"     local file = io.open(directory, "r")     local parens_start     local parens_end     local char_start     local char_end     for line in file:lines() do         if (string.find(line, word)) then             -- filter out entries ending with ?4, ?3, ?2, & ?1             for var = 1, 4 do                 char_start, char_end = string.find(line, '?' .. var)                 if (char_start ~= nil) then                     file:close()                     return nil                 end             end             parens_start, parens_end = string.find(line, "%)")             if (parens_start ~= nil) then                 line = string.gsub(line, "%)", "%)n", 1)             end             file:close()             scite.SendEditor(SCI_CALLTIPSHOW, position, line)             return true         end     end     file:close()     return true end function MouseHoverCallTips:OnDwellEnd()     scite.SendEditor(SCI_CALLTIPCANCEL)     return true end

Edited by LaCastiglione, 25 May 2012 - 10:34 PM.


#9 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 25 May 2012 - 10:39 PM

I looked into that lexer and I can't make heads or tails of it. I kinda have an idea of what's going on. You find out what kind of word you're at in the file (variable, function, comment, etc) and then you give that information to the styler along with a start position which takes over from there.

You don't have to understand the lexer I think. Just read the style of the first character of your word with SCI_GETSTYLEAT
*GERMAN* Posted Image [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

#10 jaberwocky6669

jaberwocky6669

    Dull light.

  • Active Members
  • PipPipPipPipPipPip
  • 2,082 posts

Posted 26 May 2012 - 12:00 AM

Just read the style of the first character of your word with SCI_GETSTYLEAT

Doh! I understand now. I do that from lua. Excellent. Thank you!

Edit: Ok, I did it and it works great! OP updated.

Edited by LaCastiglione, 26 May 2012 - 12:32 AM.


#11 MvGulik

MvGulik

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 2,795 posts

Posted 26 May 2012 - 08:45 AM

I tried this but nothing doing: ...

It should. (CQ: working for me.)
- OnOpen(): run's on every file that's loaded while scite is starting. And on files that are user loaded after the scite startup.
But note that OnSwitchFile() is also run on the active file/buffer if its not the last loaded file at scite startup. (and not on user loaded files/buffers ... until you switch buffers of course.)

PS: is OnDwellEnd() active? ... or not yet, as its never executed.on this side.

---

(I'm not sure what behavior's are scite4autoit related or native scites related.)

Edited by MvGulik, 26 May 2012 - 08:54 AM.

Don't Fall in Love With Ideas"If you fall in love with an idea, you won't see the merits of alternative approaches -- and will probably miss an opportunity or two. One of life's great pleasures is letting go of a previously cherished idea. Then you're free to look for new ones. What part of your idea are you in love with? What would happen if you kissed it goodbye?"

#12 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 26 May 2012 - 09:06 AM

AFAIK there is no OnDwellEnd(). OnDwellStart() is called with an empty string to signify that event according to the old documentation I read. If there is an event in later SciTE then the Events class isn't invoking it on inherited classes unless Jos caught it and added it.

#13 jaberwocky6669

jaberwocky6669

    Dull light.

  • Active Members
  • PipPipPipPipPipPip
  • 2,082 posts

Posted 26 May 2012 - 05:39 PM

Heh. You know something. I'm looking at the documentation again. I have no idea where I got onDwellEnd. Maybe my brain wished for something like that and tried to make it so.

Doh.

"OnDwellStart will receive the position of the mouse and the word under the mouse as arguments and the word will be empty when the mouse starts moving." So I updated the lua in the op.

Edited by LaCastiglione, 26 May 2012 - 05:43 PM.


#14 MvGulik

MvGulik

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 2,795 posts

Posted 26 May 2012 - 08:13 PM

Optional code suggestion:
-- 'if MouseHoverCallTips:IsAu3File(path) then', or 'if self:IsAu3File(path) then'. -- Although I'm not sure if there is a significant/important differance between the two. (just to be clear) function MouseHoverCallTips:IsAu3File(path)     -- working, but I'm not sure if there is a better way.     -- note: string.sub(props["au3"]), -4) ... assuming extention is 3 characters. (alt: ditch leading '*' character.)     if (string.lower(string.sub(path, -4)) == string.lower(string.sub(props["au3"], -4))) then         return true     end     return false end

PS: Not sure if it matters. But just in case. There is no 'file:close()' after the "for line .." loop in OnDwellStart(). (for all I know the open file might be auto-closed on hitting EOF, or on exiting the function.)
Don't Fall in Love With Ideas"If you fall in love with an idea, you won't see the merits of alternative approaches -- and will probably miss an opportunity or two. One of life's great pleasures is letting go of a previously cherished idea. Then you're free to look for new ones. What part of your idea are you in love with? What would happen if you kissed it goodbye?"

#15 jaberwocky6669

jaberwocky6669

    Dull light.

  • Active Members
  • PipPipPipPipPipPip
  • 2,082 posts

Posted 26 May 2012 - 08:40 PM

I added your function. Thanks!

#16 MvGulik

MvGulik

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 2,795 posts

Posted 27 May 2012 - 12:38 PM

Roger ... Looks a little odd with those comments. ;)

Tried to see if there was a alternative way to get a hold of 'all' the API function definitions that are actively used by the current (local user) scite4autoit setup ... but no luck so far.

Anyone know if there is a other way than doing it the file:open way ?



Anyway ... extended the definition finder a bit to do it anyway. (added+changed functions only) (LC: use as you see fit.)
Spoiler

Don't Fall in Love With Ideas"If you fall in love with an idea, you won't see the merits of alternative approaches -- and will probably miss an opportunity or two. One of life's great pleasures is letting go of a previously cherished idea. Then you're free to look for new ones. What part of your idea are you in love with? What would happen if you kissed it goodbye?"

#17 jaberwocky6669

jaberwocky6669

    Dull light.

  • Active Members
  • PipPipPipPipPipPip
  • 2,082 posts

Posted 27 May 2012 - 04:13 PM

Updated Op with MvGulik's additions. Keep 'em comin'!

#18 jaberwocky6669

jaberwocky6669

    Dull light.

  • Active Members
  • PipPipPipPipPipPip
  • 2,082 posts

Posted 27 May 2012 - 04:21 PM

What's weird is that OnOpen is called when SciTE is opened and when I switch between buffers. So, I removed OnSwitchFile and restarted SciTE but calltips are still not displayed when I hover over a function even after switching buffers.

Edited by LaCastiglione, 27 May 2012 - 04:22 PM.


#19 jaberwocky6669

jaberwocky6669

    Dull light.

  • Active Members
  • PipPipPipPipPipPip
  • 2,082 posts

Posted 27 May 2012 - 07:46 PM

Updated. Now handles call tips for user defined functions and for com methods-- assuming that you have them defined.

#20 AdmiralAlkex

AdmiralAlkex

    I'm on a boat

  • MVPs
  • 4,490 posts

Posted 30 May 2012 - 12:02 PM

Interesting, but It doesn't seem like you are reading any of the udf's from au3.api

Edited by AdmiralAlkex, 30 May 2012 - 12:02 PM.






Also tagged with one or more of these keywords: calltips, scite, lua, intellisense

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users