Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize new lines and add .gitattributes #1002

Merged
merged 1 commit into from
May 17, 2024
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
45 changes: 45 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# based on https://github.com/alexkaratarakis/gitattributes/

# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto

#
# The above will handle all files NOT found below
#
# These files are text and should be normalized (Convert crlf => lf)
*.gitattributes text
.gitignore text
*.bash text eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf
*.css text diff=css
*.exsd text
*.htm text diff=html
*.html text diff=html
*.ini text
*.md text diff=markdown
*.java text diff=java
*.js text
*.json text
*.properties text
*.sh text
*.tmLanguage text
*.ts text
*.txt text
*.xsd text
*.xml text
*.yaml text
*.yml text
MANIFEST.MF text
Dockerfile text eol=lf
Jenkinsfile text
LICENSE text

# These files are binary and should be left untouched
# (binary is a macro for -text -diff)
*.gif binary
*.ico binary
*.jpeg binary
*.jpg binary
*.png binary
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
/*******************************************************************************
* Copyright (c) 2022 Avaloq Group AG.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.lsp4e.test.semanticTokens;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.List;
import org.eclipse.jface.text.Document;
import org.eclipse.lsp4e.operations.semanticTokens.SemanticTokensDataStreamProcessor;
import org.eclipse.lsp4e.test.utils.AbstractTest;
import org.eclipse.lsp4j.SemanticTokensLegend;
import org.eclipse.swt.custom.StyleRange;
import org.junit.Test;
public class SemanticTokensDataStreamProcessorTest extends AbstractTest {
@Test
public void testKeyword() {
Document document = new Document(SemanticTokensTestUtil.keywordText);
SemanticTokensDataStreamProcessor processor = new SemanticTokensDataStreamProcessor(SemanticTokensTestUtil
.keywordTokenTypeMapper(SemanticTokensTestUtil.RED_TOKEN), SemanticTokensTestUtil.offsetMapper(document));
List<Integer> expectedStream = SemanticTokensTestUtil.keywordSemanticTokens();
List<StyleRange> expectedStyleRanges = Arrays.asList(//
new StyleRange(0, 4, SemanticTokensTestUtil.RED, null), //
new StyleRange(15, 4, SemanticTokensTestUtil.RED, null), //
new StyleRange(24, 7, SemanticTokensTestUtil.RED, null)//
);
List<StyleRange> styleRanges = processor.getStyleRanges(expectedStream, getSemanticTokensLegend());
assertEquals(expectedStyleRanges, styleRanges);
}
private SemanticTokensLegend getSemanticTokensLegend() {
SemanticTokensLegend semanticTokensLegend = new SemanticTokensLegend();
semanticTokensLegend.setTokenTypes(Arrays.asList("keyword","other"));
semanticTokensLegend.setTokenModifiers(Arrays.asList("obsolete"));
return semanticTokensLegend;
}
}
/*******************************************************************************
* Copyright (c) 2022 Avaloq Group AG.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.lsp4e.test.semanticTokens;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.List;

import org.eclipse.jface.text.Document;
import org.eclipse.lsp4e.operations.semanticTokens.SemanticTokensDataStreamProcessor;
import org.eclipse.lsp4e.test.utils.AbstractTest;
import org.eclipse.lsp4j.SemanticTokensLegend;
import org.eclipse.swt.custom.StyleRange;
import org.junit.Test;

public class SemanticTokensDataStreamProcessorTest extends AbstractTest {

@Test
public void testKeyword() {
Document document = new Document(SemanticTokensTestUtil.keywordText);

SemanticTokensDataStreamProcessor processor = new SemanticTokensDataStreamProcessor(SemanticTokensTestUtil
.keywordTokenTypeMapper(SemanticTokensTestUtil.RED_TOKEN), SemanticTokensTestUtil.offsetMapper(document));

List<Integer> expectedStream = SemanticTokensTestUtil.keywordSemanticTokens();
List<StyleRange> expectedStyleRanges = Arrays.asList(//
new StyleRange(0, 4, SemanticTokensTestUtil.RED, null), //
new StyleRange(15, 4, SemanticTokensTestUtil.RED, null), //
new StyleRange(24, 7, SemanticTokensTestUtil.RED, null)//
);

List<StyleRange> styleRanges = processor.getStyleRanges(expectedStream, getSemanticTokensLegend());

assertEquals(expectedStyleRanges, styleRanges);
}

private SemanticTokensLegend getSemanticTokensLegend() {
SemanticTokensLegend semanticTokensLegend = new SemanticTokensLegend();
semanticTokensLegend.setTokenTypes(Arrays.asList("keyword","other"));
semanticTokensLegend.setTokenModifiers(Arrays.asList("obsolete"));
return semanticTokensLegend;
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
/*******************************************************************************
* Copyright (c) 2022 Avaloq Group AG.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.lsp4e.test.semanticTokens;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.lsp4e.LanguageServerWrapper;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4e.operations.semanticTokens.SemanticHighlightReconcilerStrategy;
import org.eclipse.lsp4e.test.utils.AbstractTestWithProject;
import org.eclipse.lsp4e.test.utils.TestUtils;
import org.eclipse.lsp4j.SemanticTokensLegend;
import org.junit.Test;
public class SemanticTokensLegendProviderTest extends AbstractTestWithProject {
@Test
public void testSemanticTokensLegendProvider() throws CoreException, IOException {
// Setup Server Capabilities
List<String> tokenTypes = Arrays.asList("keyword","other");
List<String> tokenModifiers = Arrays.asList("obsolete");
SemanticTokensTestUtil.setSemanticTokensLegend(tokenTypes, tokenModifiers);
// Setup test data
IFile file = TestUtils.createUniqueTestFile(project, "lspt", "test content");
// start the LS
LanguageServerWrapper wrapper = LanguageServiceAccessor.getLSWrappers(file, c -> Boolean.TRUE).iterator()
.next();
SemanticTokensLegend semanticTokensLegend = new SemanticHighlightReconcilerStrategy().getSemanticTokensLegend(wrapper);
assertNotNull(semanticTokensLegend);
assertEquals(tokenTypes, semanticTokensLegend.getTokenTypes());
assertEquals(tokenModifiers, semanticTokensLegend.getTokenModifiers());
}
}
/*******************************************************************************
* Copyright (c) 2022 Avaloq Group AG.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.lsp4e.test.semanticTokens;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.lsp4e.LanguageServerWrapper;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4e.operations.semanticTokens.SemanticHighlightReconcilerStrategy;
import org.eclipse.lsp4e.test.utils.AbstractTestWithProject;
import org.eclipse.lsp4e.test.utils.TestUtils;
import org.eclipse.lsp4j.SemanticTokensLegend;
import org.junit.Test;

public class SemanticTokensLegendProviderTest extends AbstractTestWithProject {

@Test
public void testSemanticTokensLegendProvider() throws CoreException, IOException {
// Setup Server Capabilities
List<String> tokenTypes = Arrays.asList("keyword","other");
List<String> tokenModifiers = Arrays.asList("obsolete");
SemanticTokensTestUtil.setSemanticTokensLegend(tokenTypes, tokenModifiers);

// Setup test data
IFile file = TestUtils.createUniqueTestFile(project, "lspt", "test content");
// start the LS
LanguageServerWrapper wrapper = LanguageServiceAccessor.getLSWrappers(file, c -> Boolean.TRUE).iterator()
.next();

SemanticTokensLegend semanticTokensLegend = new SemanticHighlightReconcilerStrategy().getSemanticTokensLegend(wrapper);
assertNotNull(semanticTokensLegend);
assertEquals(tokenTypes, semanticTokensLegend.getTokenTypes());
assertEquals(tokenModifiers, semanticTokensLegend.getTokenModifiers());
}
}
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
/*******************************************************************************
* Copyright (c) 2022 Avaloq Group AG.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.lsp4e.test.semanticTokens;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import java.util.Arrays;
import java.util.List;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextEvent;
import org.eclipse.lsp4e.operations.semanticTokens.StyleRangeHolder;
import org.eclipse.lsp4e.test.utils.AbstractTest;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Color;
import org.junit.Test;
public class StyleRangeHolderTest extends AbstractTest {
private static final Color RED = new Color(255, 0, 0);
private List<StyleRange> originalStyleRanges = Arrays.asList(new StyleRange(0, 4, RED, null), new StyleRange(15, 4, RED, null), new StyleRange(24, 7, RED, null));
@Test
public void testAllDocumentRanges() {
StyleRangeHolder holder = new StyleRangeHolder();
holder.saveStyles(originalStyleRanges);
StyleRange[] allDocumentRanges = holder.overlappingRanges(new Region(0, 50));
assertNotEquals(originalStyleRanges, allDocumentRanges); // styles must be copied
assertEquals(originalStyleRanges.size(), allDocumentRanges.length);
}
@Test
public void testPartialDocumentRanges() {
StyleRangeHolder holder = new StyleRangeHolder();
holder.saveStyles(originalStyleRanges);
StyleRange[] allDocumentRanges = holder.overlappingRanges(new Region(0, 20)); // only two ranges overlap this region
assertEquals(2, allDocumentRanges.length);
}
@Test
public void testDocumentChange() {
StyleRangeHolder holder = new StyleRangeHolder();
holder.saveStyles(originalStyleRanges);
TextEvent textEvent = new TextEvent(0, 1, " ", null, new DocumentEvent(), false) {};
// this will remove the first style and shift the last two
holder.textChanged(textEvent);
StyleRange[] noOverlappingRanges = holder.overlappingRanges(new Region(0, 10)); // only one range overlap this region
assertEquals(0, noOverlappingRanges.length);
StyleRange[] twoShiftedOverlappingRanges = holder.overlappingRanges(new Region(10, 50)); // only one range overlap this region
assertEquals(2, twoShiftedOverlappingRanges.length);
assertEquals(16, twoShiftedOverlappingRanges[0].start);
assertEquals(4, twoShiftedOverlappingRanges[0].length);
assertEquals(25, twoShiftedOverlappingRanges[1].start);
assertEquals(7, twoShiftedOverlappingRanges[1].length);
}
}
/*******************************************************************************
* Copyright (c) 2022 Avaloq Group AG.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.lsp4e.test.semanticTokens;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import java.util.Arrays;
import java.util.List;

import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextEvent;
import org.eclipse.lsp4e.operations.semanticTokens.StyleRangeHolder;
import org.eclipse.lsp4e.test.utils.AbstractTest;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Color;
import org.junit.Test;

public class StyleRangeHolderTest extends AbstractTest {

private static final Color RED = new Color(255, 0, 0);
private List<StyleRange> originalStyleRanges = Arrays.asList(new StyleRange(0, 4, RED, null), new StyleRange(15, 4, RED, null), new StyleRange(24, 7, RED, null));

@Test
public void testAllDocumentRanges() {
StyleRangeHolder holder = new StyleRangeHolder();
holder.saveStyles(originalStyleRanges);

StyleRange[] allDocumentRanges = holder.overlappingRanges(new Region(0, 50));

assertNotEquals(originalStyleRanges, allDocumentRanges); // styles must be copied
assertEquals(originalStyleRanges.size(), allDocumentRanges.length);
}

@Test
public void testPartialDocumentRanges() {
StyleRangeHolder holder = new StyleRangeHolder();
holder.saveStyles(originalStyleRanges);

StyleRange[] allDocumentRanges = holder.overlappingRanges(new Region(0, 20)); // only two ranges overlap this region

assertEquals(2, allDocumentRanges.length);
}

@Test
public void testDocumentChange() {
StyleRangeHolder holder = new StyleRangeHolder();
holder.saveStyles(originalStyleRanges);

TextEvent textEvent = new TextEvent(0, 1, " ", null, new DocumentEvent(), false) {};

// this will remove the first style and shift the last two
holder.textChanged(textEvent);

StyleRange[] noOverlappingRanges = holder.overlappingRanges(new Region(0, 10)); // only one range overlap this region

assertEquals(0, noOverlappingRanges.length);

StyleRange[] twoShiftedOverlappingRanges = holder.overlappingRanges(new Region(10, 50)); // only one range overlap this region

assertEquals(2, twoShiftedOverlappingRanges.length);
assertEquals(16, twoShiftedOverlappingRanges[0].start);
assertEquals(4, twoShiftedOverlappingRanges[0].length);
assertEquals(25, twoShiftedOverlappingRanges[1].start);
assertEquals(7, twoShiftedOverlappingRanges[1].length);
}
}
Loading