use of org.eclipse.jdt.ls.core.internal.preferences.Preferences in project eclipse.jdt.ls by eclipse.
the class DocumentLifeCycleHandlerTest method mockPreferences.
private Preferences mockPreferences() {
Preferences mockPreferences = Mockito.mock(Preferences.class);
Mockito.when(preferenceManager.getPreferences()).thenReturn(mockPreferences);
Mockito.when(preferenceManager.getPreferences(Mockito.any())).thenReturn(mockPreferences);
Mockito.when(mockPreferences.getIncompleteClasspathSeverity()).thenReturn(Severity.ignore);
return mockPreferences;
}
use of org.eclipse.jdt.ls.core.internal.preferences.Preferences in project eclipse.jdt.ls by eclipse.
the class ReferencesHandlerTest method setup.
@Before
public void setup() throws Exception {
importProjects("eclipse/hello");
project = WorkspaceHelper.getProject("hello");
preferenceManager = mock(PreferenceManager.class);
when(preferenceManager.getPreferences()).thenReturn(new Preferences());
handler = new ReferencesHandler(preferenceManager);
}
use of org.eclipse.jdt.ls.core.internal.preferences.Preferences in project eclipse.jdt.ls by eclipse.
the class RenameHandlerTest method setup.
@Before
public void setup() throws Exception {
IJavaProject javaProject = newEmptyProject();
sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
preferenceManager = mock(PreferenceManager.class);
Preferences p = mock(Preferences.class);
when(preferenceManager.getPreferences()).thenReturn(p);
when(p.isRenameEnabled()).thenReturn(true);
handler = new RenameHandler(preferenceManager);
}
use of org.eclipse.jdt.ls.core.internal.preferences.Preferences in project eclipse.jdt.ls by eclipse.
the class SignatureHelpHandlerTest method setup.
@Override
@Before
public void setup() throws Exception {
importProjects("eclipse/hello");
project = WorkspaceHelper.getProject("hello");
IJavaProject javaProject = JavaCore.create(project);
sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
preferenceManager = mock(PreferenceManager.class);
Preferences p = mock(Preferences.class);
when(preferenceManager.getPreferences(null)).thenReturn(p);
when(p.isSignatureHelpEnabled()).thenReturn(true);
handler = new SignatureHelpHandler(preferenceManager);
}
use of org.eclipse.jdt.ls.core.internal.preferences.Preferences in project eclipse.jdt.ls by eclipse.
the class InitHandler method initialize.
@SuppressWarnings("unchecked")
InitializeResult initialize(InitializeParams param) {
logInfo("Initializing Java Language Server " + JavaLanguageServerPlugin.getVersion());
Map<?, ?> initializationOptions = this.getInitializationOptions(param);
Map<String, Object> extendedClientCapabilities = getInitializationOption(initializationOptions, "extendedClientCapabilities", Map.class);
if (param.getCapabilities() == null) {
preferenceManager.updateClientPrefences(new ClientCapabilities(), extendedClientCapabilities);
} else {
preferenceManager.updateClientPrefences(param.getCapabilities(), extendedClientCapabilities);
}
Collection<IPath> rootPaths = new ArrayList<>();
Collection<String> workspaceFolders = getInitializationOption(initializationOptions, "workspaceFolders", Collection.class);
if (workspaceFolders != null && !workspaceFolders.isEmpty()) {
for (String uri : workspaceFolders) {
IPath filePath = ResourceUtils.filePathFromURI(uri);
if (filePath != null) {
rootPaths.add(filePath);
}
}
} else {
String rootPath = param.getRootUri();
if (rootPath == null) {
rootPath = param.getRootPath();
if (rootPath != null) {
logInfo("In LSP 3.0, InitializeParams.rootPath is deprecated in favour of InitializeParams.rootUri!");
}
}
if (rootPath != null) {
IPath filePath = ResourceUtils.filePathFromURI(rootPath);
if (filePath != null) {
rootPaths.add(filePath);
}
}
}
if (rootPaths.isEmpty()) {
IPath workspaceLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation();
logInfo("No workspace folders or root uri was defined. Falling back on " + workspaceLocation);
rootPaths.add(workspaceLocation);
}
if (initializationOptions.get(SETTINGS_KEY) instanceof Map) {
Object settings = initializationOptions.get(SETTINGS_KEY);
@SuppressWarnings("unchecked") Preferences prefs = Preferences.createFrom((Map<String, Object>) settings);
preferenceManager.update(prefs);
}
triggerInitialization(rootPaths);
addWorkspaceDiagnosticsHandler();
Integer processId = param.getProcessId();
if (processId != null) {
JavaLanguageServerPlugin.getLanguageServer().setParentProcessId(processId.longValue());
}
try {
Collection<String> bundleList = getInitializationOption(initializationOptions, BUNDLES_KEY, Collection.class);
BundleUtils.loadBundles(bundleList);
} catch (CoreException e) {
// The additional plug-ins should not affect the main language server loading.
JavaLanguageServerPlugin.logException("Failed to load extension bundles ", e);
}
InitializeResult result = new InitializeResult();
ServerCapabilities capabilities = new ServerCapabilities();
capabilities.setCompletionProvider(new CompletionOptions(Boolean.TRUE, Arrays.asList(".", "@", "#")));
if (!preferenceManager.getClientPreferences().isFormattingDynamicRegistrationSupported()) {
capabilities.setDocumentFormattingProvider(Boolean.TRUE);
}
if (!preferenceManager.getClientPreferences().isRangeFormattingDynamicRegistrationSupported()) {
capabilities.setDocumentRangeFormattingProvider(Boolean.TRUE);
}
if (!preferenceManager.getClientPreferences().isCodeLensDynamicRegistrationSupported()) {
capabilities.setCodeLensProvider(new CodeLensOptions(true));
}
if (!preferenceManager.getClientPreferences().isSignatureHelpDynamicRegistrationSupported()) {
capabilities.setSignatureHelpProvider(SignatureHelpHandler.createOptions());
}
if (!preferenceManager.getClientPreferences().isRenameDynamicRegistrationSupported()) {
capabilities.setRenameProvider(Boolean.TRUE);
}
if (!preferenceManager.getClientPreferences().isCodeActionDynamicRegistered()) {
capabilities.setCodeActionProvider(Boolean.TRUE);
}
if (!preferenceManager.getClientPreferences().isExecuteCommandDynamicRegistrationSupported()) {
Set<String> commands = WorkspaceExecuteCommandHandler.getCommands();
capabilities.setExecuteCommandProvider(new ExecuteCommandOptions(new ArrayList<>(commands)));
}
if (!preferenceManager.getClientPreferences().isWorkspaceSymbolDynamicRegistered()) {
capabilities.setWorkspaceSymbolProvider(Boolean.TRUE);
}
if (!preferenceManager.getClientPreferences().isDocumentSymbolDynamicRegistered()) {
capabilities.setDocumentSymbolProvider(Boolean.TRUE);
}
if (!preferenceManager.getClientPreferences().isDefinitionDynamicRegistered()) {
capabilities.setDefinitionProvider(Boolean.TRUE);
}
if (!preferenceManager.getClientPreferences().isHoverDynamicRegistered()) {
capabilities.setHoverProvider(Boolean.TRUE);
}
if (!preferenceManager.getClientPreferences().isReferencesDynamicRegistered()) {
capabilities.setReferencesProvider(Boolean.TRUE);
}
if (!preferenceManager.getClientPreferences().isDocumentHighlightDynamicRegistered()) {
capabilities.setDocumentHighlightProvider(Boolean.TRUE);
}
TextDocumentSyncOptions textDocumentSyncOptions = new TextDocumentSyncOptions();
textDocumentSyncOptions.setOpenClose(Boolean.TRUE);
textDocumentSyncOptions.setSave(new SaveOptions(Boolean.TRUE));
textDocumentSyncOptions.setChange(TextDocumentSyncKind.Incremental);
if (preferenceManager.getClientPreferences().isWillSaveRegistered()) {
textDocumentSyncOptions.setWillSave(Boolean.TRUE);
}
if (preferenceManager.getClientPreferences().isWillSaveWaitUntilRegistered()) {
textDocumentSyncOptions.setWillSaveWaitUntil(Boolean.TRUE);
}
capabilities.setTextDocumentSync(textDocumentSyncOptions);
WorkspaceServerCapabilities wsCapabilities = new WorkspaceServerCapabilities();
WorkspaceFoldersOptions wsFoldersOptions = new WorkspaceFoldersOptions();
wsFoldersOptions.setSupported(Boolean.TRUE);
wsFoldersOptions.setChangeNotifications(Boolean.TRUE);
wsCapabilities.setWorkspaceFolders(wsFoldersOptions);
capabilities.setWorkspace(wsCapabilities);
result.setCapabilities(capabilities);
return result;
}
Aggregations