Skip to content

Instantly share code, notes, and snippets.

View sharwell's full-sized avatar
🏠
Working from home

Sam Harwell sharwell

🏠
Working from home
View GitHub Profile
@sharwell
sharwell / VsOutputWindowPaneAdapter.cs
Created August 31, 2012 09:23
MEF support for the Output Window in Visual Studio 2010: VsOutputWindowPaneAdapter
namespace JavaLanguageService.Panes
{
using System;
using System.Diagnostics.Contracts;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
internal sealed class VsOutputWindowPaneAdapter : IOutputWindowPane, IDisposable
{
private IVsOutputWindowPane _pane;
@sharwell
sharwell / ServiceProviderExtensions.cs
Created August 31, 2012 09:24
MEF support for the Output Window in Visual Studio 2010: ServiceProviderExtensions
namespace JavaLanguageService.Extensions
{
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio;
using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
public static class ServiceProviderExtensions
{
@sharwell
sharwell / example.g4
Created October 25, 2012 22:22
Example input for antlr/antlr4#76
grammar example;
start: keyword+ EOF;
keyword: A1
| A2
| A3
| A4
| A5
| A6
@sharwell
sharwell / FooVisitor.java
Created December 12, 2012 02:17
Extending an ANTLR 4 visitor class to allow "hooking" execution with a ParseTreeListener
// the main visitor implementation
class FooVisitor extends SomeBaseVisitor<T> {
}
// extend the visitor with hooks for a listener
class FooListenerVisitor extends FooVisitor {
private ParseTreeListener listener;
public FooListenerVisitor(ParseTreeListener listener) {
@sharwell
sharwell / SimplePolicy.g
Created December 19, 2012 16:35
Example grammar from email to the antlr-discussion group: https://groups.google.com/d/topic/antlr-discussion/KpjR95MfAKE/discussion
grammar SimplePolicy;
options {
language = Java;
backtrack = true;
}
@header {
package com.manager.impl;
@sharwell
sharwell / opentempfile.java
Last active December 12, 2015 04:48
NetBeans API: Create and open a temporary in-memory file with explicit non-serialized semantic data.
FileSystem fileSystem = FileUtil.createMemoryFileSystem();
// Store the actual text that will be displayed to the memory file system
FileObject tempFileObject = FileUtil.copyFile(FileUtil.toFileObject(inputFile), fileSystem.getRoot(), inputFile.getName(), "linterp");
DataObject od = DataObject.find(tempFileObject);
EditorCookie ec = od.getLookup().lookup(EditorCookie.class);
Document opened = ec.openDocument();
if (opened != null) {
// here I add the additional data as a property to the Document without needing to serialize it
opened.putProperty(LexerDebuggerEditorKit.PROP_INTERP_DATA, lexerInterpreterData);
@sharwell
sharwell / pom.xml
Last active January 23, 2022 15:55
Maven pom.xml to support automatic code generation for ANTLR 4 grammar(s) during an Eclipse build. This configuration does not support (and is not intended for) building using Maven alone.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.uiuc</groupId>
<artifactId>cchistory</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>CodeCompletionWithHistory</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@sharwell
sharwell / ExampleLanguageInfo.cs
Created April 19, 2013 14:33
A minimal implementation of `IVsLanguageInfo`
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.TextManager.Interop;
[Guid("your guid here")]
internal class ExampleLanguageInfo : IVsLanguageInfo
{
public int GetCodeWindowManager(IVsCodeWindow pCodeWin, out IVsCodeWindowManager ppCodeWinMgr)
{
@sharwell
sharwell / ExamplePackage.cs
Created April 19, 2013 15:11
Minimal implementation of `Package` to register and provide an implementation of `IVsLanguageInfo`.
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using IServiceContainer = System.ComponentModel.Design.IServiceContainer;
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#111", "1.0")]
[ProvideLanguageService(typeof(ExampleLanguageInfo), "Example", 100)]
[ProvideLanguageExtension(typeof(ExampleLanguageInfo), ".e1")]
@sharwell
sharwell / ExampleDefinitions.cs
Created April 19, 2013 15:16
Simple example to export the `ContentTypeDefinition`
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Utilities;
public static class ExampleDefinitions
{
/* The language name (used for the language service) and content type must be the same
* due to the way Visual Studio internally registers file extensions and content types.
*/
[Export]
[Name("Example")]