Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,21 @@
"command": "java.project.updateSourceAttachment",
"title": "Attach Source",
"category": "Java"
},
{
"command": "java.project.addToSourcePath",
"title": "Add Folder to Java Source Path",
"category": "Java"
},
{
"command": "java.project.removeFromSourcePath",
"title": "Remove Folder from Java Source Path",
"category": "Java"
},
{
"command": "java.project.listSourcePaths",
"title": "List all Java source paths",
"category": "Java"
}
],
"keybindings": [
Expand All @@ -317,6 +332,16 @@
"command": "java.projectConfiguration.update",
"when": "resourceFilename =~ /(.*\\.gradle)|(pom.xml)$/",
"group": "1_javaactions"
},
{
"when": "explorerResourceIsFolder&&javaLSReady",
"command": "java.project.addToSourcePath",
"group": "1_javaactions@1"
},
{
"when": "explorerResourceIsFolder&&javaLSReady",
"command": "java.project.removeFromSourcePath",
"group": "1_javaactions@2"
}
],
"editor/context": [
Expand All @@ -335,6 +360,14 @@
{
"command": "java.project.updateSourceAttachment",
"when": "false"
},
{
"command": "java.project.addToSourcePath",
"when": "false"
},
{
"command": "java.project.removeFromSourcePath",
"when": "false"
}
]
}
Expand Down
58 changes: 58 additions & 0 deletions src/buildpath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

import { window, commands, Uri } from 'vscode';
import { Commands } from './commands';

interface Result {
status: boolean;
message: string;
}

interface SourcePath {
path: string;
displayPath: string;
projectName: string;
projectType: string;
}

interface ListCommandResult extends Result {
data?: SourcePath[];
}

export function registerCommands() {
commands.registerCommand(Commands.ADD_TO_SOURCEPATH, async (uri: Uri) => {
const result = await <any>commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.ADD_TO_SOURCEPATH, uri.toString());
if (result.status) {
window.showInformationMessage(result.message ? result.message : "Successfully added the folder to the source path.");
} else {
window.showErrorMessage(result.message);
}
});

commands.registerCommand(Commands.REMOVE_FROM_SOURCEPATH, async (uri: Uri) => {
const result = await <any>commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.REMOVE_FROM_SOURCEPATH, uri.toString());
if (result.status) {
window.showInformationMessage(result.message ? result.message : "Successfully removed the folder from the source path.");
} else {
window.showErrorMessage(result.message);
}
});

commands.registerCommand(Commands.LIST_SOURCEPATHS, async() => {
const result: ListCommandResult = await commands.executeCommand<ListCommandResult>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.LIST_SOURCEPATHS);
if (result.status) {
if (!result.data || !result.data.length) {
window.showInformationMessage("No Java source directories found in the workspace, please use the command 'Add Folder to Java Source Path' first.");
} else {
window.showQuickPick(result.data.map(sourcePath => {
return {
label: sourcePath.displayPath,
detail: `$(file-directory) ${sourcePath.projectType} Project: ${sourcePath.projectName}`,
};
}), { placeHolder: "All Java source directories recognized by the workspace."});
}
} else {
window.showErrorMessage(result.message);
}
});
}
12 changes: 12 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,16 @@ export namespace Commands {
* Resolve the source attachment information for the selected class file
*/
export const RESOLVE_SOURCE_ATTACHMENT = 'java.project.resolveSourceAttachment';
/**
* Mark the folder as the source root of the closest project.
*/
export const ADD_TO_SOURCEPATH = 'java.project.addToSourcePath';
/**
* Unmark the folder as the source root of the project.
*/
export const REMOVE_FROM_SOURCEPATH = 'java.project.removeFromSourcePath';
/**
* List all recognized source roots in the workspace.
*/
export const LIST_SOURCEPATHS = 'java.project.listSourcePaths';
}
4 changes: 4 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Commands } from './commands';
import { StatusNotification, ClassFileContentsRequest, ProjectConfigurationUpdateRequest, MessageType, ActionableNotification, FeatureStatus, ActionableMessage, CompileWorkspaceRequest, CompileWorkspaceStatus, ProgressReportNotification, ExecuteClientCommandRequest, SendNotificationRequest,
SourceAttachmentRequest, SourceAttachmentResult, SourceAttachmentAttribute } from './protocol';
import { ExtensionAPI } from './extension.api';
import * as buildpath from './buildpath';
import * as net from 'net';

let oldConfig;
Expand Down Expand Up @@ -113,6 +114,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
item.text = '$(thumbsup)';
p.report({ message: 'Finished' });
lastStatus = item.text;
commands.executeCommand('setContext', 'javaLSReady', true);
resolve({
apiVersion: '0.1',
javaRequirement: requirements,
Expand Down Expand Up @@ -284,6 +286,8 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
}
});

buildpath.registerCommands();

window.onDidChangeActiveTextEditor((editor) => {
toggleItem(editor, item);
});
Expand Down
5 changes: 4 additions & 1 deletion test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ suite('Java Language Extension', () => {
Commands.COMPILE_WORKSPACE,
Commands.OPEN_FORMATTER,
Commands.CLEAN_WORKSPACE,
Commands.UPDATE_SOURCE_ATTACHMENT
Commands.UPDATE_SOURCE_ATTACHMENT,
Commands.ADD_TO_SOURCEPATH,
Commands.REMOVE_FROM_SOURCEPATH,
Commands.LIST_SOURCEPATHS,
];
let foundJavaCommands = commands.filter(function(value){
return JAVA_COMMANDS.indexOf(value)>=0 || value.startsWith('java.');
Expand Down