Support for code completion and function tips

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. )
分类:Tech 时间:2010-03-28 人气:276
分享到:
blog comments powered by Disqus

相关文章

  • iBATIS to map the input parameters on sql 2010-04-26

    First, the mapping of input parameters: 1, parameterClass use 2, parameterMap use 3, How to Map the incoming parameter of type object as a parameterClass <insert parameterClass="User"> insert into t_user values ( null,#username#,#password#

  • vim automatic code completion method 2011-06-08

    1. _vimrc Configuration file found, anywhere in the file add the following setting items autocmd FileType python set omnifunc = pythoncomplete # Complete autocmd FileType javascrīpt set omnifunc = javascrīptcomplete # CompleteJS autocmd FileType html

  • Eclipse code completion 2010-05-06

    Windows-> Preferences-> General-> Keys Content Assist the default settings, Ctrl + Space But our Ctrl + Space is the switch input Here we put that shortcut Remove Binding, then the Binding in the keyboard's Alt + / But Alt + / is Word Completion

  • The concept of knowledge complement the original code completion 2011-09-10

    Value because the computer that is used in complement, rather than the original code, so you have this question. Here I briefly explain you will understand. Original code is this number itself is a binary form. For example 8-bit binary 0000001 is +1

  • JavaScript Eclipse plug-ins to increase _ _ highlighting code completion 2010-05-21

    1. Open Eclipse 2. Using Update Manager to install JSEclipse, in the main directory to find: Help> Software Updates -> Find and Install 3. In the pop-up interface in the first select Search for new features to install 4. Click New remote Site button

  • Eclipse JavaScript Plugin increase _ _ highlighted code completion 2010-05-21

    1. Open Eclipse 2. Using Update Manager to install JSEclipse, in the main directory to find: Help> Software Updates -> Find and Install 3. In the pop-up interface in the first select Search for new features to install 4. Click New remote Site button

  • JAVA Oracle stored procedures input parameters in the LIST 2010-11-28

    Today we wanted to try to do nothing weekend JAVA and ORACLE degree of integration, the results reflect the combination of these two really powerful weapon, unprecedented, or since. Hey ~ ~ Because last weekend to help colleagues in JAVA implements a

  • Double-click the ALV call transaction code and pass parameters 2011-03-30

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = g_repid i_callback_user_command = 'USER_CALLBACK' I_STRUCTURE_NAME = 'T_OUTPUT' I_GRID_TITLE = 'Document List' is_layout = gs_layout is_variant = g_variant I_DEFAULT = 'X' I_SAVE =

  • Double-click the ALV calling the transaction code and pass parameters 2011-03-30

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = g_repid i_callback_user_command = 'USER_CALLBACK' I_STRUCTURE_NAME = 'T_OUTPUT' I_GRID_TITLE = 'Document List' is_layout = gs_layout is_variant = g_variant I_DEFAULT = 'X' I_SAVE =

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.379 (s). 12 q(s)