Bug 190512 - Support spell check in C/C++ editor
Summary: Support spell check in C/C++ editor
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 4.0   Edit
Hardware: PC Linux
: P3 enhancement with 2 votes (vote)
Target Milestone: 5.0   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 185695
Blocks: 406873
  Show dependency tree
 
Reported: 2007-06-01 13:22 EDT by Sergey Prigogin CLA
Modified: 2013-04-30 05:04 EDT (History)
4 users (show)

See Also:


Attachments
Implementation of the feature (1.54 MB, patch)
2007-09-16 23:23 EDT, Sergey Prigogin CLA
no flags Details | Diff
Icons for the spelling checker (54.96 KB, application/zip)
2007-09-16 23:24 EDT, Sergey Prigogin CLA
no flags Details
Addressed Tony's and Doug's concerns (1.49 MB, patch)
2007-09-22 23:31 EDT, Sergey Prigogin CLA
no flags Details | Diff
Better coexistence of C/C++ and Java spell checkers (1.49 MB, patch)
2007-09-30 12:14 EDT, Sergey Prigogin CLA
no flags Details | Diff
Fixed spell checking of preprocessor directives (1.49 MB, patch)
2007-10-07 01:59 EDT, Sergey Prigogin CLA
cdtdoug: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Prigogin CLA 2007-06-01 13:22:26 EDT
Support spell check in C/C++ editor similar to Java.
Comment 1 Doug Schaefer CLA 2007-06-01 15:22:37 EDT
I guess you haven't experienced a lot of Java development with that *!*#$ spell check turned on. I've eventually had to turn it off. But hey, others may like it.
Comment 2 Sergey Prigogin CLA 2007-06-01 15:30:31 EDT
I like it so far although my experience with it is limited.
Comment 3 Paul McConkey CLA 2007-09-04 06:08:01 EDT
I can see how a spell checker may be painful to use, but I have a member of staff who is dyslexic and he struggles to spell anything.

With content assist and the compiler picking up syntax errors, misspelt code is usually picked up easily. However, comments are often a mess.

It occurs to me that it should be possible for the spell checker to be enabled in comments only - after all content assist is turned off in comments. Having this available would be very useful.
Comment 4 Anton Leherbauer CLA 2007-09-04 09:10:11 EDT
JDT spell checks only comments and - optionally - string literals.
I don't think it makes sense to spell check identifiers.

Note that the default spellcheck engine is contributed by JDT and there is currently no common framework we could extend or build upon. See also bug 185695.
Comment 5 Doug Schaefer CLA 2007-09-04 11:10:18 EDT
(In reply to comment #4)
> I don't think it makes sense to spell check identifiers.

I don't know about that. The new project model is littered with spelling errors :). The latest one: CConfigBasedDescriptorManager.reconsile. Shouldn't that be reconcile?
Comment 6 Sergey Prigogin CLA 2007-09-06 13:14:36 EDT
I'm working on porting JDT spell checker implementation to CDT. Stay tuned.
Comment 7 Sergey Prigogin CLA 2007-09-16 23:23:10 EDT
Created attachment 78526 [details]
Implementation of the feature

Tony or Markus, please review the patch and initiate the IP review process. Thanks.
Comment 8 Sergey Prigogin CLA 2007-09-16 23:24:30 EDT
Created attachment 78527 [details]
Icons for the spelling checker
Comment 9 Sergey Prigogin CLA 2007-09-16 23:31:33 EDT
For the spelling checker to work, "Enable editor problem annotation" option has to be enabled. I've flipped the default for that option to true since it doesn't produce false positives any more. 

I couldn't figure out a way to access the spelling dictionaries used by JDT and had to create a separate copy of the dictionaries (org.eclipse.cdt.ui/dictionaries).
Comment 10 Anton Leherbauer CLA 2007-09-19 08:51:19 EDT
(In reply to comment #7)
> Tony or Markus, please review the patch and initiate the IP review process.
> Thanks.

Sergey, I had a look at your patch. Basically it looks good. Most of the code is copied from JDT as expected. Some issues remain:

- Are the changes in package org.eclipse.cdt.core.parser really necessary?
  Most of the code is obsolete and will probably be removed anyway.
- The patch introduces an optional dependency to o.e.jdt.ui
  I.e. JDT is required to build CDT, I am not sure everyone is happy with that.
- The spelling checker does not distinguish between comments and code
- There are some compilation errors against Eclipse 3.3. I assume you coded against a 3.4 milestone.

(In reply to comment #9)
> I couldn't figure out a way to access the spelling dictionaries used by JDT and
> had to create a separate copy of the dictionaries
> (org.eclipse.cdt.ui/dictionaries).

The following should work:

public static URL getDictionaryLocation() throws MalformedURLException {
  Bundle jdtuiBundle= Platform.getBundle("org.eclipse.jdt.ui"); //$NON-NLS-1$
  if (jdtuiBundle != null && (jdtuiBundle.getState() & Bundle.RESOLVED) != 0) {
    return jdtuiBundle.getEntry("/" + DICTIONARY_LOCATION); //$NON-NLS-1$
  }
  return null;
}
Comment 11 Anton Leherbauer CLA 2007-09-19 09:17:30 EDT
The following *does* work ;-)

public static URL getDictionaryLocation() throws MalformedURLException {
  Bundle jdtuiBundle= Platform.getBundle("org.eclipse.jdt.ui"); //$NON-NLS-1$
  if (jdtuiBundle != null && (jdtuiBundle.getState() & (Bundle.RESOLVED|Bundle.STARTING|Bundle.ACTIVE)) != 0) {
    return jdtuiBundle.getEntry("/" + DICTIONARY_LOCATION); //$NON-NLS-1$
  }
  return null;
}
Comment 12 Doug Schaefer CLA 2007-09-19 11:36:18 EDT
The fact that this feature depends on the JDT points out that there's stuff they need to move down to the platform.

There are many CDT-based IDEs that do not include the JDT. I'd prefer this functionality be applicable to all.

At any rate, this would be a great feature for CDT Ganymede. We still have time to work out ways of removing the JDT dependencies. Let me know if you need help co-ordinating with the JDT team on this.
Comment 13 Sergey Prigogin CLA 2007-09-19 13:14:13 EDT
> - Are the changes in package org.eclipse.cdt.core.parser really necessary?
>   Most of the code is obsolete and will probably be removed anyway.

Couple changes were needed to avoid compilation errors. The rest is just formatting.

> - The patch introduces an optional dependency to o.e.jdt.ui
>   I.e. JDT is required to build CDT, I am not sure everyone is happy with that.

Spell check support in Eclipse is weird. Even when you are editing a simple text file it is provided by JDT, not by the platform. I had a choice between reusing JDT provided preferences (General/Editors/Text Editors/Spelling) or providing an independent set of spelling preferences. Unfortunately, the second approach forces user to choose which of the two spelling engines to use for the whole platform, irrespective of the file type. I will soon file bugs against platform/JDT for this. org.eclipse.jdt.internal.ui.text.spelling.DefaultSpellingEngine class has to move to the platform and support an extension point allowing contribution of content type specific spelling engines.

> - The spelling checker does not distinguish between comments and code

Oops. I'll investigate.

> - There are some compilation errors against Eclipse 3.3. I assume you coded
> against a 3.4 milestone.

Yes.

> public static URL getDictionaryLocation() throws MalformedURLException {
>   Bundle jdtuiBundle= Platform.getBundle("org.eclipse.jdt.ui"); //$NON-NLS-1$
>   if (jdtuiBundle != null && (jdtuiBundle.getState() & Bundle.RESOLVED) != 0) {
>     return jdtuiBundle.getEntry("/" + DICTIONARY_LOCATION); //$NON-NLS-1$
>   }
>   return null;
> }
 
Thanks a lot!

Comment 14 Sergey Prigogin CLA 2007-09-19 13:18:09 EDT
(In reply to comment #12)
> The fact that this feature depends on the JDT points out that there's stuff
> they need to move down to the platform.
> 
> There are many CDT-based IDEs that do not include the JDT. I'd prefer this
> functionality be applicable to all.
> 
> At any rate, this would be a great feature for CDT Ganymede. We still have time
> to work out ways of removing the JDT dependencies. Let me know if you need help
> co-ordinating with the JDT team on this.

I'll try to formulate a proposal for moving core spelling checker functionality to the platform and file a bugzilla for it. I will definitely need all help I can get.
Comment 15 Sergey Prigogin CLA 2007-09-22 23:31:52 EDT
Created attachment 79036 [details]
Addressed Tony's and Doug's concerns

This patch fixes the problem of comments and code being treated the same way. To make it happen I had to completely depart from JDT. The dependency on it is now gone. Unfortunately, when both JDT and CDT are installed, user now has to choose between two spelling engines. Bug 204370 describes the problem.

Formatting changes in Parser.java have been reverted.
Comment 16 Sergey Prigogin CLA 2007-09-30 12:14:45 EDT
Created attachment 79456 [details]
Better coexistence of C/C++ and Java spell checkers

Added CSpellingService class that calls the C/C++ spelling engine on C/C++ content types even when it is not selected in Preferences/General/Editors/Text Editors/Spelling.

SpellingEngineDispatcher delegates to the default spelling engine (the JDT one) if it is called for a content type outside of C/C++ realm. This may happen when the C/C++ spelling engine is selected in Preferences/General/Editors/Text Editors/Spelling.

Time to initiate an IP review process?
Comment 17 Sergey Prigogin CLA 2007-10-07 01:59:39 EDT
Created attachment 79852 [details]
Fixed spell checking of preprocessor directives

Unfortunately, there seem to be no general purpose utilities for parsing of preprocessor directives. As a result, CSpellingEngine has to do some low level parsing on its own.
Comment 18 Sergey Prigogin CLA 2007-12-02 19:22:20 EST
The feature committed to HEAD. For the spelling checker to work, "Enable editor problem annotation" option has to be turned on. It is now enabled by default for new workspaces but has to be turned on for existing ones.

Code duplication between CDT and JDT can be avoided when the core of the spell checker gets moved from JDT to the platform (see bug 185695).
Comment 19 Vivian Kong CLA 2008-06-09 09:57:26 EDT
(In reply to comment #18)
> The feature committed to HEAD. For the spelling checker to work, "Enable editor
> problem annotation" option has to be turned on. It is now enabled by default
> for new workspaces but has to be turned on for existing ones.
> 
> Code duplication between CDT and JDT can be avoided when the core of the spell
> checker gets moved from JDT to the platform (see bug 185695).
> 

Hi Sergey,

Does this enhancement make use of the iSpell dictionaries?

/org.eclipse.cdt.ui/dictionaries/en_GB.dictionary 
/org.eclipse.cdt.ui/dictionaries/en_US.dictionary 

(Are they the same as the ones in JDT?)

If so, I'll need to add the third party code info in about.html.

Thanks!
Comment 20 Sergey Prigogin CLA 2008-06-09 11:49:03 EDT
(In reply to comment #19)
> Hi Sergey,
> 
> Does this enhancement make use of the iSpell dictionaries?
> 
> /org.eclipse.cdt.ui/dictionaries/en_GB.dictionary 
> /org.eclipse.cdt.ui/dictionaries/en_US.dictionary 
> 
> (Are they the same as the ones in JDT?)
> 
> If so, I'll need to add the third party code info in about.html.
> 
> Thanks!

Yes, the dictionaries were borrowed from JDT.

Comment 21 Vivian Kong CLA 2009-03-24 10:34:39 EDT
(In reply to comment #20)

> Yes, the dictionaries were borrowed from JDT.

Thanks.  I've opened a CQ for this (CQ 3223).