diff --git a/com.wudsn.ide.pas/.classpath b/com.wudsn.ide.pas/.classpath new file mode 100644 index 00000000..6e16b23d --- /dev/null +++ b/com.wudsn.ide.pas/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/com.wudsn.ide.pas/.gitignore b/com.wudsn.ide.pas/.gitignore new file mode 100644 index 00000000..ae3c1726 --- /dev/null +++ b/com.wudsn.ide.pas/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/com.wudsn.ide.pas/.project b/com.wudsn.ide.pas/.project new file mode 100644 index 00000000..01b0706c --- /dev/null +++ b/com.wudsn.ide.pas/.project @@ -0,0 +1,28 @@ + + + com.wudsn.ide.pas + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/com.wudsn.ide.pas/META-INF/MANIFEST.MF b/com.wudsn.ide.pas/META-INF/MANIFEST.MF new file mode 100644 index 00000000..d5fd9b40 --- /dev/null +++ b/com.wudsn.ide.pas/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: WUDSN IDE Pascal Plug-in +Bundle-SymbolicName: com.wudsn.ide.pas;singleton:=true +Bundle-Version: 1.7.1.qualifier +Bundle-Activator: com.wudsn.ide.pas.Activator +Bundle-Vendor: Peter Dell +Require-Bundle: org.eclipse.core.resources, + org.eclipse.core.runtime, + org.eclipse.jface.text, + org.eclipse.ui, + org.eclipse.ui.editors +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy +Automatic-Module-Name: com.wudsn.ide.pas diff --git a/com.wudsn.ide.pas/build.properties b/com.wudsn.ide.pas/build.properties new file mode 100644 index 00000000..6f20375d --- /dev/null +++ b/com.wudsn.ide.pas/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/com.wudsn.ide.pas/plugin.xml b/com.wudsn.ide.pas/plugin.xml new file mode 100644 index 00000000..07071e71 --- /dev/null +++ b/com.wudsn.ide.pas/plugin.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/com.wudsn.ide.pas/src/com/wudsn/ide/pas/Activator.java b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/Activator.java new file mode 100644 index 00000000..c5ef8221 --- /dev/null +++ b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/Activator.java @@ -0,0 +1,76 @@ +/** + * Copyright (C) 2009 - 2019 Peter Dell + * + * This file is part of WUDSN IDE. + * + * WUDSN IDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * WUDSN IDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WUDSN IDE. If not, see . + */ +package com.wudsn.ide.pas; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + * + * @since 1.7.1 + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "com.wudsn.ide.pas"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework. + * BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework. + * BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalContentAssistProcessor.java b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalContentAssistProcessor.java new file mode 100644 index 00000000..115101f7 --- /dev/null +++ b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalContentAssistProcessor.java @@ -0,0 +1,92 @@ +/** + * Copyright (C) 2009 - 2019 Peter Dell + * + * This file is part of WUDSN IDE. + * + * WUDSN IDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * WUDSN IDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WUDSN IDE. If not, see . + */ +package com.wudsn.ide.pas.editor; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectNatureDescriptor; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; + +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.contentassist.CompletionProposal; +import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.text.contentassist.IContextInformation; +import org.eclipse.jface.text.contentassist.IContextInformationValidator; + +/** + * + * @author Peter Dell + * @since 1.7.1 + */ +public class PascalContentAssistProcessor implements IContentAssistProcessor { + + @Override + public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { + // TODO this is logic for .project file to complete on nature and project references. Replace with your language logic! + String text = viewer.getDocument().get(); + String natureTag= ""; + String projectReferenceTag=""; + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + if (text.length() >= natureTag.length() && text.substring(offset - natureTag.length(), offset).equals(natureTag)) { + IProjectNatureDescriptor[] natureDescriptors= workspace.getNatureDescriptors(); + ICompletionProposal[] proposals = new ICompletionProposal[natureDescriptors.length]; + for (int i= 0; i < natureDescriptors.length; i++) { + IProjectNatureDescriptor descriptor= natureDescriptors[i]; + proposals[i] = new CompletionProposal(descriptor.getNatureId(), offset, 0, descriptor.getNatureId().length()); + } + return proposals; + } + if (text.length() >= projectReferenceTag.length() && text.substring(offset - projectReferenceTag.length(), offset).equals(projectReferenceTag)) { + IProject[] projects= workspace.getRoot().getProjects(); + ICompletionProposal[] proposals = new ICompletionProposal[projects.length]; + for (int i= 0; i < projects.length; i++) { + proposals[i]=new CompletionProposal(projects[i].getName(), offset, 0, projects[i].getName().length()); + } + return proposals; + } + return new ICompletionProposal[0]; + } + + @Override + public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) { + return null; + } + + @Override + public char[] getCompletionProposalAutoActivationCharacters() { + return new char[] { '"' }; //NON-NLS-1 + } + + @Override + public char[] getContextInformationAutoActivationCharacters() { + return null; + } + + @Override + public String getErrorMessage() { + return null; + } + + @Override + public IContextInformationValidator getContextInformationValidator() { + return null; + } + +} \ No newline at end of file diff --git a/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalHoverProvider.java b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalHoverProvider.java new file mode 100644 index 00000000..bdf7d527 --- /dev/null +++ b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalHoverProvider.java @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2009 - 2019 Peter Dell + * + * This file is part of WUDSN IDE. + * + * WUDSN IDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * WUDSN IDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WUDSN IDE. If not, see . + */ +package com.wudsn.ide.pas.editor; + +//import org.eclipse.core.resources.IProjectNatureDescriptor; +//import org.eclipse.core.resources.IWorkspace; +//import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextHover; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.Region; + +/** + * + * @author Peter Dell + * @since 1.7.1 + */ +public class PascalHoverProvider implements ITextHover { + + @Override + public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { + // TODO this is logic for .project file to show nature description on hover. Replace with your language logic! + // String contents= textViewer.getDocument().get(); + // int offset= hoverRegion.getOffset(); +// int endIndex= contents.indexOf("", offset); +// if (endIndex==-1) return ""; +// int startIndex= contents.substring(0, offset).lastIndexOf(""); +// if (startIndex==-1) return ""; +// String selection = contents.substring(startIndex+"".length(), endIndex); +// +// IWorkspace workspace = ResourcesPlugin.getWorkspace(); +// IProjectNatureDescriptor[] natureDescriptors= workspace.getNatureDescriptors(); +// for (int i= 0; i < natureDescriptors.length; i++) { +// if (natureDescriptors[i].getNatureId().equals(selection)) +// return natureDescriptors[i].getLabel(); +// } + return ""; + } + + @Override + public IRegion getHoverRegion(ITextViewer textViewer, int offset) { + return new Region(offset, 0); + } +} \ No newline at end of file diff --git a/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalReconciler.java b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalReconciler.java new file mode 100644 index 00000000..929ad5b8 --- /dev/null +++ b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalReconciler.java @@ -0,0 +1,69 @@ +/** + * Copyright (C) 2009 - 2019 Peter Dell + * + * This file is part of WUDSN IDE. + * + * WUDSN IDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * WUDSN IDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WUDSN IDE. If not, see . + */ +package com.wudsn.ide.pas.editor; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.NumberRule; +import org.eclipse.jface.text.rules.PatternRule; +import org.eclipse.jface.text.rules.RuleBasedScanner; +import org.eclipse.jface.text.rules.SingleLineRule; +import org.eclipse.jface.text.rules.Token; + +/** + * + * @author Peter Dell + * @since 1.7.1 + */ +public class PascalReconciler extends PresentationReconciler { + + private IToken quoteToken = new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(139, 69, 19)))); + private IToken numberToken = new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(0, 0, 255)))); + private IToken commentToken = new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(0, 100, 0)))); + private IToken keywordToken = new Token( + new TextAttribute(new Color(Display.getCurrent(), new RGB(150, 0, 85)), null, SWT.BOLD)); + + public PascalReconciler() { + + RuleBasedScanner scanner = new RuleBasedScanner(); + + List rules = new ArrayList(); + rules.add(new SingleLineRule("'", "'", quoteToken)); + rules.add(new PatternRule("//", null, commentToken, (char) 0, true)); + rules.add(new NumberRule(numberToken)); + rules.add(new PascalWordRule(keywordToken)); + scanner.setRules(rules.toArray(new IRule[rules.size()])); + + DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner); + this.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + this.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + } +} diff --git a/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalWordDetector.java b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalWordDetector.java new file mode 100644 index 00000000..5b8a215a --- /dev/null +++ b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalWordDetector.java @@ -0,0 +1,38 @@ +/** + * Copyright (C) 2009 - 2019 Peter Dell + * + * This file is part of WUDSN IDE. + * + * WUDSN IDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * WUDSN IDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WUDSN IDE. If not, see . + */ +package com.wudsn.ide.pas.editor; + +import org.eclipse.jface.text.rules.IWordDetector; + +/** + * + * @author Peter Dell + * @since 1.7.1 + */ +class PascalWordDetector implements IWordDetector { + @Override + public boolean isWordStart(char c) { + return Character.isLetter(c); + } + + @Override + public boolean isWordPart(char c) { + return Character.isLetter(c) || Character.isDigit(c) || (c == '_'); + } +} \ No newline at end of file diff --git a/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalWordRule.java b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalWordRule.java new file mode 100644 index 00000000..adcedc22 --- /dev/null +++ b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/PascalWordRule.java @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2009 - 2019 Peter Dell + * + * This file is part of WUDSN IDE. + * + * WUDSN IDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * WUDSN IDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WUDSN IDE. If not, see . + */ +package com.wudsn.ide.pas.editor; + +import java.util.StringTokenizer; + +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.rules.WordRule; + +/** + * + * @author Peter Dell + * @since 1.7.1 + */ +public class PascalWordRule extends WordRule { + + public PascalWordRule(IToken token) { + super(new PascalWordDetector(), new Token(""), true); + + // From C:\jac\system\Atari800\Tools\PAS\MP\geany\data\filedefs\filetypes.pascal + String words = "absolute abstract add and array as asm assembler automated begin boolean break byte cardinal case cdecl char class const constructor contains default deprecated destructor dispid dispinterface div do downto dynamic dword else end except export exports external far file final finalization finally for forward function goto if implementation implements in index inherited initialization inline integer interface is label library longword longint message mod name near nil nodefault not object of on or out overload override package packed pascal platform private procedure program property protected public published raise read readonly real record register reintroduce remove repeat requires resourcestring safecall sealed set shl shortint smallint shr static stdcall stored strict string then threadvar to try tstring type uint32 unit unsafe until uses var varargs virtual while with word write writeonly xor"; + StringTokenizer st = new StringTokenizer(words, " "); + while (st.hasMoreTokens()) { + addWord(st.nextToken(), token); + + } + } + +} diff --git a/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/ValidatorDocumentSetupParticipant.java b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/ValidatorDocumentSetupParticipant.java new file mode 100644 index 00000000..572166e5 --- /dev/null +++ b/com.wudsn.ide.pas/src/com/wudsn/ide/pas/editor/ValidatorDocumentSetupParticipant.java @@ -0,0 +1,116 @@ +/** + * Copyright (C) 2009 - 2019 Peter Dell + * + * This file is part of WUDSN IDE. + * + * WUDSN IDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * WUDSN IDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WUDSN IDE. If not, see . + */ +package com.wudsn.ide.pas.editor; + +//import java.io.StringReader; +// +//import javax.xml.parsers.DocumentBuilder; +//import javax.xml.parsers.DocumentBuilderFactory; + +import org.eclipse.core.filebuffers.IDocumentSetupParticipant; +import org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension; +import org.eclipse.core.filebuffers.LocationKind; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentListener; +//import org.xml.sax.InputSource; +//import org.xml.sax.SAXParseException; + +/** + * + * @author Peter Dell + * @since 1.7.1 + */ +public class ValidatorDocumentSetupParticipant + implements IDocumentSetupParticipant, IDocumentSetupParticipantExtension { + + private final class DocumentValidator implements IDocumentListener { + private final IFile file; + private IMarker marker; + + DocumentValidator(IFile file) { + this.file = file; + } + + @Override + public void documentChanged(DocumentEvent event) { + if (this.marker != null) { + try { + this.marker.delete(); + } catch (CoreException e) { + e.printStackTrace(); + } + this.marker = null; + } + // try { + // String document=event.getDocument().get(); + // if (document.length()==0) { + // document = "EMPTY"; + // } + // // StringReader reader = new + // StringReader(event.getDocument().get());) { + // // DocumentBuilder documentBuilder = + // // DocumentBuilderFactory.newInstance().newDocumentBuilder(); + // // documentBuilder.parse(new InputSource(reader)); + // } catch (Exception ex) { + // try { + // this.marker = file.createMarker(IMarker.PROBLEM); + // this.marker.setAttribute(IMarker.SEVERITY, + // IMarker.SEVERITY_ERROR); + // this.marker.setAttribute(IMarker.MESSAGE, ex.getMessage()); + // if (ex instanceof SAXParseException) { + // SAXParseException saxParseException = (SAXParseException) ex; + // int lineNumber = saxParseException.getLineNumber(); + // int offset = event.getDocument().getLineInformation(lineNumber - + // 1).getOffset() + // + saxParseException.getColumnNumber() - 1; + // this.marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); + // this.marker.setAttribute(IMarker.CHAR_START, offset); + // this.marker.setAttribute(IMarker.CHAR_END, offset + 1); + // } + // } catch (Exception e) { + // e.printStackTrace(); + // } + // } + } + + @Override + public void documentAboutToBeChanged(DocumentEvent event) { + } + + } + + @Override + public void setup(IDocument document) { + } + + @Override + public void setup(IDocument document, IPath location, LocationKind locationKind) { + if (locationKind == LocationKind.IFILE) { + IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(location); + document.addDocumentListener(new DocumentValidator(file)); + } + } + +}