Work in progress on symbol provider
This commit is contained in:
		
							parent
							
								
									093451a8c5
								
							
						
					
					
						commit
						45ec5f4ade
					
				
					 3 changed files with 95 additions and 2 deletions
				
			
		
							
								
								
									
										18
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								package.json
									
									
									
									
									
								
							| 
						 | 
					@ -6,13 +6,18 @@
 | 
				
			||||||
    "publisher": "svaberg",
 | 
					    "publisher": "svaberg",
 | 
				
			||||||
    "repository": {
 | 
					    "repository": {
 | 
				
			||||||
        "type": "git",
 | 
					        "type": "git",
 | 
				
			||||||
        "url": "https://github.com/svaberg/SWMF-grammar"},
 | 
					        "url": "https://github.com/svaberg/SWMF-grammar"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "engines": {
 | 
					    "engines": {
 | 
				
			||||||
        "vscode": "^1.40.0"
 | 
					        "vscode": "^1.40.0"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "categories": [
 | 
					    "categories": [
 | 
				
			||||||
        "Programming Languages"
 | 
					        "Programming Languages"
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
 | 
					    "main": "./out/extension.js",
 | 
				
			||||||
 | 
					    "activationEvents": [
 | 
				
			||||||
 | 
					        "onLanguage:swmf-config"
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
    "contributes": {
 | 
					    "contributes": {
 | 
				
			||||||
        "languages": [
 | 
					        "languages": [
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
| 
						 | 
					@ -36,7 +41,16 @@
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    "scripts": {
 | 
				
			||||||
 | 
					        "vscode:prepublish": "npm run compile",
 | 
				
			||||||
 | 
					        "compile": "tsc -p ./",
 | 
				
			||||||
 | 
					        "watch": "tsc -watch -p ./",
 | 
				
			||||||
 | 
					        "pretest": "npm run compile",
 | 
				
			||||||
 | 
					        "test": "node ./out/test/runTest.js"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "dependencies": {
 | 
					    "dependencies": {
 | 
				
			||||||
        "vsce": "^1.69.0"
 | 
					        "tsc": "^1.20150623.0",
 | 
				
			||||||
 | 
					        "vsce": "^1.69.0",
 | 
				
			||||||
 | 
					        "vscode-languageclient": "^5.1.0"
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										63
									
								
								src/extension.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								src/extension.ts
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,63 @@
 | 
				
			||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// src/extension.ts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import * as vscode from 'vscode';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function activate(context: vscode.ExtensionContext) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    context.subscriptions.push(
 | 
				
			||||||
 | 
					        vscode.languages.registerDocumentSymbolProvider(
 | 
				
			||||||
 | 
					            {language: "swmf-config"}, 
 | 
				
			||||||
 | 
					            new SwmfConfigDocumentSymbolProvider()
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SwmfConfigDocumentSymbolProvider implements vscode.DocumentSymbolProvider {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public provideDocumentSymbols(
 | 
				
			||||||
 | 
					        document: vscode.TextDocument,
 | 
				
			||||||
 | 
					        token: vscode.CancellationToken): Thenable<vscode.DocumentSymbol[]> 
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        return new Promise((resolve, reject) => {
 | 
				
			||||||
 | 
					            var symbols = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (var i = 0; i < document.lineCount; i++) {
 | 
				
			||||||
 | 
					                var line = document.lineAt(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                var marker
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (line.text.startsWith("#BEGIN_COMP")) {
 | 
				
			||||||
 | 
					                    let marker_symbol = {
 | 
				
			||||||
 | 
					                        name: line.text.substr(1,13),
 | 
				
			||||||
 | 
					                        kind: vscode.SymbolKind.Namespace,
 | 
				
			||||||
 | 
					                        location: new vscode.Location(document.uri, line.range)
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    marker = marker_symbol
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else if (line.text.startsWith("#")) {
 | 
				
			||||||
 | 
					                    let boo = line.text.substr(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    symbols.push({
 | 
				
			||||||
 | 
					                        name: boo,
 | 
				
			||||||
 | 
					                        kind: vscode.SymbolKind.Module,
 | 
				
			||||||
 | 
					                        location: new vscode.Location(document.uri, line.range)
 | 
				
			||||||
 | 
					                    })
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else {
 | 
				
			||||||
 | 
					                    let boo = line.text
 | 
				
			||||||
 | 
					                    var regex = /^[1-9]\d{0,2}$/g
 | 
				
			||||||
 | 
					                    regex.test("2")
 | 
				
			||||||
 | 
					                    symbols.push({
 | 
				
			||||||
 | 
					                        name: boo,
 | 
				
			||||||
 | 
					                        kind: vscode.SymbolKind.Variable,
 | 
				
			||||||
 | 
					                        location: new vscode.Location(document.uri, line.range)
 | 
				
			||||||
 | 
					                    })
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            resolve(symbols);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										16
									
								
								tsconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								tsconfig.json
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,16 @@
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    "compilerOptions": {
 | 
				
			||||||
 | 
					        "module": "commonjs",
 | 
				
			||||||
 | 
					        "target": "es6",
 | 
				
			||||||
 | 
					        "outDir": "out",
 | 
				
			||||||
 | 
					        "lib": [
 | 
				
			||||||
 | 
					            "es6"
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        "sourceMap": true,
 | 
				
			||||||
 | 
					        "rootDir": "src"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "exclude": [
 | 
				
			||||||
 | 
					        "node_modules",
 | 
				
			||||||
 | 
					        ".vscode-test"
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in a new issue