Support for code completion and function tips
Advertisements
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
- / / We have to highlight the two functions
- const size_t FUNCSIZE = 2;
- char * g_szFuncList [FUNCSIZE] = (/ / function name
- "CreateWindow (",
- "MoveWindow ("
- );
- char * g_szFuncDesc [FUNCSIZE] = (/ / Function Information
- "HWND CreateWindow ("
- "LPCTSTR lpClassName,"
- "LPCTSTR lpWindowName,"
- "DWORD dwStyle,"
- "Int x,"
- "Int y,"
- "Int nWidth,"
- "Int nHeight,"
- "HWND hWndParent,"
- "HMENU hMenu,"
- "HANDLE hInstance,"
- "PVOID lpParam"
- ")"
- "BOOL MoveWindow ("
- "HWND hWnd,"
- "Int X,"
- "Int Y,"
- "Int nWidth,"
- "Int nHeight,"
- "BOOL bRepaint"
- ")"
- );
- void __fastcall TForm1:: WndProc (Messages:: TMessage & Message)
- (
- TForm:: WndProc (Message);
- if (Message.Msg == WM_NOTIFY)
- (
- SCNotification * notify = (SCNotification *) Message.LParam;
- ...
- if (notify-> nmhdr.code == SCN_CHARADDED)
- (
- ...
- / / Function prompt function
- static const char * pCallTipNextWord = NULL; / / highlight the location of the next
- static const char * pCallTipCurDesc = NULL; / / current function information prompted
- if (notify-> ch == '(') / / If you enter a left parenthesis, indicating the function prompt
- (
- char word [1000]; / / save the current word under the cursor (function name)
- TextRange tr; / / command for SCI_GETTEXTRANGE
- int pos = SendEditor (SCI_GETCURRENTPOS); / / get the current position (the position in parentheses)
- int startpos = SendEditor (SCI_WORDSTARTPOSITION, pos-1); / / starting position of the current word
- int endpos = SendEditor (SCI_WORDENDPOSITION, pos-1); / / terminate the current position of the word
- tr.chrg.cpMin = startpos; / / set word interval, remove the word
- tr.chrg.cpMax = endpos;
- tr.lpstrText = word;
- SendEditor (SCI_GETTEXTRANGE, 0, sptr_t (& tr));
- for (size_t i = 0; i <FUNCSIZE; i + +) / / Zhao Zhao have not we realize the function?
- (
- if (memcmp (g_szFuncList [i], word, sizeof (g_szFuncList [i])) == 0)
- (/ / Find the friends, then it prompts
- pCallTipCurDesc = g_szFuncDesc [i]; / / current function information prompted
- SendEditor (SCI_CALLTIPSHOW, pos, sptr_t (pCallTipCurDesc ));// Show this tip
- const char * pStart = strchr (pCallTipCurDesc ,'(')+ 1; / / highlight the first parameter
- const char * pEnd = strchr (pStart ,',');// comma-separated list of parameters
- if (pEnd == NULL) pEnd = strchr (pStart ,')');// if the last parameter, followed by the right parenthesis
- SendEditor (SCI_CALLTIPSETHLT,
- pStart-pCallTipCurDesc, pEnd-pCallTipCurDesc);
- pCallTipNextWord = pEnd +1; / / point to next parameter position
- break;
- )
- )
- )
- else if (notify-> ch == ')') / / If you enter the right parentheses, prompts to close the function
- (
- SendEditor (SCI_CALLTIPCANCEL);
- pCallTipCurDesc = NULL;
- pCallTipNextWord = NULL;
- )
- else if (notify-> ch == ',' & & SendEditor (SCI_CALLTIPACTIVE) & & pCallTipCurDesc)
- (
- / / Input is a comma, highlight the next parameter
- const char * pStart = pCallTipNextWord;
- const char * pEnd = strchr (pStart ,',');
- if (pEnd == NULL) pEnd = strchr (pStart ,')');
- if (pEnd == NULL) / / no next argument the matter, close the prompt
- SendEditor (SCI_CALLTIPCANCEL);
- else
- (
- SendEditor (SCI_CALLTIPSETHLT, pStart-pCallTipCurDesc, pEnd-pCallTipCurDesc);
- pCallTipNextWord = pEnd +1;
- )
- )
- ) / / If (notify-> nmhdr.code == SCN_CHARADDED)
- ...
- ) / / If (Message.Msg == WM_NOTIFY)
- )
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:
- void __fastcall TForm1:: WndProc (Messages:: TMessage & Message)
- (
- TForm:: WndProc (Message);
- if (Message.Msg == WM_NOTIFY)
- (
- ...
- if (notify-> nmhdr.code == SCN_CHARADDED)
- (
- ...
- if (notify-> ch == '.')
- (
- char word [1000]; / / save the current word under the cursor
- TextRange tr; / / command for SCI_GETTEXTRANGE
- int pos = SendEditor (SCI_GETCURRENTPOS); / / get the current position
- int startpos = SendEditor (SCI_WORDSTARTPOSITION, pos-1); / / starting position of the current word
- int endpos = SendEditor (SCI_WORDENDPOSITION, pos-1); / / terminate the current position of the word
- tr.chrg.cpMin = startpos; / / set word interval, remove the word
- tr.chrg.cpMax = endpos;
- tr.lpstrText = word;
- SendEditor (SCI_GETTEXTRANGE, 0, sptr_t (& tr));
- if (strcmp (word, "file.") == 0) / / input file. After the object file suggest several ways
- (
- SendEditor (SCI_AUTOCSHOW, 0,
- sptr_t (
- "Close"
- "Eof"
- "Good"
- "Open"
- "Rdbuf"
- "Size"
- ));
- )
- )
- ...
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:
- if (strcmp (word, "Create") == 0)
- (
- SendEditor (SCI_AUTOCSHOW, 6, / / 6 characters have been entered
- sptr_t (
- "CreateBitmap"
- "CreateDC"
- "CreateHandle"
- "CreateWindow"
- "CreateWindowEx"
- ));
- )
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












