@@ -8,7 +8,12 @@ import Gio from "gi://Gio";
88import Gtk from "gi://Gtk" ;
99import Adw from "gi://Adw" ;
1010
11- import { createLSPClient , languages , getLanguage } from "../common.js" ;
11+ import {
12+ createLSPClient ,
13+ languages ,
14+ getLanguage ,
15+ PYTHON_LSP_CONFIG ,
16+ } from "../common.js" ;
1217import lint , { waitForDiagnostics } from "./lint.js" ;
1318import format , { formatting } from "./format.js" ;
1419
@@ -51,6 +56,12 @@ export async function main([action, ...args]) {
5156 lspc . _start_process ( ) ;
5257 await lspc . _initialize ( ) ;
5358
59+ if ( lang . id === "python" ) {
60+ await lspc . _request ( "workspace/didChangeConfiguration" , {
61+ settings : PYTHON_LSP_CONFIG ,
62+ } ) ;
63+ }
64+
5465 let success = false ;
5566
5667 if ( action === "lint" ) {
@@ -78,7 +89,7 @@ const window = new Adw.ApplicationWindow();
7889
7990function createLSPClients ( { root_uri } ) {
8091 return Object . fromEntries (
81- [ "javascript" , "blueprint" , "css" , "vala" , "rust" ] . map ( ( id ) => {
92+ [ "javascript" , "blueprint" , "css" , "vala" , "rust" , "python" ] . map ( ( id ) => {
8293 const lang = languages . find ( ( language ) => language . id === id ) ;
8394 const lspc = createLSPClient ( {
8495 lang,
@@ -363,7 +374,6 @@ async function ci({ filenames, current_dir }) {
363374 uri,
364375 lspc : lsp_clients . vala ,
365376 } ) ;
366-
367377 // FIXME: deprecated features, no replacement?
368378 if ( demo_dir . get_basename ( ) === "Text Fields" ) {
369379 const ignore_for_text_fields = [
@@ -397,6 +407,55 @@ async function ci({ filenames, current_dir }) {
397407 } ) ;
398408 }
399409
410+ const file_python = demo_dir . get_child ( "main.py" ) ;
411+ if ( file_python . query_exists ( null ) ) {
412+ print ( ` ${ file_python . get_path ( ) } ` ) ;
413+
414+ const uri = file_python . get_uri ( ) ;
415+ const languageId = "python" ;
416+ let version = 0 ;
417+
418+ const [ contents ] = await file_python . load_contents_async ( null ) ;
419+ const text = new TextDecoder ( ) . decode ( contents ) ;
420+
421+ await lsp_clients . python . _request ( "workspace/didChangeConfiguration" , {
422+ settings : PYTHON_LSP_CONFIG ,
423+ } ) ;
424+
425+ await lsp_clients . python . _notify ( "textDocument/didOpen" , {
426+ textDocument : {
427+ uri,
428+ languageId,
429+ version : version ++ ,
430+ text,
431+ } ,
432+ } ) ;
433+
434+ const diagnostics = await waitForDiagnostics ( {
435+ uri,
436+ lspc : lsp_clients . python ,
437+ } ) ;
438+ if ( diagnostics . length > 0 ) {
439+ printerr ( serializeDiagnostics ( { diagnostics } ) ) ;
440+ return false ;
441+ }
442+ print ( ` ✅ lints` ) ;
443+
444+ const checks = await checkFile ( {
445+ lspc : lsp_clients . python ,
446+ file : file_python ,
447+ lang : getLanguage ( "python" ) ,
448+ uri,
449+ } ) ;
450+ if ( ! checks ) return false ;
451+
452+ await lsp_clients . python . _notify ( "textDocument/didClose" , {
453+ textDocument : {
454+ uri,
455+ } ,
456+ } ) ;
457+ }
458+
400459 const file_rust = demo_dir . get_child ( "code.rs" ) ;
401460 if ( file_rust . query_exists ( null ) ) {
402461 print ( ` ${ file_rust . get_path ( ) } ` ) ;
0 commit comments