Support for code completion and function tips

sponsored links

Support for code completion and function tips


From http://www.cppprog.com/2009/1111/176_4.html

VS code completion and function prompt function yes is worth commendable, they can greatly improve the programming Xiaoshuai we (the result that now write code O'clock often Zhi Ji Zhu first four letters, if the Duixiang behind Dianle without prompting after the decimal point will be agitated and confused to say -_-), although sometimes fail.

This function is used as IDE is indispensable D. Even if you only intend to be a editor that if this feature is also a bright spot ah ~ ~ (currently a lot of code editor said no this function).

Some tips on the function command to SCI_CALLTIP as prefix, we will use here only introduce a few commands (more commands see: http://scintilla.sourceforge.net/ScintillaDoc.html # CallTips )

  • SCI_CALLTIPSHOW (int posStart, const char * definition) display the prompt. posStart said display position, definition content is displayed
  • SCI_CALLTIPCANCEL cancel Tips
  • SCI_CALLTIPACTIVE If the current editor, has prompted information, returns 1, otherwise it returns 0
  • SCI_CALLTIPSETHLT (int highlightStart, int highlightEnd) set the prompt in the highlighted location, where we enter the function in VS when the function argument tips will highlight the current name of the input parameters.

In our program the best time to add tips is SCN_CHARADDED (see previous section) event. When the user enters the left parenthesis '(' time to obtain the function name in parentheses on the left, and then show the full definition of the function.

The following code implements two API CreateWindow function and MoveWindow Tips

  1. / / We have to highlight the two functions
  2. const size_t FUNCSIZE = 2;
  3. char * g_szFuncList [FUNCSIZE] = (/ / function name
  4. "CreateWindow (",
  5. "MoveWindow ("
  6. );
  7. char * g_szFuncDesc [FUNCSIZE] = (/ / Function Information
  8. "HWND CreateWindow ("
  9. "LPCTSTR lpClassName,"
  10. "LPCTSTR lpWindowName,"
  11. "DWORD dwStyle,"
  12. "Int x,"
  13. "Int y,"
  14. "Int nWidth,"
  15. "Int nHeight,"
  16. "HWND hWndParent,"
  17. "HMENU hMenu,"
  18. "HANDLE hInstance,"
  19. "PVOID lpParam"
  20. ")"
  21. "BOOL MoveWindow ("
  22. "HWND hWnd,"
  23. "Int X,"
  24. "Int Y,"
  25. "Int nWidth,"
  26. "Int nHeight,"
  27. "BOOL bRepaint"
  28. ")"
  29. );
  30. void __fastcall TForm1:: WndProc (Messages:: TMessage & Message)
  31. (
  32. TForm:: WndProc (Message);
  33. if (Message.Msg == WM_NOTIFY)
  34. (
  35. SCNotification * notify = (SCNotification *) Message.LParam;
  36. ...
  37. if (notify-> nmhdr.code == SCN_CHARADDED)
  38. (
  39. ...
  40. / / Function prompt function
  41. static const char * pCallTipNextWord = NULL; / / highlight the location of the next
  42. static const char * pCallTipCurDesc = NULL; / / current function information prompted
  43. if (notify-> ch == '(') / / If you enter a left parenthesis, indicating the function prompt
  44. (
  45. char word [1000]; / / save the current word under the cursor (function name)
  46. TextRange tr; / / command for SCI_GETTEXTRANGE
  47. int pos = SendEditor (SCI_GETCURRENTPOS); / / get the current position (the position in parentheses)
  48. int startpos = SendEditor (SCI_WORDSTARTPOSITION, pos-1); / / starting position of the current word
  49. int endpos = SendEditor (SCI_WORDENDPOSITION, pos-1); / / terminate the current position of the word
  50. tr.chrg.cpMin = startpos; / / set word interval, remove the word
  51. tr.chrg.cpMax = endpos;
  52. tr.lpstrText = word;
  53. SendEditor (SCI_GETTEXTRANGE, 0, sptr_t (& tr));
  54. for (size_t i = 0; i <FUNCSIZE; i + +) / / Zhao Zhao have not we realize the function?
  55. (
  56. if (memcmp (g_szFuncList [i], word, sizeof (g_szFuncList [i])) == 0)
  57. (/ / Find the friends, then it prompts
  58. pCallTipCurDesc = g_szFuncDesc [i]; / / current function information prompted
  59. SendEditor (SCI_CALLTIPSHOW, pos, sptr_t (pCallTipCurDesc ));// Show this tip
  60. const char * pStart = strchr (pCallTipCurDesc ,'(')+ 1; / / highlight the first parameter
  61. const char * pEnd = strchr (pStart ,',');// comma-separated list of parameters
  62. if (pEnd == NULL) pEnd = strchr (pStart ,')');// if the last parameter, followed by the right parenthesis
  63. SendEditor (SCI_CALLTIPSETHLT,
  64. pStart-pCallTipCurDesc, pEnd-pCallTipCurDesc);
  65. pCallTipNextWord = pEnd +1; / / point to next parameter position
  66. break;
  67. )
  68. )
  69. )
  70. else if (notify-> ch == ')') / / If you enter the right parentheses, prompts to close the function
  71. (
  72. SendEditor (SCI_CALLTIPCANCEL);
  73. pCallTipCurDesc = NULL;
  74. pCallTipNextWord = NULL;
  75. )
  76. else if (notify-> ch == ',' & & SendEditor (SCI_CALLTIPACTIVE) & & pCallTipCurDesc)
  77. (
  78. / / Input is a comma, highlight the next parameter
  79. const char * pStart = pCallTipNextWord;
  80. const char * pEnd = strchr (pStart ,',');
  81. if (pEnd == NULL) pEnd = strchr (pStart ,')');
  82. if (pEnd == NULL) / / no next argument the matter, close the prompt
  83. SendEditor (SCI_CALLTIPCANCEL);
  84. else
  85. (
  86. SendEditor (SCI_CALLTIPSETHLT, pStart-pCallTipCurDesc, pEnd-pCallTipCurDesc);
  87. pCallTipNextWord = pEnd +1;
  88. )
  89. )
  90. ) / / If (notify-> nmhdr.code == SCN_CHARADDED)
  91. ...
  92. ) / / If (Message.Msg == WM_NOTIFY)
  93. )


Of course, this prompts a considerable cottage friends. Such as the function name and a space between the parentheses is not prompted to come out, the function will prompt the last nested call a function parameter. If the improvements on, we fancy takes it.

In addition, there is a mention of foreign words, in actual use, the information that we can not function the same as here, death is written, but based on user input dynamically generated list of function names and information. This involves a C + + code to resolve the problem (okay, as long as the analytic function declaration on the line), to this point, cattle X, students can write their own parsing code; times cattle X, consider using WAVE, Spirit, Regex, etc. Library to help resolve; Xiang Niu Di students even Zhezhong Bu, consider using CTAGS Gongju generated in a background thread tag Wen Jian, Women from the tag file can be a li Qu (Dangran, Xiaoshuai Well ~ ~ can refer to the Han Shu C + + Builder Tips efficiency -_-)。

Code completion and function similar to the usage of tips, the prefix is SCI_AUTOC, specific command, see: http://scintilla.sourceforge.net/ScintillaDoc.html # Autocompletion

Directly on the code:


  1. void __fastcall TForm1:: WndProc (Messages:: TMessage & Message)
  2. (
  3. TForm:: WndProc (Message);
  4. if (Message.Msg == WM_NOTIFY)
  5. (
  6. ...
  7. if (notify-> nmhdr.code == SCN_CHARADDED)
  8. (
  9. ...
  10. if (notify-> ch == '.')
  11. (
  12. char word [1000]; / / save the current word under the cursor
  13. TextRange tr; / / command for SCI_GETTEXTRANGE
  14. int pos = SendEditor (SCI_GETCURRENTPOS); / / get the current position
  15. int startpos = SendEditor (SCI_WORDSTARTPOSITION, pos-1); / / starting position of the current word
  16. int endpos = SendEditor (SCI_WORDENDPOSITION, pos-1); / / terminate the current position of the word
  17. tr.chrg.cpMin = startpos; / / set word interval, remove the word
  18. tr.chrg.cpMax = endpos;
  19. tr.lpstrText = word;
  20. SendEditor (SCI_GETTEXTRANGE, 0, sptr_t (& tr));
  21. if (strcmp (word, "file.") == 0) / / input file. After the object file suggest several ways
  22. (
  23. SendEditor (SCI_AUTOCSHOW, 0,
  24. sptr_t (
  25. "Close"
  26. "Eof"
  27. "Good"
  28. "Open"
  29. "Rdbuf"
  30. "Size"
  31. ));
  32. )
  33. )
  34. ...


SCI_AUTOCSHOW first argument of command that have entered the number of characters. This is useful for code completion, such that we can use it to help the user to enter long strings of words, such as:

  1. if (strcmp (word, "Create") == 0)
  2. (
  3. SendEditor (SCI_AUTOCSHOW, 6, / / 6 characters have been entered
  4. sptr_t (
  5. "CreateBitmap"
  6. "CreateDC"
  7. "CreateHandle"
  8. "CreateWindow"
  9. "CreateWindowEx"
  10. ));
  11. )
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Support for code completion and function tips

  • extjs development environment set up and practice

    1, download and extract the extjs 2, download eclipse and Eclipse AJAX Toolkit Framework (ATF) I have been accustomed to using eclipse as a development environment, a variety of open-source plugin so that eclipse has all-around performance, operating effi

  • fck pages

    <% @ Page contentType = "text / html; charset = UTF-8"%> <% @ Include file = "/ commons / taglibs.jsp"%> <% @ Taglib uri = "/ FCKeditor" prefix = "FCK"%> <script language = "javascript

  • Depth understanding of the eval function in javascript

    http://wanyij.blog.51cto.com/46570/43794 In this paper, the discovery of an appropriate title is not so easy, huh, huh, so in this note under the first two purposes of this article: (1) introduction of the eval function in javascript usage (2) how to func

  • Hibernate query: HQL and Criteria

    HQL query methods generally used in more general way through the query query. Examples are as follows: The Criteria is a more than HQL query object-oriented approach: Created as follows: Criteria crit = session.createCriteria (Object.class); crit.add ...

  • Software development sunflower Baodian [reprint]

    Master the ability to reuse code very familiar with the new API's fast. This is because, he once used a lot of the API, have a lot of reusable code. He knows what is available and what is deficient. He has been using Qt, also used by gtk +, also used

  • Detailed JS regular expressions

    Opening, or have to talk about ^ and $ that they are separately used to match the beginning and end of the string, the following examples to illustrate separately "^ The": there must be at the beginning of "The" string; "of despai

  • JavaScript inheritance

    About JavaScript inherited a small example ... <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 / / EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" conte ...

  • JavaScript String Functions Guinness

    Own JS function 1.Asc (x), Chr (x): convert characters, character code 2. Filter: Search string array of a specific string Format: v = filter (x, s [, include [, compare]]) Examples: Dim x ()={" kjwang "," wangkj "," peter ")

  • EJB ant script to deploy template works

    <? xml version = "1.0" encoding = "UTF-8"?> <! - Name Project name basedir build.xml file directory -> <project name="HelloWorld" basedir="."> <! - Property variables -> <! - The sour ...

  • java read file

    java read documents in two ways: java.io and java.lang.ClassLoader When using the java.io, when java.lang.ClassLoader use it? (Note: If prior to read xml file java read file clearly aware of these two methods have been like! Can take much less to understa

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries