-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes several issues and refactor codebase (#15)
- Loading branch information
1 parent
c1ddd8a
commit 250e3d0
Showing
12 changed files
with
484 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Place your settings in this file to overwrite default and user settings. | ||
{ | ||
"files.exclude": { | ||
"out": false // set this to true to hide the "out" folder with the compiled JS files | ||
}, | ||
"search.exclude": { | ||
"out": true // set this to false to include "out" folder in search results | ||
}, | ||
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts | ||
"typescript.tsc.autoDetect": "off" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------*/ | ||
'use strict'; | ||
|
||
import * as vscode from 'vscode'; | ||
import * as debug from './utils/debug'; | ||
|
||
export let definitionProvider: vscode.DefinitionProvider; | ||
export const locationMap = new Map<string, Map<number, TargetLocation[]>>(); | ||
|
||
export interface ColInterval { | ||
start: number; | ||
end: number; | ||
} | ||
|
||
export interface TargetLocation { | ||
interval: ColInterval; | ||
targetFile: string; | ||
targetLine: number; | ||
targetStartCharacter: number; | ||
} | ||
|
||
export function activate(context: vscode.ExtensionContext) { | ||
/* Go to definition */ | ||
try { | ||
definitionProvider = new JuvixDefinitionProvider(); | ||
context.subscriptions.push( | ||
vscode.languages.registerDefinitionProvider( | ||
{ language: 'Juvix', scheme: 'file' }, | ||
definitionProvider | ||
) | ||
); | ||
debug.log('info', 'Go to definition registered'); | ||
} catch (error) { | ||
debug.log('error', 'No definition provider', error); | ||
} | ||
} | ||
|
||
export class JuvixDefinitionProvider implements vscode.DefinitionProvider { | ||
async provideDefinition( | ||
document: vscode.TextDocument, | ||
position: vscode.Position, | ||
token: vscode.CancellationToken | ||
): Promise<vscode.Location | vscode.Location[] | undefined> { | ||
const filePath: string = document.fileName; | ||
const line: number = position.line; | ||
const col: number = position.character; | ||
debug.log('info', 'Find def. requested ------------------------'); | ||
debug.log( | ||
'info', | ||
'Looking for definition of the symbol at: ' + (line + 1) + ':' + (col + 1) | ||
); | ||
debug.log('info', 'Active file: ' + filePath); | ||
|
||
if (!locationMap.has(filePath)) { | ||
debug.log( | ||
'info', | ||
'There is no definitions registered in file: ' + filePath | ||
); | ||
return undefined; | ||
} else { | ||
if (!locationMap.get(filePath)!.has(line)) { | ||
debug.log( | ||
'info', | ||
'There is no defnition registered at line: ' + (line + 1) | ||
); | ||
return undefined; | ||
} else { | ||
const locsByLine: TargetLocation[] = locationMap | ||
.get(filePath)! | ||
.get(line)!; | ||
debug.log( | ||
'info', | ||
'> Found ' + locsByLine.length + ' definitions at line: ' + (line + 1) | ||
); | ||
for (let i = 0; i < locsByLine.length; i++) { | ||
const info: TargetLocation = locsByLine[i]; | ||
// debug.log( | ||
// 'info', | ||
// '+ Checking if symbol is between colummns: ' + | ||
// (info.interval.start + 1) + | ||
// ' and ' + | ||
// (info.interval.end + 1) | ||
// ); | ||
|
||
if (info.interval.start <= col && info.interval.end >= col) { | ||
debug.log( | ||
'info', | ||
'[!] Found definition at: ' + | ||
info.targetFile + | ||
':' + | ||
(info.targetLine + 1) + | ||
':' + | ||
(info.targetStartCharacter + 1) | ||
); | ||
const definitionFound = new vscode.Location( | ||
vscode.Uri.file(info.targetFile), | ||
new vscode.Position(info.targetLine, info.targetStartCharacter) | ||
); | ||
return definitionFound; | ||
} | ||
} | ||
} | ||
} | ||
debug.log('info', 'No definition found'); | ||
return undefined; | ||
} | ||
} |
Oops, something went wrong.