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

Feature/multi tab support #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function activate(context: vscode.ExtensionContext) {
let clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'Processing' }],
synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher('**/.clientrc')
fileEvents: vscode.workspace.createFileSystemWatcher('**/*')
}
};

Expand Down
23 changes: 17 additions & 6 deletions server/src/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Definition } from 'vscode-languageserver'
import * as parser from './parser'
import * as javaSpecific from './grammer/terms/javaspecific'
import { ClassDeclarationContext, VariableDeclaratorIdContext, MethodDeclarationContext } from 'java-ast/dist/parser/JavaParser';
import * as sketch from './sketch'

let currentTempAST: [ParseTree][] = new Array();
let _currentTempCounter = -1
Expand Down Expand Up @@ -41,15 +42,15 @@ export function scheduleLookUpDefinition(receivedUri: string,lineNumber: number,
parser.tokenArray.forEach(function(token){
if(token[1] instanceof ClassDeclarationContext){
if(!(javaSpecific.TOP_LEVEL_KEYWORDS.indexOf(token[0].text) > -1)){
foundDeclaration[_foundDeclarationCount] = [`class`, token[0].text, token[0].payload._line-(adjustOffset+1), token[0].payload._charPositionInLine]
foundDeclaration[_foundDeclarationCount] = [`class`, token[0].text, token[0].payload._line-(adjustOffset), token[0].payload._charPositionInLine]
_foundDeclarationCount +=1
}
} else if(token[1] instanceof VariableDeclaratorIdContext){
foundDeclaration[_foundDeclarationCount] = [`var`, token[0].text, token[0].payload._line-(adjustOffset+1), token[0].payload._charPositionInLine]
foundDeclaration[_foundDeclarationCount] = [`var`, token[0].text, token[0].payload._line-(adjustOffset), token[0].payload._charPositionInLine]
_foundDeclarationCount +=1
} else if(token[1] instanceof MethodDeclarationContext){
// TODO: conflict in `_charPositionInLine` due to addition of `public` infront during preprocessing -> tabs should also be handled
foundDeclaration[_foundDeclarationCount] = [`method`, token[0].text, token[0].payload._line-(adjustOffset+1), token[0].payload._charPositionInLine - 3]
foundDeclaration[_foundDeclarationCount] = [`method`, token[0].text, token[0].payload._line-(adjustOffset), token[0].payload._charPositionInLine - 3]
_foundDeclarationCount +=1
}
})
Expand All @@ -61,15 +62,25 @@ export function scheduleLookUpDefinition(receivedUri: string,lineNumber: number,
if((word[1] <= charNumber) && (charNumber <= word[2])){
foundDeclaration.forEach(function(delarationName){
if(word[0] == delarationName[1]){

let lineNumberJavaFile = delarationName[2];
let diffLine : number = 0;
let docUri : string = '';
if (sketch.transformMap.get(lineNumberJavaFile)) {
diffLine = sketch.transformMap.get(lineNumberJavaFile)!.lineNumber
let docName = sketch.transformMap.get(lineNumberJavaFile)!.fileName
docUri = sketch.uri+docName
}

finalDefinition = {
uri: receivedUri,
uri: docUri,
range:{
start: {
line: delarationName[2],
line: diffLine-1,
character: delarationName[3]
},
end: {
line: delarationName[2],
line: diffLine-1,
character: delarationName[3]+word[0].length
}
}
Expand Down
40 changes: 33 additions & 7 deletions server/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as parser from './parser'
import * as preProcessingClass from './preprocessing'
import * as pStandards from './grammer/terms/preprocessingsnippets'
import * as log from './scripts/syslogs'
import * as sketch from './sketch';

const fs = require('fs');

Expand All @@ -27,12 +28,30 @@ let totalErrorCount = 0
// Diagnostics report based on Error Node
export async function checkForRealtimeDiagnostics(processedTextDocument: TextDocument): Promise<void> {
let settings = await server.getDocumentSettings(processedTextDocument.uri);
let processedText = processedTextDocument.getText()
let problems = 0;
let diagnostics: Diagnostic[] = []
let m: RegExpMatchArray | null;
errorNodeLine.forEach(function(errorLine, index){
if(problems < settings.maxNumberOfProblems){
let errorLine : number = 0
let errorDocName : string = ''
let errorDocUri : string = ''

//Create a diagnostic report per .pde file (tab)
let fileDiagnostics = new Map<string, Diagnostic[]>()
sketch.contents.forEach(function(value, key : string){
let emptyDiag : Diagnostic[] = []

fileDiagnostics.set(key, emptyDiag)
})

errorNodeLine.forEach(function(javaErrorLine, index){
// Get the real error line number
if (sketch.transformMap.get(javaErrorLine)) {
errorLine = sketch.transformMap.get(javaErrorLine)!.lineNumber
errorDocName = sketch.transformMap.get(javaErrorLine)!.fileName
errorDocUri = sketch.uri+errorDocName
}

let diagnostics = fileDiagnostics.get(errorDocName);

if(problems < settings.maxNumberOfProblems && diagnostics){
problems++;
let diagnostic: Diagnostic = {
severity: DiagnosticSeverity.Error,
Expand All @@ -54,17 +73,24 @@ export async function checkForRealtimeDiagnostics(processedTextDocument: TextDoc
diagnostic.relatedInformation = [
{
location: {
uri: processedTextDocument.uri,
uri: errorDocUri,
range: Object.assign({}, diagnostic.range)
},
message: `${errorNodeReasons[index]}`
}
];
}
diagnostics.push(diagnostic);
fileDiagnostics.set(errorDocName, diagnostics)
}
})
server.connection.sendDiagnostics({ uri: processedTextDocument.uri, diagnostics });

//Send all diagnostic reports to the client
for (let [file, diagnostics] of fileDiagnostics) {
let fileUri = sketch.uri+file
server.connection.sendDiagnostics({uri: fileUri, diagnostics})
}

}

function setErrorNodeBackToDefault(){
Expand Down
9 changes: 8 additions & 1 deletion server/src/preprocessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parse } from 'java-ast'
import { ParseTree } from 'antlr4ts/tree/ParseTree'
import { MethodDeclarationContext } from 'java-ast/dist/parser/JavaParser';
import * as log from './scripts/syslogs'
import * as sketch from './sketch'

export let defaultBehaviourEnable = false
export let methodBehaviourEnable = false
Expand All @@ -23,7 +24,13 @@ export let multiLineCommentComponents = [
]

export async function performPreProcessing(textDocument: lsp.TextDocument): Promise<void>{
let unProcessedText = textDocument.getText()
if (!sketch.initialized) {
sketch.initialize(textDocument);
}

sketch.updateContent(textDocument)
let unProcessedText = sketch.getContent()

let processedText: String
let unProcessedMethodName: RegExpExecArray | null
// Super set that contains all the methods in the workspace
Expand Down
15 changes: 12 additions & 3 deletions server/src/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as pstandard from './grammer/terms/preprocessingsnippets'
import { parse } from 'java-ast'
import { ParseTree } from 'antlr4ts/tree/ParseTree'
import { tokenArray } from './parser';
import * as sketch from './sketch'

let currentTempAST: [ParseTree][] = new Array();
let _currentTempCounter = -1
Expand Down Expand Up @@ -48,15 +49,23 @@ export function scheduleLookUpReference(_referenceParams: ReferenceParams): Loca
if((word[1] <= _referenceParams.position.character) && (_referenceParams.position.character <= word[2])){
tokenArray.forEach(function(token){
if(token[0].text == word[0]){
let lineNumberJavaFile = token[0].payload._line-adjustOffset
let refLine : number = 0;
let docUri : string = '';
if (sketch.transformMap.get(lineNumberJavaFile)) {
refLine = sketch.transformMap.get(lineNumberJavaFile)!.lineNumber
let docName = sketch.transformMap.get(lineNumberJavaFile)!.fileName
docUri = sketch.uri+docName
}
multipleTokenOccurenceLocations[_multipleTokenCount] = {
uri: _referenceParams.textDocument.uri,
uri: docUri,
range: {
start: {
line: token[0].payload._line-(adjustOffset+1),
line: refLine-1,
character: token[0].payload._charPositionInLine
},
end: {
line: token[0].payload._line-(adjustOffset+1),
line: refLine-1,
character: token[0].payload._charPositionInLine + word[0].length
}
}
Expand Down
20 changes: 19 additions & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
Location,
ReferenceParams,
RenameParams,
WorkspaceEdit
WorkspaceEdit,
FileChangeType
} from 'vscode-languageserver';

import { interval, Observable, of, Subject } from 'rxjs';
Expand All @@ -28,6 +29,7 @@ import * as log from './scripts/syslogs'
import * as definition from './definition'
import * as lens from './lens'
import * as reference from './references'
import * as sketch from './sketch';

export let connection = createConnection(ProposedFeatures.all);

Expand Down Expand Up @@ -159,6 +161,22 @@ function sleep(ms: number) {

connection.onDidChangeWatchedFiles(_change => {
connection.console.log('We received an file change event');

for (let i = 0; i < _change.changes.length; i++) {
const change = _change.changes[i];

switch (change.type) {
case FileChangeType.Created:
sketch.addTab(change.uri)
break;
case FileChangeType.Deleted:
sketch.removeTab(change.uri)
break;
default:
// do nothing
break;
}
}
});

// Implementation for `goto definition` goes here
Expand Down
Loading