WIP: snippet infrastructure
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2017 Pivotal, Inc.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Pivotal, Inc. - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.springframework.ide.vscode.boot.java.handlers;
|
||||||
|
|
||||||
|
import org.eclipse.lsp4j.CompletionItemKind;
|
||||||
|
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||||
|
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||||
|
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||||
|
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||||
|
|
||||||
|
public class SimpleCompletionFactory {
|
||||||
|
|
||||||
|
public ICompletionProposal simpleProposal(IDocument doc, int offset, String query, CompletionItemKind kind, String value, String detail, Renderable info) {
|
||||||
|
DocumentEdits edits = new DocumentEdits(doc);
|
||||||
|
edits.replace(offset-query.length(), offset, value);
|
||||||
|
return new ICompletionProposal() {
|
||||||
|
@Override
|
||||||
|
public DocumentEdits getTextEdit() {
|
||||||
|
return edits;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLabel() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletionItemKind getKind() {
|
||||||
|
return kind;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Renderable getDocumentation() {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDetail() {
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2017 Pivotal, Inc.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Pivotal, Inc. - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.springframework.ide.vscode.boot.java.snippets;
|
||||||
|
|
||||||
|
public class JavaSnippet {
|
||||||
|
|
||||||
|
private SnippetContext context;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2017 Pivotal, Inc.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Pivotal, Inc. - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.springframework.ide.vscode.boot.java.snippets;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.core.dom.ASTNode;
|
||||||
|
|
||||||
|
public interface SnippetContext {
|
||||||
|
boolean appliesTo(ASTNode node);
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<!-- These are the original templates. This file will be deleted. It just here for 'inspiration' -->
|
||||||
|
<templates>
|
||||||
|
<template autoinsert="true"
|
||||||
|
id="org.springframework.ide.eclipse.boot.templates.RequestMapping"
|
||||||
|
name="RequestMapping method" context="boot-members" description="RequestMapping method"
|
||||||
|
enabled="true">${x:import(org.springframework.web.bind.annotation.RequestMapping,
|
||||||
|
org.springframework.web.bind.annotation.RequestMethod,
|
||||||
|
org.springframework.web.bind.annotation.RequestParam)}@RequestMapping(value="${path}",
|
||||||
|
method=RequestMethod.${GET})
|
||||||
|
public ${SomeData} ${requestMethodName}(@RequestParam ${String} ${param}) {
|
||||||
|
return new ${SomeData}(${cursor});
|
||||||
|
}
|
||||||
|
</template>
|
||||||
|
<template autoinsert="true"
|
||||||
|
id="org.springframework.ide.eclipse.boot.templates.GetMapping" name="GetMapping method"
|
||||||
|
context="boot-members" description="GetMapping method" enabled="true">
|
||||||
|
${x:import(org.springframework.web.bind.annotation.GetMapping,
|
||||||
|
org.springframework.web.bind.annotation.RequestParam)}@GetMapping(value="${path}")
|
||||||
|
public ${SomeData} ${getMethodName}(@RequestParam ${String} ${param})
|
||||||
|
{
|
||||||
|
return new ${SomeData}(${cursor});
|
||||||
|
}
|
||||||
|
</template>
|
||||||
|
<template autoinsert="true"
|
||||||
|
id="org.springframework.ide.eclipse.boot.templates.PostMapping" name="PostMapping method"
|
||||||
|
context="boot-members" description="PostMapping method" enabled="true">
|
||||||
|
${x:import(org.springframework.web.bind.annotation.PostMapping,
|
||||||
|
org.springframework.web.bind.annotation.RequestBody)}@PostMapping(value="${path}")
|
||||||
|
public ${SomeEnityData} ${postMethodName}(@RequestBody
|
||||||
|
${SomeEnityData} ${entity}) {
|
||||||
|
//TODO: process POST request
|
||||||
|
${cursor}
|
||||||
|
return ${entity};
|
||||||
|
}
|
||||||
|
</template>
|
||||||
|
<template autoinsert="true"
|
||||||
|
id="org.springframework.ide.eclipse.boot.templates.PutMapping" name="PutMapping method"
|
||||||
|
context="boot-members" description="PutMapping method" enabled="true">
|
||||||
|
${x:import(org.springframework.web.bind.annotation.PutMapping,
|
||||||
|
org.springframework.web.bind.annotation.RequestBody,
|
||||||
|
org.springframework.web.bind.annotation.PathVariable)}@PutMapping(value="${path}/{${id}}")
|
||||||
|
public ${SomeEnityData} ${putMethodName}(@PathVariable
|
||||||
|
${pvt:link(String,int,long)} ${id}, @RequestBody ${SomeEnityData}
|
||||||
|
${entity}) {
|
||||||
|
//TODO: process PUT request
|
||||||
|
${cursor}
|
||||||
|
return ${entity};
|
||||||
|
}
|
||||||
|
</template>
|
||||||
|
</templates>
|
||||||
Reference in New Issue
Block a user